0 votes

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?


Godot version 3.3
in Engine by (16 points)

1 Answer

0 votes

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?

by (586 points)

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
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.