Set Width By Aliening Two Image Points

0 favourites
  • 5 posts
From the Asset Store
7 Dark mystery music ranging from a piano arrangement to full orchestral pieces.
  • Math Heavy

    I'm making a custom character menu but am having trouble getting the width of the hair sprite to function correctly. I have a head sprite and I have a Hair Sprite and both are animations that contain all the individual pieces. That way all I have to do is +/- a frame to cycle all my parts. I have a point where the top of the head meets the hair who's point is where the top of the head should be. So I can not statically set a with for each hair as it would change width every frame of the head and I have now 20 heads and 40 - 60 hair options.

    In the image below I drew out what I am trying to do algebraically which is aliening a image point where the temple on the left side of the head should fall. Thus dynamically seating the width of the hair sprite regardless of which head or hair image.

    I think I am doing the math right however I still am having issues as the hair is too small but if I know my High School algebra (from a longer time ago than I care to admit) This should give me what I am looking for assuming that the distance form the image point to the center of the sprite is the same distance for the Hair and the Head respectively.

    Thank you for your time in helping me solve this.

    -edit- Ahhh I made a typo when entering the string, now that I asked for the help

    distance(Head.BBoxLeft, Head.ImagePointY(5), Head.ImagePointX(5), Head.ImagePointY(1))+distance(Head.BBoxLeft, Head.ImagePointY(0), Head.ImagePointX(0), Head.ImagePointY(0))-distance(Hair.BBoxLeft, Hair.ImagePointY(1), Hair.ImagePointX(1), Hair.ImagePointY(1))

    that sets it right. Hope that this will help someone who will need to do the same thing.

  • If I understand you correct you have 20 heads with different width and 40-60 hair options which are also different width and you want these to match any of the heads no matter what width?`

    If that's the case I think you might be overcomplicating things a bit, if each type of head have a hairline image point you should be able to just set the hair types image point to that image point and then you change the width of the hair to be equal to the head width. Just be sure that the image point is in the centre of the sprite.

  • If I understand you correct you have 20 heads with different width and 40-60 hair options which are also different width and you want these to match any of the heads no matter what width?`

    If that's the case I think you might be overcomplicating things a bit, if each type of head have a hairline image point you should be able to just set the hair types image point to that image point and then you change the width of the hair to be equal to the head width. Just be sure that the image point is in the centre of the sprite.

    Unfortunately nimos100 many of my hair parts have various volumes (female hair). If i have a buzz cut it works very well but anything larger and I loose proportion as having the same width as the head means that the piece is shrunk and does not line up. Which is why I am trying to go the route that I am but its time consuming to make sure that the two points line up every time without a real good control over the points placement.

    Any ideas to get this effect that is efficient and accurate would be welcome.

  • [quote:27dhbzm8]Any ideas to get this effect that is efficient and accurate would be welcome.

    Unfortunately I don't think I have any ideas you would like As I would suggest remaking the hair so they are made for fitting your head sprite better. Because it sounds like it would probably take longer time to create the code to fit all the hair parts, than to just recreate them.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • [quote:1ls1y0ez]Any ideas to get this effect that is efficient and accurate would be welcome.

    Unfortunately I don't think I have any ideas you would like As I would suggest remaking the hair so they are made for fitting your head sprite better. Because it sounds like it would probably take longer time to create the code to fit all the hair parts, than to just recreate them.

    Aye but even if I just had 5 hair and 5 head That is 5 hair size code line for head, another 5 for head 2 ect so even that small a system would mean that I would need to hand code 25 actions. With 60 hair styles and 25 heads that becomes 1500 lines of code. Which effects performance and that is just for one race and gender and I still have a fairly large game to append to that one layout.

    anyway after playing around I came to something much easier. If for every tick y1 and x1 are not equal; than if y1>x1change the with of Hair till it matches, and do the opposite for <

    And It works great and only uses 4 lines

    -edit- fixed the hair height at bottom

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)