I need Help with Depths based on y value

Subscribe to  I need Help with Depths based on y value 4 posts

avatar for angrygiraffe977 angrygiraffe977 8 posts
Flag Post

Hey I learned AS3 because I heard that you could use it to give all your movie clips on the stage a different depth based on their Y value. So if my player character was closer to the bottom of the screen than a tree or an AI was, then he would have a higher depth than that AI so he appears in front of him, or if he was higher on the screen he would have a lower depth so he appeared behind him. Kind of like in Pokemon or Zelda, really any rpg or rts. ANY HELP FIGURING THIS OUT WOULD BE GREATLY APPRECIATED!! :)

 
avatar for Amibtious Amibtious 377 posts
Flag Post

Add everything you want depth sorted to an array/vector list, then use .sortOn() to arrange them by y.

 
avatar for Lucidius Lucidius 180 posts
Flag Post

Try to use the objects’ bottom-y that is…their current y (top of the image) PLUS the height of the object. In this way you can sort by y AND have entities of different heights (trees versus the player, etc)

 
avatar for jasonjie88 jasonjie88 302 posts
Flag Post

1) Find the y- value. This y-value should equal the same value as your vanishing point. The vanishing point is the point at which the object cannot be visible.
2) Find the point at which the object will have a scale of 1, and get its y-value. Note: you may like to experiment on values, taking into account you want to be realistic, and do not want a person accidentally look like a giant or an elf or something.
3) Get the object. Pass the values o the width and height of the object when it is of scale 1 into an array. Then use the top center corner of the object to scale the object. Make the depth sorting function return a scale number. Multiply that by the normal width and height of the object, and you have the current width and height of the object. Note: The top-center point works best when the player is moving forwards/backwards. You may want to use other points if the object is moving diagonally forwards/backwards.
4) If you have multiple object, do what Ambitious did. Use the .sortOn method to arrange the objects by y-value. This way, objects will appear to be behind other object.
5) Final notes: This method may be complicated if you want your player to jump. Especially if you want to make your player jump forwards or backwards. In this case, it would be better to raise the vanishing point temporarily so you can still scale the player without the guy getting smaller as the guy jumps.
6) If you want the player to be hittable (I don’t know if this is a word), like get crushed, or hit by bullets, or something, you could determine a function. If the player has the same scale as the bullet, plus or minus a certain amount, then the player will get hit.
7) An alternative method is to control the object by scaling the player AND control its y-value as he/she/it moves. When the player jumps, alter the y-value regardless of where the player moves. In fact, if the player moves, you add the corresponding y-value to the player as well.
8) If you want platforms in the game as well, this may be tricky. I suggest trying isometric projections if you want this sort of effect.

Hope this helps :D