goplus / spx

spx - A Scratch Compatible Go/Go+ 2D Game Engine for STEM education
https://builder.goplus.org
Apache License 2.0
100 stars 28 forks source link

(Costume-group) Animation issues #300

Closed nighca closed 3 weeks ago

nighca commented 2 months ago

Project: animation.zip

For sprite Fighter:

Config:

{
  "fAnimations": {
    "fight": {
      "from": "__animation_fight_attack_1-1",
      "to": "__animation_fight_attack_1-4",
      "duration": 0.4,
      "anitype": 0
    },
    "dying": {
      "from": "__animation_dying_dead-1",
      "to": "__animation_dying_dead-3",
      "duration": 0.6,
      "anitype": 0
    },
    "walk": {
      "from": "__animation_walk_walk-1",
      "to": "__animation_walk_walk-8",
      "duration": 0.8,
      "anitype": 0
    },
    "default": {
      "from": "__animation_default_idle-1",
      "to": "__animation_default_idle-6",
      "duration": 0.6,
      "anitype": 0
    }
  },
  "defaultAnimation": "default",
  "animBindings": {
    "die": "dying",
    "step": "walk"
  }
}

Code:

onKey KeyUp, => {
    say "animate fight", 0.3
    animate "fight"
}

onKey KeyDown, => {
    say "die", 0.3
    die
}

onKey KeyLeft, => {
    say "step left"
    setRotationStyle LeftRight
    turnTo Left
    step 50
}

onKey KeyRight, => {
    say "step right"
    setRotationStyle LeftRight
    turnTo Right
    step 50
}

There are some issues:

  1. The animation default (which is bound as defaultAnimation) is played only once while sprite in default state. It is expecetd to be played repeatedly (see details in https://github.com/goplus/builder/issues/603#issuecomment-2180367864)
  2. After animation fight (played by calling animate "fight") finished playing, the sprite does not return to the default state, while it keeps the last csotume of animation fight
  3. If we call step 50, it is expected to play animation walk (which is bound to state step). However, the sprite plays fight, and then die, and then walk, and then panic:

    panic: invalid costume index [recovered]
        panic: invalid costume index
nighca commented 1 month ago
  1. To make it possible to bind one animation to multiple states at the same time, we should put all animations in one place, e.g., fAnimations.
nighca commented 1 month ago

Now in builder, all the animations are frame animations, based on https://github.com/goplus/spx/pull/303 we do configure like this:

nighca commented 3 weeks ago

fixed by #303