In the current version of my app I've got a function that slides out a card, a function that resizes the card and moves it and then another function to flip the card. Each function uses a bunch of tweens and runs a simple loop after each one while the tween is running to stop it from moving on to the next function. Something like this:
function SlideOutCard()
tween = CreateTween(0.2)
SetTweenSpriteX(tween, currentX, newX, TweenLinear())
SetTweenSpriteY(tween, currentY, newY, TweenLinear())
PlayTweenSprite(tween, cardSprite, 0)
if (GetTweenPlaying(tween, cardSprite))
UpdateAllTweens(GetFrameTime())
Sync()
endif
endfunction
function FlipCard()
cardWidth = GetSpriteWidth(cardSprite)
tween = CreateTween(0.2)
SetTweenSpriteSizeX(tween, cardWidth, 0, TweenLinear())
PlayTweenSprite(tween, cardSprite, 0)
if (GetTweenPlaying(tween, cardSprite))
UpdateAllTweens(GetFrameTime())
Sync()
endif
if (cardType = 1) then SetSpriteImage(cardSprite, imgCard1)
if (cardType = 2) then SetSpriteImage(cardSprite, imgCard2)
if (cardType = 3) then SetSpriteImage(cardSprite, imgCard3)
tween = CreateTween(0.2)
SetTweenSpriteSizeX(tween, 0, cardWidth , TweenLinear())
PlayTweenSprite(tween, cardSprite, 0)
if (GetTweenPlaying(tween, cardSprite))
UpdateAllTweens(GetFrameTime())
Sync()
endif
endfunction
In the flip function I tween the width of the sprite to 0, change the image and then tween the width back to it's original width to give the impression of a card flipping.
This all works.
I've recently found TweenChains and notice that I can put all of this in one chain which is also working, however I can't get the card image to change in the middle of it. I've tried adding some code outside of the function that changes the card image if the width is 0 or close to 0 but it seems to miss it sometimes or does it too early etc.
This is what the new combined function kind of looks like with a tween chain
function AnimateCard()
cardWidth = GetSpriteWidth(cardSprite)
tweenChain = CreateTweenChain()
tween1 = CreateTween(0.2)
SetTweenSpriteX(tween1, currentX, newX, TweenLinear())
SetTweenSpriteY(tween1, currentY, newY, TweenLinear())
AddTweenSpriteChain(tweenChain, tween1, cardSprite, 0)
tween2 = CreateTween(0.2)
SetTweenSpriteSizeX(tween2, cardWidth, 0, TweenLinear())
AddTweenSpriteChain(tweenChain, tween, cardSprite, 0)
// CHANGE CARD IMAGE OBVIOUSLY DOESN'T WORK HERE AS THE TWEEN ISN'T EVEN PLAYING YET.
//if (cardType = 1) then SetSpriteImage(cardSprite, imgCard1)
//if (cardType = 2) then SetSpriteImage(cardSprite, imgCard2)
//if (cardType = 3) then SetSpriteImage(cardSprite, imgCard3)
tween3 = CreateTween(0.2)
SetTweenSpriteSizeX(tween3, 0, cardWidth , TweenLinear())
PlayTweenChain(tweenChain)
endfunction
// I'VE TRIED ADDING SOMETHING LIKE THIS ELSEWHERE IN THE CODE.
// I HAVE PLAYED AROUND WITH CHECKING DIFFERENT RANGES OF WIDTHS I.E WIDTH >= 0 AND WIDTH <= 5
if (GetTweenChainPlaying(tweenChain) = 1 and GetSpriteWidth(cardSprite) = 0)
if (cardType = 1) then SetSpriteImage(cardSprite, imgCard1)
if (cardType = 2) then SetSpriteImage(cardSprite, imgCard2)
if (cardType = 3) then SetSpriteImage(cardSprite, imgCard3)
endif
None of this code is the code used in my program. Just typed it in to the forum post so it may contain errors or missing something.
Does anyone know how I might change the image of the sprite at a certain point in the tween please? I'd prefer not to have to go back to the old method as I quite like the TweenChains now that I've found them as they allow me to queue quite a few different tweens (not all mentioned) that I want to apply to the card sprite.