Forums

OverviewV-Play 1 SupportChange Sprite's "loop" property at runtime? › Reply To: Change Sprite's "loop" property at runtime?

OverviewV-Play 1 SupportChange Sprite's "loop" property at runtime? › Reply To: Change Sprite's "loop" property at runtime?
#6072

Alex
V-Play Team

Hi again Chrisu,

here’s what you can do, although it might seem a little dirty:

SpriteSequenceFromFile {
  id: spriteSquence
  //...

  // the animation for walking
  Sprite {
    name: "walk"
    //...
  }

  // the animation for rolling
  Sprite {
    name: "roll1"
    loop: false
    //...
    onAnimationFinished: {
      scene.checkForStandingUp("roll2")
    }
  }

  // the same animation for rolling, just with different name. we will switch between both rolling animations while rolling
  // the reason we are doing is because the jumpTo(...) function only works if the new sprite is different from the previous one
  Sprite {
    name: "roll2"
    loop: false
    //...
    onAnimationFinished: {
      scene.checkForStandingUp("roll1")
    }
  }
}

and in your game scene or where ever you want to check if you can stand up:

function checkForStandingUp(toggleSpriteName) {
      // here you can check whether you want to resume rolling or stand up
      if(allowedToStandUp) {
        squabySprite.jumpTo("walk")
      }
      else {
        squabySprite.jumpTo(toggleSpriteName)
      }
    }

In a nutshell: We have to toggle the roll animations because a jumpTo(…) to the same animation as the current one is currently not supported.┬áBy default you are walking. You start rolling with jumpTo(“roll1”). When the animation finishes you check if you can stand up. If YES, jumpTo(“walk”), if NO you gotta keep on rolling, so you jumpTo(“roll2”). If that animation finishes as well, we will check again and either switch to “walk” or “roll1”.

Does this work for you?

Cheers,
Alex

Voted #1 for:

  • Easiest to learn
  • Most time saving
  • Best support

Develop Cross-Platform Apps and Games 50% Faster!

  • Voted the best supported, most time-saving and easiest to learn cross-platform development tool
  • Based on the Qt framework, with native performance and appearance on all platforms including iOS and Android
  • Offers a variety of plugins to monetize, analyze and engage users
FREE!
create apps
create games
cross platform
native performance
3rd party services
game network
multiplayer
level editor
easiest to learn
biggest time saving
best support