Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Doing something else with a sprite in the middle of a SpriteTweenChain

Author
Message
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 22nd Jun 2018 14:05 Edited at: 22nd Jun 2018 14:16
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:



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



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.
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 22nd Jun 2018 15:11 Edited at: 22nd Jun 2018 15:12
I think I've sussed it on a small mini project



I'm using an extra variable to store if it's just been flipped so that it doesn't switch the image multiple times in the main do loop and I'm storing the time when the flip will happen in this example the flip will happen 1 second into the main tween chain.

This works on fast flips like 0.1 seconds.

Hopefully it will work in my main project.
Bengismo
7
Years of Service
User Offline
Joined: 20th Nov 2017
Location: Yorkshire, England
Posted: 22nd Jun 2018 15:41 Edited at: 22nd Jun 2018 15:43
Looks like you have it sorted

...a few options i would consider

1) Use sprite animation:
just 2 frames...1 front...1 back (use AddSpriteAnimationFrame( iSpriteIndex, iImageIndex ))
Then just set the frame rate so that the change occurs when you want....(FPS=1/Time before the change)
Then call PlaySprite when you start the flip/tween change
No monitoring the time and you can flip back easily too

2) Use a shader:
You can tween sprite alpha/red/breen/blue
So use a shader thta when alpha is <0.5 it shows the front and when alpha is>0.5 is shows the back and then you can tween an image being shown
Everything is then covered in tweens
Its possible to write a shader that allows you to set a shader constant or use the alpha value to display one of 52 cards if wanted

3) Use 3d
You can mix 3d into a 2d scene
One image on the front...one image on the back of a simple 2 sided quad
Tween the actual y rotation to flip the cardand there are no images to change at all.
Its like flipping a real card
Kevin Cross
21
Years of Service
User Offline
Joined: 15th Nov 2003
Location: London, UK
Posted: 22nd Jun 2018 18:05
Thanks for the suggestions Bengismo. I've dabbled a little with 3D in AppGameKit but not enough to have felt confident going that route. Seeing as it would have only been flat planes for each card though I probably could have coped.

I do have it sorted now though and it's working in my app, so for now I'm going to stick with AddTweenSprite and timers. I worked out I didn't actually need the flag variable "cardFlipped". Only needed the two floats to store the different times. One time for when the tween starts and the other time for when the flip is due.

I can call the one function with a string of parameters to say how I want a card to animate i.e.

TweenCard(cardID, "delay:0.1;moveCardTo:50,50;delay:0.1;flip:1;showOptions:1")

And the function will add each of those tweens to the chain in that order with the relevant values. It does other things like slide in and out of the card pile, add to discard pile, and resize.

Login to post a reply

Server time is: 2024-11-23 21:09:50
Your offset time is: 2024-11-23 21:09:50