I'm new to using sprites and am loving SpriteLoq, but I can't seem to get my sprites to switch to another set of sprites the moment you touch a button (i.e. an attack button). Is there something I'm leaving out or is this just my app running slowly?
here's some of my code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | --attack button listener local function manAttackPress(event) if event.phase == "began" then print("attack button pressed") isAttacking = true justOneAttack = true if isAttacking then if justOneAttack then justOneAttack = false if isJumping then print("isAttacking and jumping") pMan:prepare("pManAttack") pMan:play() else print("isAttacking from ground") pMan:prepare("pManAttack") pMan:play() end end end local function endAttack() isAttacking = false returnToNonAttackAnimation() end timer.performWithDelay(200,endAttack) end end |
Hi Matt,
I haven't had any issues switching sprites, and this is the first time I've heard of any issues with switching.
From the looks of the function every time you press, if isJumping is false then it'll play pManAttack. and then 200 ms later it'll call returnToNonAttackAnimation.
Try replacing the prepare calls with play calls like pMan:play('pManAttack'). You only need to call prepare with the Spriteloq api if you want to display the sprite without playing the animation.
Also what build of Corona are you runnning?
Have you tried the NinjaApp? Does that give you any problems when clicking on the ninja to switch animations? If you send your project files to support@loqheart.com, I can take a closer look.