我正在开发赛车游戏,我想要实现的目标之一是确保背景图像无限移动,同时当你触摸背景时,它会改变汽车的车道。
function scene:create( event )
physics.start();
physics.setGravity(0, 0);
local group = self.view;
local bg = display.newImageRect(group, "IMG/bg.png", 384, totalHeight);
bg.x, bg.y = centerX, centerY;
function bg:touch(event)
if event.phase == "began" then
if event.x < centerX then
redCar:changeLane();
else
blueCar:changeLane();
end
end
end
bg:addEventListener("touch", bg);
end
我在网上尝试了不同的文章,但都没有效果。任何指南将不胜感激。感谢
答案 0 :(得分:0)
以下是制作垂直滚动背景的代码:
local function moveBg(dt)
bg1.y = bg1.y + scrollSpeed * dt
bg2.y = bg2.y + scrollSpeed * dt
if (bg1.y - display.contentHeight/2) > display.actualContentHeight then
bg1:translate(0, -bg1.contentHeight * 2)
end
if (bg2.y - display.contentHeight/2) > display.actualContentHeight then
bg2:translate(0, -bg2.contentHeight * 2)
end
end
完整的教程在这里:http://lomza.totem-soft.com/tutorial-scrollable-background-in-corona-sdk/