----------------------------------------------------------------------------------------- -- -- main.lua -- ----------------------------------------------------------------------------------------- display.setStatusBar( display.HiddenStatusBar ) system.activate( "multitouch" ) require "physics" physics.start() local width = display.actualContentWidth local height = display.actualContentHeight local myGroup = display.newGroup() local ground = display.newRect( myGroup, width \* 0.5, height - 5, width, 10 ) ground:setFillColor( 0.1 ) physics.addBody( ground, "static" ) local player = display.newRect( width \* 0.5, height \* 0.5, 100, 100 ) player:setFillColor( 0.93, 0.11, 0.14 ) physics.addBody( player ) local left = display.newRect( 100, height - 100, 200, 200 ) left.alpha = 0.1 local right = display.newRect( width - 100, height - 100, 200, 200 ) right.alpha = 0.1 local up = display.newRect( width - 300, height - 100, 200, 200 ) up.alpha = 0.1 local speed = 0 local function touchListener( event ) if event.phase == "began" then if event.target == left then speed = -10 else speed = 10 end elseif event.phase == "ended" or event.phase == "cancelled" then speed = 0 end end left:addEventListener( "touch", touchListener ) right:addEventListener( "touch", touchListener ) local function update() myGroup.x = myGroup.x - speed end Runtime:addEventListener( "enterFrame", update )
I wanted to simulate a camera so used a display group. Player doesn’t move, it is the group that moves. It works but when my player go left and left and left when there is no ground, i mean when the player doesn’t collide the ground, it should fall but it doesn’t fall. What is wrong with my code? Thanks in advance. I writed topic so fast so sorry for my english.