LUA Gideros:触摸Touble绘图线LUA、Gideros、Touble

2023-09-07 09:50:45 作者:奈何桥上等你

在使用Gideros和Lua我的比赛,我希望球员能够吸取他们触摸屏幕,直到他们释放点的点的直线。然而,当我尝试运行此code,我总是得到一个错误信息。这里是code:

In my Game using Gideros and Lua, I want players to be able to draw a straight line from the point they touch the screen until the point they release. However, when I try run this code, I always get an error message. Here is the code:

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在我的code:

This next line is line 66 in my code:

scene:addEventListener(Event.MOUSE_DOWN, onMouseDown)
scene:addEventListener(Event.MOUSE_UP, onMouseUp)

下面是我设置了现场的路线:

Here is the line where I set up "scene":

scene = gideros.class(Sprite)

这是我的错误消息:

Here is my error message:

main.lua:66:索引__userdata'无法找到堆栈回溯:    main.lua:66:主块

main.lua:66: index '__userdata' cannot be found stack traceback: main.lua:66: in main chunk

有谁知道为什么我收到这条消息?谢谢!

Does anyone know why I am getting this message? Thank you!

推荐答案

如果您

scene = gideros.class(Sprite)

这意味着场景是一类,但你只能到类的实例,而不是类本身。

it means scene is a class, but you can add event listeners only to the instance of the class, not the class itself.

所以,这样的事情应该工作:

So something like this should work:

Scene = gideros.class(Sprite)
local scene = Scene.new()
stage:addChild(scene)
 
精彩推荐
图片推荐