我对 Lua 和 corona 都是新手,一直在努力让我的游戏起飞(双关语)
我基本上想顺时针和逆时针旋转我的火箭,并调整它的 x 和 y 以便在按下推力按钮时朝着它的方向移动
我尝试了很多方法,并且陷入了方程式以及如何实现它们,请参见下面的代码(如果偏离标记,请随意大笑)
local rocket = display.newSprite( rocketsheet, rocketsequencedata)
physics.addBody(rocket, { bounce = 0.5} )
rocket.x = display.contentWidth/3
rocket.y = display.contentHeight/1.5
rocket.rotation = angle
rocket:setSequence("idle")
rocket:play()
local inverseRotation = rocket.rotation + math.pi
local speedX = 0.000
local speedY = 0.005
speedX = speedX * math.cos(inverseRotation) + speedY * math.sin(inverseRotation)
speedY = -speedX * math.sin(inverseRotation) + speedY * math.cos(inverseRotation)
function thrust(event)
rocket:applyLinearImpulse(speedX, speedY, rocket.x, rocket.y)
rocket:setSequence("afterburn")
rocket:play()
end
function rotateleft(event)
speedX = speedX - 0.0005
rocket.rotation = rocket.rotation - 2
end
function rotateright(event)
speedX = speedX + 0.0005
rocket.rotation = rocket.rotation + 2
end
controlthrust:addEventListener( "touch", thrust)
controlleft:addEventListener( "touch", rotateleft)
controlright:addEventListener( "touch", rotateright)