Hi, Peach!
Before I go any further, thanks for being a great resource and providing wonderful tutorials. I would be lost without those 
Anyway, I guess it would be better to post some codes to make things easier. It is just like Mario type platform.
Here are some facts.
- Stage is 2X screen width.
- There are boxes (no shown in this code) on stage.
- Boxes, bg, and the player are all in the same group (bgGroup).
- Player can interact with the boxes (collide, jump on, etc)
- Once the player moves to 1/2 x position (moving from left to right) on screen, bgGroup starts moving opposite direction (left) and the player continue moving right but visually it stays put in the center because bgGroup is moving left.
I am wondering whether I am approaching this correctly and if so, how can I keep the background from scrolling and the player stay put in center, when the player encounters a static box and can’t walk further but d-pad is being pressed (touched)?
[code]
local playerRight = 0
local playerLeft = 0
local playerSpeed = 2
local motionPlayer = 0
local motionBg = 0
– actions
local function movePlayerRight(e)
if playerRight == 1 then
if player.x < _W * 0.5 then
motionPlayer = playerSpeed
motionBg = 0
elseif player.x > _W * 0.5 and bgGroup.x > -_W then
motionPlayer = playerSpeed
motionBg = -playerSpeed
else
motionPlayer = playerSpeed
motionBg = 0
end
player.x = player.x + motionPlayer
bgGroup.x = bgGroup.x + motionBg
end
– don’t let it go past right wall
if player.x >= _W * 2 then
player.x = _W * 2
end
end
local function movePlayerLeft(e)
if playerLeft == 1 then
if player.x > (_W * 2) - _W * 0.5 then
motionPlayer = playerSpeed
motionBg = 0
elseif player.x < (_W * 2) - _W * 0.5 and player.x > _W * 0.5 then
motionPlayer = playerSpeed
motionBg = -playerSpeed
else
motionPlayer = playerSpeed
motionBg = 0
end
player.x = player.x - motionPlayer
bgGroup.x = bgGroup.x - motionBg
end
– don’t let it go past left wall
if player.x <= 0 then
player.x = 0
end
end
local function EnterFrame(e)
movePlayerRight(e)
movePlayerLeft(e)
end
Runtime:addEventListener( “enterFrame” , EnterFrame )
function goRight(e)
if(e.phase == “began”) then
playerRight = 1
elseif(e.phase == “ended” or e.phase == “cancelled”) then
playerRight = 0
end
return true
end
function goLeft(e)
if(e.phase == “began”) then
playerLeft = 1
elseif(e.phase == “ended” or e.phase == “cancelled”) then
playerLeft = 0
end
return true
end
[/code] [import]uid: 39031 topic_id: 15550 reply_id: 57504[/import]