Create a Crate.
Moves crate from right to left repeatedly until a button is pressed.
Move Crate up 100 px on Y axis.
And crate starts repeating the side to side transition again.
Repeat until Y axis value is 0.
For some reason I cant get the logic to work.
How do I keep creating a NEW crate every few pixels on a NEW Y Axis ?
I know I got to use a transition.to but I cant seem to get it to work.
seems that every time i modify the crate.y value it RESETS to original starting Y value.
Any ideas ?
Here is the code
local physics = require( “physics” )
physics.start()
local disp_width = display.contentWidth --is the width in screen coordinates.
local sky = display.newImage( “bkg_clouds.png” )
sky.x = 160; sky.y = 195
local ground = display.newImage( “ground.png” )
ground.x = 160; ground.y = 445
physics.addBody( ground, “static”, { friction=0.5, bounce=0.3 } )
local crate = display.newImage( “crate.png” )
crate.x =lvl_x;crate.y = 380;crate.rotation = 0
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0.3 } )
function transition_to_left()
transition.to(crate, {time=crate_speed, x = 0, y = crate.y, onComplete = transition_to_right})
end
function transition_to_right()
transition.to(crate, {time=crate_speed, x = 300, y = crate.y, onComplete = transition_to_left})
end
transition_to_right()
–lt blue
local button2 = display.newRoundedRect( 220, 425, 50, 40, 8 )
button2:setFillColor( 0, 170, 170, 170 )
local side_right = display.newImage(“side_right.png”,-95,0)
physics.addBody(side_right,“static”, {density=1,friction=1,bounce=1})
local side_left = display.newImage(“side_left.png”,350,0)
physics.addBody(side_left,“static”, {density=1,friction=1,bounce=1})
function button2:touch(event)
if event.phase == “began” then
crate.y = crate.y - 50
transition_to_right()
end
if event.phase == “ended” then
local crate = display.newImage( “crate.png” )
crate.x =lvl_x;crate.y = 380;crate.rotation = 0
crate.alpha=1
end
return true
end
button2:addEventListener(“touch”,button2)
----------------------------------------------------------------- [import]uid: 11094 topic_id: 16774 reply_id: 316774[/import]
