random position - please assist

Hello. Here is some pretty simple code -

 --Hide status bar from the beginning display.setStatusBar( display.HiddenStatusBar ) -- forward references local centerX = display.contentCenterX local centerY = display.contentCenterY local jitterUp local jitterDown -- create the display object/button local bgImg = display.newImageRect( "images/start.png", 173, 170 ) bgImg.x = centerX bgImg.y = centerY bgImg:scale(.6,.6) --move down local jitterDown = function (obj) transition.to (bgImg, {x=centerX, y=centerY +3, time=50, onComplete=jitterUp}) end -- move up local jitterUp = function (obj) transition.to (bgImg, { x=centerX, y=centerY -3 , time=50, onComplete=jitterDown }) end -- call functions jitterDown() jitterUp() timer.performWithDelay( 50, jitterDown, -1 ) timer.performWithDelay( 50, jitterUp, -1 )

The code works just fine - I am trying to find a way to add random movement of the “jittering” effect. I already tried to go into the transition.to statements and insert “y=math.randomseed(-3,3)”, but it does not work. I’m trying to randomize the Y position of the transition.to statements. No luck, yet.

Please help me figure this out. Thanks a lot, community!

Joe,

Have you tried changing your jitter functions to look something like this?

--move down local jitterDown = function (obj) local randomY = math.random(3) transition.to (bgImg, {x=centerX, y=centerY + randomY, time=50, onComplete=jitterUp}) end -- move up local jitterUp = function (obj) local randomY = math.random(3) transition.to (bgImg, { x=centerX, y=centerY - randomY , time=50, onComplete=jitterDown }) end

Thanks for that bit of code. I was playing around with the math.randomseed command. I was trying to insert it into the transition.to statement, but clearly that was incorrect.

I knew math.random (or math.randomseed) had to be inserted somewhere in that code - i just didn’t know where. Thanks again for the bit of code. Time to go play with it!  :D 

Thanks again for the response.

No problem! Best of luck

Joe,

Have you tried changing your jitter functions to look something like this?

--move down local jitterDown = function (obj) local randomY = math.random(3) transition.to (bgImg, {x=centerX, y=centerY + randomY, time=50, onComplete=jitterUp}) end -- move up local jitterUp = function (obj) local randomY = math.random(3) transition.to (bgImg, { x=centerX, y=centerY - randomY , time=50, onComplete=jitterDown }) end

Thanks for that bit of code. I was playing around with the math.randomseed command. I was trying to insert it into the transition.to statement, but clearly that was incorrect.

I knew math.random (or math.randomseed) had to be inserted somewhere in that code - i just didn’t know where. Thanks again for the bit of code. Time to go play with it!  :D 

Thanks again for the response.

No problem! Best of luck