Essentially, i have a thing that if you press shift, it turns your sprite into a fireball. i also have a walk cycle, and basically, they both won't work at the same time. From what I've tried it's just the one last in the code that actually work. The effects of the dash work, just not the animation
Here's my code for the described issue:
if inputMag != 0 && !keyDash {
sprite_index = s_PLRW;
if keyLeft {image_xscale = -1}
if keyRight {image_xscale = 1}
}
else {
sprite_index = s_PLR;
}
if keyDash {
sprite_index = s_PLRD;
wSpeed = 2;
immune = true;
}
else {
sprite_index = s_PLR;
immune = false;
wSpeed = 1.25;
I've tried rearranging the code, making it into different events, renaming the sprites but nothing seems to work
Essentially, i have a thing that if you press shift, it turns your sprite into a fireball. i also have a walk cycle, and basically, they both won't work at the same time. From what I've tried it's just the one last in the code that actually work. The effects of the dash work, just not the animation
Here's my code for the described issue:
if inputMag != 0 && !keyDash {
sprite_index = s_PLRW;
if keyLeft {image_xscale = -1}
if keyRight {image_xscale = 1}
}
else {
sprite_index = s_PLR;
}
if keyDash {
sprite_index = s_PLRD;
wSpeed = 2;
immune = true;
}
else {
sprite_index = s_PLR;
immune = false;
wSpeed = 1.25;
I've tried rearranging the code, making it into different events, renaming the sprites but nothing seems to work
Share Improve this question asked Mar 9 at 4:48 Strawberry AnimationsStrawberry Animations 11 bronze badge 3- Is dashing always allowed, or can you only dash when walking? – liggiio Commented Mar 9 at 9:55
- I ended up fixing it, by just putting the dash code into an else inside the walk cycle. – Strawberry Animations Commented Mar 9 at 17:40
- Then, consider answering your own question with the correct solution. This way you'll help someone else stumbling on your same problem – maybe even your future self :) – liggiio Commented Mar 9 at 18:22
1 Answer
Reset to default 0A simple approach is to have a little if-else chain to define order of priority for animations:
if (dashing) {
sprite_index = spr_player_dash;
} else if (walking) {
sprite_index = spr_player_walk;
} else {
sprite_index = spr_player_idle;
}