0
爲標題美國我有一個事件偵聽器從我的火箭級事件偵聽器從外部模塊調用函數
調用一個函數,但我在下面說調用函數的代碼收到錯誤信息。已收到的CONSOLE
ROCKETCLASS.LUA
module(..., package.seeall)
function rocket()
local rocket = {}
local rocket_mt = { __index = rocket } -- metatable
local sprite
local rockettop, rocketbottom, speedX, speedY
function rocket.new() -- constructor
local newRocket = {
sprite = "red-rocket.png"
}
return setmetatable(newRocket, rocket_mt)
end
function rocket:draw(x,y,group)
local spritesheetdata = {
width = 30,
height = 55,
numFrames = 7,
sheetContentWidth = 210,
sheetContentHeight = 55,
}
local spritesheet = graphics.newImageSheet("red_rocket.png", spritesheetdata)
local spritesequencedata = {
{ name = "idle", frames = {1},
} ,
{ name = "afterburn",
start = 2,
count = 2,
time = 500,
loopCount = 0, -- optional default 0(infinite)
loopDirection = "forward" -- optional (default)
} ,
{ name = "explode",
start = 4,
count = 4,
time = 1200,
loopCount = 1
}
}
sprite = display.newSprite(spritesheet, spritesequencedata)
rockettop = {-14.5, 5, 0, -25,14.5,5}
rocketbottom = {-14.5,7,-14.5,6,14.5,6,14.5,7}
physics.addBody(sprite, {shape = rockettop},{bounce = 0.5,friction = 0.6, shape = rocketbottom})
sprite.angularDamping = 2
sprite.x = x
sprite.y = y
sprite:setSequence("idle")
sprite:play()
group:insert (sprite)
end
function rocket:thrust(event)
speedX = 0.0025 * (math.sin(sprite.rotation*(math.pi/180)))
speedY = -0.0025 * (math.cos(sprite.rotation*(math.pi/180)))
if(event.phase =="began") then
sprite:applyLinearImpulse(speedX, speedY, sprite.x, sprite.y)
return true
end
sprite:setSequence("afterburn")
sprite:play()
end
return rocket
end
和CONTROLS.LUA
module(..., package.seeall)
rocket = require("rocketclass")
local controlthrust = display.newImage("thrust control.png")
controlthrust.y = display.contentWidth/1.6
controlthrust.x = display.contentWidth/1.1
local controlleft = display.newImage("direction controls.png")
controlleft.y = display.contentWidth/1.6
local controlright = display.newImage("direction controls.png")
controlright.y = display.contentWidth/1.6
controlright.x = display.contentWidth/6
controlright.rotation = 180
controlthrust:addEventListener("touch",rocket:thrust)
錯誤是:
controls.lua:21:試圖調用方法 '推力' 堆回溯: C:功能'錯誤' ?:功能'gotoScene' ... nts \ corona項目\火箭着陸器 - 類\ menu.lu
感謝您的回覆,我在level1.lua(未顯示)中做到了這一點,但是我已經通過重新創建火箭類和刪除已棄用的方法模塊(...,package.seeall)來修復問題 我現在可以完全控制我的火箭和所有三個lua文件正在互動,如果你想看,請讓我知道 – Krisdom