Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Animation 在corona中,在允许再次播放之前,如何使精灵表动画播放到最后?_Animation_Button_Lua_Coronasdk_Sprite Sheet - Fatal编程技术网

Animation 在corona中,在允许再次播放之前,如何使精灵表动画播放到最后?

Animation 在corona中,在允许再次播放之前,如何使精灵表动画播放到最后?,animation,button,lua,coronasdk,sprite-sheet,Animation,Button,Lua,Coronasdk,Sprite Sheet,我有一个点击按钮,使我的角色打孔,但如果在快速连续点击我的角色只是继续执行打孔动画之前,他完成了它,所以他只是猛拉周围奇怪。。。我已经摆弄它好几个小时了,但似乎还没弄明白 我试着在点击后移除按钮事件监听器,但没有足够快(在它启动之前,我还是设法点击了两三下) 在播放动画时,我尝试将顶部的“ispunching”变量切换为true,但在这两个变量开始之前,我仍然可以点击几下 我知道可能有一个简单的方法,我很傻!感谢您的帮助 谢谢 精灵数据和序列: local sheetData1 = { widt

我有一个点击按钮,使我的角色打孔,但如果在快速连续点击我的角色只是继续执行打孔动画之前,他完成了它,所以他只是猛拉周围奇怪。。。我已经摆弄它好几个小时了,但似乎还没弄明白

我试着在点击后移除按钮事件监听器,但没有足够快(在它启动之前,我还是设法点击了两三下)

在播放动画时,我尝试将顶部的“ispunching”变量切换为true,但在这两个变量开始之前,我仍然可以点击几下

我知道可能有一个简单的方法,我很傻!感谢您的帮助

谢谢

精灵数据和序列:

local sheetData1 = { width=175, height=294, numFrames=11, sheetContentWidth=1925, sheetContentHeight=294}
local sheet1 = graphics.newImageSheet( "guy.png", sheetData1 )

local sheetData2 = { width=220, height=294, numFrames=4, sheetContentWidth=880, sheetContentHeight=294 }
local sheet2 = graphics.newImageSheet( "guy2.png", sheetData2 )

local sheetData3 = { width=261, height=300, numFrames=8, sheetContentWidth=2088, sheetContentHeight=300 }
local sheet3 = graphics.newImageSheet( "guy3.png", sheetData3 )

local sequenceData = {          
{ name="walk", sheet=sheet1, start=5, count=4, time=800, loopCount=0 },
{ name="idle", sheet=sheet1, frames={ 1,2,3,4 }, time=2000, loopCount=0 },
{ name="punch", sheet=sheet2, start=1, count=4, time=400, loopCount=1 },
{ name="kick", sheet=sheet3, start=1, count=4, time=400, loopCount=1 },
{ name="kick2", sheet=sheet3, start=5, count=4, time=400, loopCount=1 },
{ name="jump", sheet=sheet1, start=9, count=3, time=400, loopCount=1 }
}
人物:

guy = display.newSprite( group, sheet1, sequenceData )
physics.addBody( guy, "static", { friction=0.5, bounce=0 } )
guy.x = 600
guy.y = 600
空闲姿势:

local function idlePose()
guy:setSequence( "idle" )
guy:play()

end
显示按钮:

local btn1 = display.newImage ("button1.png")
btn1.x = 1100
btn1.y = 510
btn1:scale (1.5,1.5)
btn1.alpha=0.5
group:insert( btn1 )
按钮代码:

local function onTap( event )

if guy.sequence == "punch" and guy.isPlaying == true then
print("isplaying")
return
else
print("notplaying")
guy:setSequence( "punch" )
guy:play()
timer.performWithDelay(400, idlePose)
end
end
btn1:addEventListener("tap", onTap)

精灵对象上定义了一个
isPlaying
属性,点击时可以检查该属性:

local function onTap(event)
    if guy.isPlaying then
        return
    end

    guy:setSequence("punch")
    guy:play()

    timer.performWithDelay(400, idlePose)
end

btn1:addEventListener("tap", onTap)
如果您只想阻止他重复打拳(即,他仍然可以做其他事情),那么,您还可以检查一个
sequence
属性:


如果将if条件从
guy.isplay
更改为
guy.isplay和guy.sequence==“punch”
,则仅当他正在打孔时,才会停止事件再次触发,但会允许覆盖其他事件。例如,如果您的角色正在跑步,并且您希望他在按下“打孔”按钮后立即打孔,而不是等待跑步动画结束。

您能否提供您正在使用的示例代码…?刚刚为“我的按钮”添加了代码,我现在正在检查精灵是否在播放冲压动画之前显示,但如果我继续点击按钮,它仍会继续重新启动动画。这真让我难堪<代码>本地函数onTap(事件)
如果guy.isplay==true,则返回
在这种情况下,我需要看到更多的代码,而不仅仅是
onTap
功能,比如
guy
的定义位置和方式。对不起,我现在可以工作了,我的角色没有做空闲动画,但我需要他在没有按下按钮的情况下执行空闲动画。我已经完全更新了代码,我已经修复了它,我让一个enterframe侦听器监听按钮结束阶段,以将角色重置为空闲(因为我的移动按钮是触摸而不是轻触),因此我将结束阶段放在按钮功能中,并修复了它,为您的帮助松鼠欢呼