Lua Gideros:麻烦画线 [英] Lua Gideros: Trouble drawing line with touch

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

问题描述

在使用Gideros和Lua的游戏中,我希望玩家能够从他们触摸屏幕的点开始画出直线,直到他们释放为止。但是,当我尝试运行此代码时,我总是收到一条错误消息。代码如下:

pre $ 本地函数onMouseDown(event)
event.x = startx
事件。 y = starty

event:stopPropagation()
结束

本地函数onMouseUp(event)
event.x = endx
事件。 y = endy
event:stopPropagation()
local line = Shape.new()
line:setLineStyle(5,0x0000ff,1)
line:beginPath()
行:moveTo(startx,starty)
行:lineTo(endx,endy)
行:endPath()

结束



下一行是我的代码中的第66行:

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

下面是我设置scene的那一行:

$ $ $ $ $ $ $ $ c $ scene $ gideros.class(Sprite)

这是我的错误信息:

main .lua:66:index'__userdata'找不到
stack traceb ack:
main.lua:66:in main chunk



有人知道我为什么收到这条消息吗?

  scene = gideros.class(Sprite) 

它意味着场景是一个类,但是您只能将事件侦听器添加到类的实例中,而不是类本身。



所以像这样的东西应该工作:

  Scene = gideros.class(Sprite)
local scene = Scene.new()
stage:addChild(scene)


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

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: index '__userdata' cannot be found stack traceback: main.lua:66: in main chunk

Does anyone know why I am getting this message?

解决方案

If you do

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:麻烦画线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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