最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

game development - Sprite not updating correctly in GMS2 - Stack Overflow

programmeradmin9浏览0评论

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
Add a comment  | 

1 Answer 1

Reset to default 0

A 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;
}
发布评论

评论列表(0)

  1. 暂无评论