Ysort fun and Frollics 2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By KaiProton

So Ive got my entities in the Scene,

a player Kinematic and Animated Sprites,
and a static with animated sprites,

Added to a Ysort in the World, and its all good, sorts on the Y exactly like expected,
but Im trying to make the character have multiple characters in it,
as in they were be selectable fighters in the scrolling beat em up,
the four player characters are basically the same, with different speeds and power, and health, so while adding them I came up with the idea of adding other animated sprites as the other player characters, then in _ready it hides and shows the correct one based on the players choice on the selection screen,
the idea is I only have to deal with creating one player kinematic, and duplicating it, later when getting to the 2player options,
however… changing character sprite now stops the Ysort, and I cant figure out why,

also in code I duplicate the sprite node, and colour it like a shadow, using the Z index to move the node back behind the chosen player sprite, so it looks like Mortal Kombat 1 shadows,

anyways, the shadow works fine for the characters and creates the correct one for the player dependent on the choice, but when walking around the level, the ysort now doesnt, I thought it would because its based on the kinematicbody not the sprite, or at least thats what I thought…

can anyone point me into a direction of fixing this?


:bust_in_silhouette: Reply From: scrubswithnosleeves

Show some code lol. The Ysort is based upon the collision shape attached to the physics body node. Are you messing with the sprite z-index or the node z-index itself?

Also, rather than having several animated sprite nodes, you should just have one animated sprite node, and then change which sprite frames it uses.

I also don’t know what you mean by duplicate. like you are literally duplicating the node or you are instancing several instances of your player scene?

Hey Thanks for the response,

Ive got it working now,

Basically it was the Z-index overriding the ySort,
so set them back to 0 so all the sprites were on the same index layer,

then learned the Sprite duplicate inside the player node, that was created in the code, could be moved up the tree in code with move_child(),
added that line and its fixed all my issues with the layering, and works how I want it to now.
Here is some code on how I created fake sprite shadows

onready var anim = get_node("AnimatedSprite")

       func CreateShadow():
        	shadow = anim.duplicate()
        	shadow.name = "shadow"
        	shadow.modulate = Color(0,0,0,0.5)
        	shadow.offset.x = -1
        	shadow.offset.y = 66
        	shadow.scale.y = 0.33

KaiProton | 2021-05-04 06:24