Hello Corona Community!
I would like to build a game where the level is bigger than the screen. However, I’m running into the issue of where the player does not collide with other physics objects.
In the code below, the player (using Peach’s awesome tutorials) stays in the middle of the screen with a simple d-pad in the bottom left corner for controls. I then placed three blocks in the level, one on screen and two off screen, and I want the player to stop when they collide with one of the blocks.
What can I do to make the player stop when they collide the blocks? I’ve tried setting the blocks to not allow sleeping, and that did not work. Help, please?
[code]
– Declare Game Variables
local motionx = 0
local motiony = 0
local speed = 2
– Insert Player and Controls
local player = display.newCircle (100,100,14)
player.x = _G.W/2
player.y = _G.H/2
physics.addBody(player, { density = 0, friction = 0, bounce = 0 })
player.isSleepingAllowed = false
local up = display.newCircle( 70, 230, 18)
local down = display.newCircle ( 70, 290, 18)
local left = display.newCircle ( 30, 260, 18 )
local right = display.newCircle ( 110, 260, 18)
local function stop (event)
– Stop movement when no arrow is pushed.
if event.phase ==“ended” then
motionx = 0
motiony = 0
end
end
Runtime:addEventListener(“touch”, stop )
local function moveGroups (event)
–player.x = player.x + motionx
–player.y = player.y + motiony
levelGroup.x = levelGroup.x - motionx
levelGroup.y = levelGroup.y - motiony
end
Runtime:addEventListener(“enterFrame”, moveGroups)
function up:touch()
motionx = 0
motiony = -speed
end
up:addEventListener(“touch”, up)
function down:touch()
motionx = 0
motiony = speed
end
down:addEventListener(“touch”, down)
function left:touch()
motionx = -speed
motiony = 0
end
left:addEventListener(“touch”,left)
function right:touch()
motionx = speed
motiony = 0
end
right:addEventListener(“touch”,right)
– END Insert Player and Controls
– Start Level Creation
levelGroup = display.newGroup();
block = display.newRect (100,100,100,100)
block.x = 100; block.y = 100;
physics.addBody( block, “dynamic”, { } );
block.isSleepingAllowed = false
levelGroup:insert(block);
block2 = display.newRect (100,100,100,100)
block2.x = -25; block2.y = 100;
physics.addBody( block2, “dynamic”, { } );
block2.isSleepingAllowed = false
levelGroup:insert(block2);
block3 = display.newRect (100,100,100,100)
block3.x = -150; block3.y = 100;
physics.addBody( block3, “dynamic”, { } );
block3.isSleepingAllowed = false
levelGroup:insert(block3);
– END Level Creation
[/code] [import]uid: 14218 topic_id: 31383 reply_id: 331383[/import]