Camera and Physics Problem

----------------------------------------------------------------------------------------- -- -- 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.

Have you verified your touch listeners?  Those look wrong to me.

This is how I implement touch listeners.

local speed = 0 local function touchListener( self, event ) if( event.phase == "began" ) then speed = speed + self.speed end elseif( event.phase == "ended" ) then speed = speed - self.speed end end local left = display.newRect( 100, height - 100, 200, 200 ) left.alpha = 0.1 left.touch = touchListener left.speed = -10 local right = display.newRect( width - 100, height - 100, 200, 200 ) right.alpha = 0.1 right.touch = touchListener right.speed = 10 left:addEventListener( "touch" ) right:addEventListener( "touch" )

I can’t solve my problem :confused: My player doesn’t fall after walking out of platform.

Have you verified your touch listeners?  Those look wrong to me.

This is how I implement touch listeners.

local speed = 0 local function touchListener( self, event ) if( event.phase == "began" ) then speed = speed + self.speed end elseif( event.phase == "ended" ) then speed = speed - self.speed end end local left = display.newRect( 100, height - 100, 200, 200 ) left.alpha = 0.1 left.touch = touchListener left.speed = -10 local right = display.newRect( width - 100, height - 100, 200, 200 ) right.alpha = 0.1 right.touch = touchListener right.speed = 10 left:addEventListener( "touch" ) right:addEventListener( "touch" )

I can’t solve my problem :confused: My player doesn’t fall after walking out of platform.