Lua Gideros:触摸线2 [英] Lua Gideros: Line with touch 2
本文介绍了Lua Gideros:触摸线2的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
$ p $
本地函数onMouseDown(事件)
startx = event.x
starty = event.y
event:stopPropagation()
结束
本地函数onMouseUp(event)
endx = event.x
endy = event.y
local line = Shape.new()
line:setLineStyle(5,0x0000ff,1)
line:beginPath()
line:moveTo (startx,starty)
行:lineTo(endx,endy)
行:endPath()
事件:stopPropagation()
结束
地方: addEventListener(Event.MOUSE_DOWN,onMouseDown)
place:addEventListener(Event.MOUSE_UP,onMouseUp)
有人知道为什么这不起作用?感谢!
这是我另一个问题的第二部分。 解决方案
如果你不工作,你的意思是没有任何事情发生,没有任何东西在屏幕上绘制,那是因为你没有将你的形状添加到舞台结构中
它应该是这样的:
local line = Shape.new()
line:setLineStyle(5,0x0000ff, 1)
- 可以添加到舞台或者地点,
- 如果您使用的是场景
stage:addChild(line)
本地函数onMouseDown(event)
startx = event.x
starty = event.y
event:stopPropagation()
结束
本地函数onMouseUp(event)
line:beginPath()
line:moveTo(startx,starty)
line:lineTo(event.x,event.y)
line:endPath()
event:stopPropagation()
end
place:addEventListener(Event.MOUSE_DOWN,onMouseDown)
place:addEventListener(Event.MOUSE_UP,onMouseUp)
In my game using Lua and Gideros studio, I want someone to draw a straight line from mouse down to mouse up. Here is my code that doesn't work:
local function onMouseDown(event)
startx = event.x
starty = event.y
event:stopPropagation()
end
local function onMouseUp(event)
endx = event.x
endy = event.y
local line = Shape.new()
line:setLineStyle(5, 0x0000ff, 1)
line:beginPath()
line:moveTo(startx,starty)
line:lineTo(endx,endy)
line:endPath()
event:stopPropagation()
end
place:addEventListener(Event.MOUSE_DOWN, onMouseDown)
place:addEventListener(Event.MOUSE_UP, onMouseUp)
Anybody know why this isn't working? Thanks!
This is part 2 of my other question.
解决方案
If you by not working, you mean that nothing is happening and nothing is drawn on the screen, then it is because you did not add your shape to the stage hiearchy
It should be like this:
local line = Shape.new()
line:setLineStyle(5, 0x0000ff, 1)
--can add to stage or maybe place,
--if that's what you are using for scene
stage:addChild(line)
local function onMouseDown(event)
startx = event.x
starty = event.y
event:stopPropagation()
end
local function onMouseUp(event)
line:beginPath()
line:moveTo(startx,starty)
line:lineTo(event.x,event.y)
line:endPath()
event:stopPropagation()
end
place:addEventListener(Event.MOUSE_DOWN, onMouseDown)
place:addEventListener(Event.MOUSE_UP, onMouseUp)
这篇关于Lua Gideros:触摸线2的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文