Making image change loop infinitely
ralphbugs
Member Posts: 39
Guys, how do you make a series of images changing and looping?
Eg:
Image1 comes out, after 5 seconds change into Image2, then after another 5 seconds it will change into Image3 and then after another 5 seconds it will change back to Image1 and I want to make this looping.
I tried to use timer but failed. After Image3, it won't change into Image1 and stays at Image3. I want to make an advertisement like banner.
Can somebody give me a hand here?
Answers
Create a text attribute called self.imagePrefix and set its value to "Image" (without the quotes). Create an integer attribute called self.imageNumber and set its value to 0.
Timer every 5 seconds Change attribute self.imageNumber to mod(self.imageNumber,3)+1 Constrain attribute self.Image to self.imagePrefix..self.imageNumber
New to GameSalad? (FAQs) | Tutorials | Templates | Greenleaf Games | Educator & Certified GameSalad User
Use the animate behavior. It's better and more efficient.
The 'problem' with the animate behavior is that the request is for a change in image every 5 seconds...
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
You can simply drag-duplicate actors within Animate behaviour, so in this case you'd set Animate to 1fps, and then drag-duplicate 5 of each image. It works just fine, although that doesn't feel like a very elegant solution.
Although saying that I use the method @tatiang posted for most things, also the fast-frame-swap method will do the trick too, as you can enter any value you want for the time multiplier.
https://forums.gamesalad.com/discussion/63454/fast-frame-swap
@Socks, agreed. That would work but would feel 'clunky' at best.
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
Yeah, I edited my post just before you posted to make the very same point, it works just fine but it's not very elegant - and while it's fine for a three frame sequence where each frame is held for 5 seconds, it'd become super-clunky™ with a 40 or 50 image sequence . . .
@Socks, hey! you stole my trademark!
http://jamie-cross.net/posts/ ✮ Udemy: Introduction to Mobile Games Development ✮ Learn Mobile Game Development in One Day Using Gamesalad ✮ My Patreon Page
I was also planning to use the animation behaviour but when thinking back I have to animate in AE first then make the sequence made me hold that plan. But never crossed in my mind that I can just duplicate the image in behaviour and set the frame to 1fps like you mentioned Socks.
I'm now try using Tatiang method first (for learning sake) but where do I put the change image behaviour? Inside the timer or just underneath it? Oh, and the Contraint attribute self.image will become blank after each time I preview. I don't know why.
Inside.
I think i miss something here. The images does not come out. Could you take a look at this demo project file?
https://drive.google.com/file/d/0By5DNbqYRGiOUkxUNGZEanVMQ1k/view?usp=sharing
Well, sorry about that. I don't know why I also cannot open the file in the previous link. Though your demo file works! Thank you very much for assisting me
Here is what I get combining your method. Thanks mate!
https://drive.google.com/file/d/0By5DNbqYRGiORGtuSjhiSDExWkU/view?usp=sharing
(have double checked the link and its working now)