Hello all,
I am trying to do this and i am stuck.
I made a button that adds + 1 to the variable lvl every time
it is pressed.
Now when that “lvl” variable increments,
I want the transition to move right to left at a specific “Y” axis(a.k.a. level)
I can get the variable to increment, but the crates dont appear
to work correctly Why ?
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 } )
– create a large button
–local rect = display.newRect( 20, 20, 50, 50 )
–rect:setFillColor( 128, 64, 64 )
local lvl = 0
if (lvl >= 1) or (lvl <= 2) then
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 } )
end
if (lvl >= 3) or (lvl <= 4) then
local crate = display.newImage( “crate.png” )
crate.x =lvl_x;crate.y = 320;crate.rotation = 0
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0.3 } )
end
if (lvl >= 5) or (lvl <= 6) then
local crate = display.newImage( “crate.png” )
crate.x =lvl_x;crate.y = 260;crate.rotation = 0
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0.3 } )
end
if (lvl >= 7) or (lvl <= 8) then
local crate = display.newImage( “crate.png” )
crate.x =lvl_x;crate.y = 220;crate.rotation = 0
physics.addBody( crate, { density=3.0, friction=0.5, bounce=0.3 } )
end
crate = {}
function transition_to_left()
transition.to(crate, {time=5000, x = 0, y = crate.y, onComplete = transition_to_right})
end
function transition_to_right()
transition.to(crate, {time=5000, 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)
lvl = lvl + 1
print (" button 2 " … lvl)
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
–print("at the end " … lvl_x)
–lvl_x = 50
– crate.alpha=1
end
return true
end
button2:addEventListener(“touch”,button2) [import]uid: 11094 topic_id: 16795 reply_id: 316795[/import]
[import]uid: 3826 topic_id: 16795 reply_id: 62913[/import]