gpt4 book ai didi

events - Corona SDK event.target 触摸/点击

转载 作者:行者123 更新时间:2023-12-02 13:32:22 24 4
gpt4 key购买 nike

我正在尝试使用 event.target 来查看哪个对象被点击。我有一个由本地事件监听器调用的函数:

local param1 = 0

function changeParams(event)
if( event.target == "op1Up" ) then
param1 = param1 + 1
elseif( event.target == "op1Down" ) then
param1 = param1 - 1
end
dispMyParams1.text = ( "Param 1: "..param1 )
end

local op1Up = display.newRect( --[[rect parameters]]-- )
op1Up:addEventListener( "tap", changeParams )
local op1Down = display.newRect( --[[rect parameters]]-- )
op1Down:addEventListener( "tap", changeParams )

最佳答案

local param1 = 0

function changeParams(event)
if( event.target.name == "op1Up" ) then
param1 = param1 + 1
elseif( event.target.name == "op1Down" ) then
param1 = param1 - 1
end
dispMyParams1.text = ( "Param 1: "..param1 )
end

local op1Up = display.newRect( --[[rect parameters]]-- )
op1Up.name="op1Up"
op1Up:addEventListener( "tap", changeParams )
local op1Down = display.newRect( --[[rect parameters]]-- )
op1Up.name="op1Down"

event.target 返回对对象的引用,您首先需要向所有对象添加属性“name”,然后尝试识别那里的 .name,如我在代码中所示。

op1Down:addEventListener( "tap", changeParams )

关于events - Corona SDK event.target 触摸/点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20667618/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com