I’m creating a game where you have a player, he walks left and right, jumps, ducks and fires. He starts on to of a building and goes down using elevators. There are 30 floors until the ground, so obviously it is not possible to fit the whole level on a single screen.
So I move the scene accordingly to the players Y position.
local function moveCamera() if (player.y \> screenH/2) or (player.y \< screenH/2) then content.y = -player.y + screenH/2 end end Runtime:addEventListener("enterFrame", moveCamera)
To make it more clear what am I moving:
function scene:create(event) local sceneGroup = self.view -- all display objects must be inserted into group sceneGroup:insert(camera) sceneGroup:insert(content) sceneGroup:insert(score)
for i=0, #walls do
content:insert(walls[i])
end
content:insert(elevator)
content:insert(player)
…
The physics gets corrupted using this. At least the hybrid mode shows so. And when I try to create a bullet on player’s Y position, it is created where the hybrid overlay box shows he is, not where the actual sprite is.
My question is, is it possible to have camera following player (only on the Y axis) in a large environment and still have physics? In the docs you say that I shouldn’t move groups that contain physics objects. What should I move then?