LUA Gideros:触摸Touble绘图线 [英] Lua Gideros: Touble drawing line with touch

查看:191
本文介绍了LUA Gideros:触摸Touble绘图线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用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)

这篇关于LUA Gideros:触摸Touble绘图线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆