直接上代码
<pre name="code" class="html">--params msg 提示信息 img背景图片 time 显示时间 position 初始位置 function Toast:createToast(node,msg,img,time,position)
<span style="white-space:pre"> </span>--Toast 显示的文字msg local label = cc.ui.UILabel.new({UILabelType = 2,font="fonts/arial.ttf",text=msg,color=cc.c3b(255,255,255),size=32 }) :align(display.CENTER,position.x,position.y) :zorder(10) :addTo(node)
<span style="white-space:pre"> </span>--显示的背景图 local sprite = display.newSprite(img) :align(display.CENTER,position.y) :zorder(9) :scale(0.8) :opacity(10) :addTo(node) local seq1 = cc.Sequence:create(cc.FadeIn:create(time/5),cc.DelayTime:create(time/5*1.5),cc.FadeOut:create(time/5*2.5)); local seq2 = cc.Sequence:create(cc.EaseSineIn:create(cc.MoveBy:create(time/5,cc.p(0,100))),
<span style="white-space:pre"> </span> cc.DelayTime:create(time/5*2),
<span style="white-space:pre"> </span> cc.EaseSineOut:create(cc.MoveBy:create(time/3,-50)))); local spawn = cc.Spawn:create(seq1,seq2); local action = cc.Repeat:create(spawn,1); local action2 = action:clone()
--背景sprite,文字label运行action 先向上缓动移动100,在向下缓动移动50,并结合淡入淡出,最后消失 sprite:runAction(action2); label:runAction(action); end