Sprite still doesnt work..??

Hey guys i am trying to make my 2d character (Sprite) to Idle in a certain direction

So first i just wanted it to just idle when there was no input so i made this:

if (Velocity.X == 0)
animationManager.Play(animations[“WalkIdle”]);

Thats what i added to my other code i already had just to walk:

if (Velocity.X > 0)
animationManager.Play(animations[“WalkRight”]);
else if (Velocity.X < 0)
animationManager.Play(animations[“WalkLeft”]);
else if (Velocity.Y > 0)
animationManager.Play(animations[“WalkDown”]);
else if (Velocity.Y < 0)
animationManager.Play(animations[“WalkUp”]);

But now my question is How can i let it idle a certain direction??
this is what i made but i didnt work and it just displayed the IdleDown animation the whole time:

if (Velocity.X > 0)
animationManager.Play(animations[“WalkRight”]);
else if (Velocity.X < 0)
animationManager.Play(animations[“WalkLeft”]);
else if (Velocity.Y > 0)
animationManager.Play(animations[“WalkDown”]);
else if (Velocity.Y < 0)
animationManager.Play(animations[“WalkUp”]);
else if (Velocity.Y <= 0)
animationManager.Play(animations[“WalkIdleDown”]);
else if (Velocity.Y >= 0)
animationManager.Play(animations[“WalkIdleUp”]);
else if (Velocity.X <= 0)
animationManager.Play(animations[“WalkIdleRight”]);
else if (Velocity.X >= 0)
animationManager.Play(animations[“WalkIdleLeft”]);

What am i doing Wrong??

please send me code and dont tell me what to do cause my english is pretty bad :frowning:

Is that your homework?

No but im like just learning c# and evertime i make a topic people say owh you have to do this and this and that and then im like bro like im just learning please provide me the code instead of just saying you have to add this and this

You’ll learn less by just taking code. If you implement the code yourself from hints given by other people, you will learn a lot more. We can’t, and shouldn’t, do your code for you.

2 Likes

I understand that btw how can i remove a topic because i have alot of topics open that need to be closed

I don’t think you can close a topic, but you can edit the topic to add “[SOLVED]” or similar.

Ok btw could you help me with my code cause i tried alot but i cant find the fix the code is above in this topic could you tell me what to do?

What have you tried since last time?
Did you ever take a second look at the code or tried to put a breakpoint and step through the code?

you could use booleans to register you last movement action. so like boolean isLeft = true when you pressed left. and do that for every movement. based on that you know what idle sprite you need to use.

Thx for the tip ill have a look

Could you stop being so rude just help or leave me alone thx

Hey man, @nkast wasn’t being rude, he was only trying to help.

I’ve just been informed that my animations tutorials (that I think you got this code from) is actually missing 1 line of code (doh!).

In the Move method of the Sprite class, there should be the below line of code

else _animationManager.Stop();

That should solve your problem.

1 Like