Okay so, I have been surfing the web for weeks to find the answer to this question:
How can I loop my transition for example, I make my object move to a random position but after it moved their I want it to go back to it’s starting position and repeat the transition. Please Help, Oh and I commented some things for me to go back to if I made a mistake
Here is my lengthyyyyy codeeee:
–[[— INITIAL VALUES -----]]
display.setStatusBar( display.HiddenStatusBar )
background = display.newImageRect( “background.png”, display.contentWidth, display.contentHeight+100 )
background.x = display.contentCenterX
background.y = display.contentCenterY
local physics = require “physics”
local btn = display.newImageRect(“button.png”,150,150)
local menuIcon = display.newImageRect( “menu.png”, 60, 60 )
menuIcon.x = display.contentCenterX-120
menuIcon.y = display.contentCenterY+240
local playsound = display.newImageRect( “playsound.png”, 50, 50)
playsound.x = display.contentCenterX + 90
playsound.y = display.contentCenterY - 260
local stopsound = display.newImageRect( “stopsound.png”, 50, 50)
stopsound.x = display.contentCenterX + 140
stopsound.y = display.contentCenterY - 260
– Trying to create an asteriod Shower
btn.x = math.random( 1,150 )
btn.y = -125
transition.to(btn, {
x = math.random( 150,300 ),
y = math.random( 700,800 ),
time = 5000,
})
–[[
for i=1,10 do
if btn.x >= 150 and btn.y >= 700 then
btn.x = math.random( 1,150 )
btn.y = -125
transition.to(btn, {
x = math.random( 150,300 ),
y = math.random( 700,800 ),
time = 5000,
})
end
end
]]
–
–[[
btn.x = display.contentWidth/2
btn.y = display.contentHeight/2
]]
amountOfTimeYouClicked = 0
testText = display.newText( amountOfTimeYouClicked, display.contentWidth/2, display.contentHeight/2 , “spaceage.ttf”, 30 )
testText:setFillColor( 250,223,0 )
test1Text = display.newText( "Clicks ", display.contentWidth/2, display.contentHeight/6 , “SPACEBAR.ttf”, 20 )
test1Text.x = display.contentCenterX/2.5
test1Text.y = display.contentCenterY-260
testText.x = display.contentCenterX-110
testText.y = display.contentCenterY-235
– audio
local sndTouch = audio.loadSound(“metal-clash.wav”)
local sndBackground = audio.loadStream( “backgroundmusic.ogg”)
local function audioloop()
if audio.isChannelActive(2) == true then
audio.resume()
else
audio.play(sndBackground, {channel = 2, loop = -1})
end
end
playsound:addEventListener( “touch”, audioloop)
local function stopaudioloop()
audio.pause()
end
stopsound:addEventListener( “touch”, stopaudioloop)
local function pushBtn(event)
if event.phase == “began” then
amountOfTimeYouClicked = amountOfTimeYouClicked + 1
print( amountOfTimeYouClicked )
testText.text = tostring(amountOfTimeYouClicked)
audio.play(sndTouch)
– Makes Asteriod Rotate
transition.to( btn, { rotation=-45, time=500, transition=easing.inOutCubic } )
transition.to( btn, { rotation=90, time=500, transition=easing.inOutCubic } )
if btn.rotation == -45 then
transition.to(btn, {rotation = 90, time = 500, transition=easing.inOutCubic})
elseif btn.rotation == 90 then
transition.to( btn, { rotation=-45, time=500, transition=easing.inOutCubic } )
end
—
end
end
btn:addEventListener( “touch”, pushBtn )
local settings = display.newImageRect(“gear.png”, 65 , 65)
settings.x = display.contentCenterX + 120
settings.y = display.contentCenterY+240
local resetBtn = display.newImageRect(“reset.png”, 65, 65)
resetBtn.x = display.contentCenterX
resetBtn.y = display.contentCenterY+235
local function resetingBtn(event)
if event.phase == “began” then
print( 0 )
testText.text = 0
amountOfTimeYouClicked = testText.text
end
end
resetBtn:addEventListener( “touch”, resetingBtn)
– Trying to make a Asteriod Wrap around the Screen
–[[
– Makes Asteriod Rotate
btn.rotation = -45
local reverse = 1
local function rockRect()
if ( reverse == 0 ) then
reverse = 1
transition.to( btn, { rotation=-45, time=500, transition=easing.inOutCubic } )
else
reverse = 0
transition.to( btn, { rotation=90, time=500, transition=easing.inOutCubic } )
end
end
timer.performWithDelay( 600, rockRect, 0 )
—
]]