cocos2d-x lua中2种动画:骨骼动画 和 帧动画

帧动画(下面只是帧动画的一种播放模式,还有其他的模式可使用,参照:http://blog.csdn.net/slow_liao/article/details/45317349)

    self.activityLayer = cc.CSLoader:createNode(G_GetPlazaRes("layout/activity/activity_main_bg.csb"))
    self.activityLayer:addTo(self.layerColor)
    local activeAnimation = cc.CSLoader:createTimeline(G_GetPlazaRes("layout/activity/activity_main_bg.csb"))
    self.activityLayer:runAction(activeAnimation)
    
  --动画一(没有帧动画事件的动画)
   --activeAnimation:gotoFrameAndPlay(0, 30, false)--false一次
    activeAnimation:play("animation_name",false)--false一次

  --动画二(有帧动画事件的动画)
  local function doOutAnimation( _callbackfunc )
        --动画二(有帧动画事件的动画)
        --activeAnimation:gotoFrameAndPlay(40, 60, false)--false一次
        activeAnimation:play("form_close", false)--false一次
        activeAnimation:setFrameEventCallFunc(
            function(sender)
                local aniName = sender:getEvent()
                print("aniName = ",aniName)
                if aniName == "form_close" then
                    print("执行了离开动画+++++++++++++++")
                    if _callbackfunc then
                        _callbackfunc()
                    end
                end
            end
        )
    end

    -- 找到“X”按钮
    local backBtn = self.detailBackNode:getChildByName("Panel_Top"):getChildByName("Button_Close")
    backBtn:addTouchEventListener(function ( sender,eventType )
        print("点击了返回到大厅按钮")
        if eventType == ccui.TouchEventType.ended then
            self:playEffectWhenBtnClick()
            --删除弹出的任务layer
            doOutAnimation(function (  )
                --其他代码
                --eg:删除弹出的layer
                --将layer删除后,layer上绑定的子节点、动画等都会删除(此处针对自己公司设置的)
                self.layer:removeFromParent()
                self.layer = nil
            end)
        end
    end)

骨骼动画

--加载动画
                            local awdResultBackSp = Panel_onlineNode:getChildByName("img_effect")
                            self.awdResultAnimation = sp.SkeletonAnimation:create(
                                G_GetPlazaRes("SubHall_animationFiles/dating_lingqujiangli/dating_lingqujiangli.json"), 
                                G_GetPlazaRes("SubHall_animationFiles/dating_lingqujiangli/dating_lingqujiangli.atlas"), 
                                1)--必不可少
                            self.awdResultAnimation:addTo(awdResultBackSp)
                            self.awdResultAnimation:setContentSize(awdResultBackSp:getContentSize())

                            self.awdResultAnimation:setPosition(awdResultBackSp:getContentSize().width / 2, awdResultBackSp:getContentSize().height / 2)
                            ccui.Helper:doLayout(self.awdResultAnimation)--必不可少
                            self.awdResultAnimation:setAnimation(0, "dating_lingqujiangli", false)--必不可少

                            --拿到确定按钮
                            local sureBtn = Panel_onlineNode:getChildByName("Button_close")
                            sureBtn:addTouchEventListener(function ( sender,eventType )
                                if eventType == ccui.TouchEventType.ended then
                                    --删除骨骼动画
                                    local scheduler = cc.Director:getInstance():getScheduler()
                                    local callBackEntry = nil
                                    callBackEntry =
                                        scheduler:scheduleScriptFunc(
                                        function()
                                            scheduler:unscheduleScriptEntry(callBackEntry)
                                            self.awdResultAnimation:removeFromParent()
                                            self.awdResultAnimation = nil
                                            --删除弹框layer
                                            if layer then
                                                layer:removeAllChildren()
                                                layer:removeFromParent()
                                                layer = nil
                                            end
                                        end,
                                        0.01,
                                        false
                                    )
                                end
                            end)

你可能感兴趣的:(cocos2d-x lua中2种动画:骨骼动画 和 帧动画)