Android Lua Gideros:触摸画线有问题
在我使用Gideros和Lua的游戏中,我希望玩家能够从触屏点到释放点绘制一条直线。但是,当我尝试运行此代码时,总是会收到一条错误消息。代码如下:Android Lua Gideros:触摸画线有问题,android,graphics,lua,gideros,Android,Graphics,Lua,Gideros,在我使用Gideros和Lua的游戏中,我希望玩家能够从触屏点到释放点绘制一条直线。但是,当我尝试运行此代码时,总是会收到一条错误消息。代码如下: local function onMouseDown(event) event.x = startx event.y = starty event:stopPropagation() end local function onMouseUp(event) event.x = endx event.y = e
local function onMouseDown(event)
event.x = startx
event.y = starty
event:stopPropagation()
end
local function onMouseUp(event)
event.x = endx
event.y = endy
event:stopPropagation()
local line = Shape.new()
line:setLineStyle(5, 0x0000ff, 1)
line:beginPath()
line:moveTo(startx,starty)
line:lineTo(endx,endy)
line:endPath()
end
下一行是代码中的第66行:
scene:addEventListener(Event.MOUSE_DOWN, onMouseDown)
scene:addEventListener(Event.MOUSE_UP, onMouseUp)
下面是我设置“场景”的一行:
以下是我的错误消息:
main.lua:66:找不到索引“\uu userdata”
堆栈回溯:
main.lua:66:在主块中
有人知道我为什么收到这个消息吗?如果你知道的话
scene = gideros.class(Sprite)
这意味着场景是一个类,但您只能将事件侦听器添加到类的实例,而不能添加到类本身
因此,类似这样的方法应该有效:
Scene = gideros.class(Sprite)
local scene = Scene.new()
stage:addChild(scene)
代码中的第66行在哪里?我刚才在我的问题中添加了这一行。我这样做了,现在当我从屏幕上松开手指时,它说:main.lua:62:bad argument#1到“moveTo”(数字预期为零)堆栈回溯:main.lua:62:在函数中,您在错误的方向上执行赋值,它应该是
startx=event.x
,etcThanks!这很有效!这是我问题的第二部分:也许你可以回答!
Scene = gideros.class(Sprite)
local scene = Scene.new()
stage:addChild(scene)