2
進出口新的這兩個Lua和電暈,並已試圖讓我的遊戲升空(雙關語意)旋轉在二維空間中的火箭,並允許它在方向移動的面對,LUA,電暈
我本質想要順時針和逆時針旋轉我的火箭,並調整其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)