I have a transition.to command that I want to repeat ad nauseum at a rate that can be tweaked and/or randomized. I'm still a newbie, however, so I don't know how to code repeated actions. It's just an object crossing the screen from left to right:
1 2 3 4 | scooter1.x = -100 scooter1.y = math.random(1,1024) scooter1:play('Scooter 1 moving right') transition.to(scooter1, {time = 1500, delay = 500, x = scooter1.x + 968}) |
use
timer.performWithDelay(milliseconds here, your function here, number of times to repeat(0 for infinite))
Thanks, I tried changing my code to:
1 2 3 4 | scooter1.x = -100 scooter1.y = math.random(1,1024) scooter1:play('Scooter 1 moving right') timer.performWithDelay(1000,transition.to(scooter1, {time = 1500, delay = 500, x = scooter1.x + 968}) , 0) |
Right you need to add your code into a function.
1 2 3 4 5 6 7 8 | function scooterFunction() scooter1.x = -100 scooter1.y = math.random(1,1024) scooter1:play('Scooter 1 moving right') transition.to(scooter1, {time = 1500, delay = 500, x = scooter1.x + 968}) end |
@notts_forest_
Thank you for responding, at the stage I'm at, I really appreciate the walkthrough approach to your answer, something tells me you've got teaching exp:)
I'm getting some odd results off your code sugg. The scooter enters from screen left, pops down to a different y coordinate, and then does this several more times before exiting screen right, slowing down with each pop. The timer seems to be causing the scooterFunction to fire at the random intervals intended, but rather than starting a new scooter crossing the screen with every firing (the effect I want), it's applying itself to the existing scooter that's already making it's way across.
I'm trying to make sense of this, but my head's starting to hurt, any ideas?
Thank you,
Steven
did you create the scooter inside the function ?
for your requirement you should do something like this
1 2 3 4 5 6 7 8 9 10 11 12 | local randTime = math.random( 500, 10000 ) function scooterFunction() --scooter should be declare local inside the function to create --separate instance on each function call local scooter = display.newImage("scooter.png") scooter.x = -100 scooter.y = math.random(1,1024) transition.to(scooter, {time = 1500, delay = 500, x = scooter.x + 968}) end timer.performWithDelay(randTime, scooterFunction, 0) |
Hit the nail on the head, it's working as intended now! So unless the function calls for a new image to be spawned everytime it fires, it will just apply the function repeatedly to the one image spawned outside of the function, I get it! Thanks yet again Renjith for clearing that up, and thanks darkconsoles and notts_forest_ for your help as well:)
send message and call to a person
Forum: Report Spam + PM
[INSTALL_PARSE_FAILED_NO_CERTIFICATES]
[SOLVED] Director ERROR: Failed to execute new( params ) function on 'screen1'
Too many (200) local variables
Corona SVG Level Builder released. Drag and drop physics level editor with Inkscape and SVG.
Small bug in Collectible Items example
Pivot Joints and apparent elasticity
Can't make removeSelf() delayed
Need 10 tester for my cardgame android 2.2-2.3
Corona vs devices with non supported CPUs
Calcudate [FREE | iPhone]
Scaling physics objects
Kunundrum is live!
help with setting drag to an image?
Publishing/Building
New Article on how to make Pulsating Animation with CoronaSDK
Developer needed to port current iPhone game to Corona (Android). Paid job.