【Cocos2d-x Lua笔记七】Action动作

【Cocos2d-x Lua笔记七】Action动作,第1张

概述Action常会修改对象的一些属性,如位置,旋转,缩放等。 常用的动作 1.简单动作 MoveTo——移动动作 MoveBy   RotateTo——旋转动作 RotateBy   ScaleTo——缩放动作 Scaleby   FadeIn——淡入,修改透明度的值(0~255之间 FadeOut——淡出   TintTo——色调,使节点的NodeRGB从当前值改变到用户设置值 TintBy  

Action常会修改对象的一些属性,如位置,旋转,缩放等。

常用的动作

1.简单动作

Moveto——移动动作

MoveBy

Rotateto——旋转动作

RotateBy

Scaleto——缩放动作

Scaleby

FadeIn——淡入,修改透明度的值(0~255之间

FadeOut——淡出

TintTo——色调,使节点的NodeRGB从当前值改变到用户设置值

TintBy

简单的说to是绝对的,by是相对的。。By相当于这个节点是相对的。To是绝对的,意思是它并不考虑到这个节点的当前状态。

2.动作序列

Sequence可以使一系列的动作对象按顺序执行,可以将最后一个动作设置为回调动作,当动作完成时就能调用相关函数。cc.Sequence:create(action1action2,action3,callfunc)

Spawn使所有动作是同时执行的。

Reverse调用reserve()函数使动作逆序执行。Action:reverse()

3.动作回调

cc.CallFunc:create(hander,value) -- hander : 执行的回调函数 -- value : 传递给回调函数的可选参数,必须为一个table 4.缓动函数 使动作变化的幅度进行相应非线性变化

EaseIn/EaSEOut: 动作由慢变快/动作由快变慢

EaseInOut:动作由慢变快再由快变慢

EaseExponentialin:动作由慢变极快

EaseExponentialOut:动作由极快变慢

EaseExponentialinOut:动作由慢至极快再由极快边慢

EaseSineIn:动作由快变慢

EaseSineOut:动作由慢变快

EaseSineInOut:精灵由慢至快再由快至慢

EaseElasticIn:让目标动作赋予d性 ,且以目标动作起点位子赋予d性

EaseElasticOut:让目标动作赋予d性 ,且以目标动作终点位子赋予d性

EaseElasticInOut:让目标动作赋予d性 ,且以目标动作起点和终点位子赋予d性

EaseBounceIn:让目标动作缓慢开始

EaseBounceOut:让目标动作赋予反d力,且以目标动作结束位子开始反d

EaseBounceInOut:让目标动作赋予反d力,且以目标动作起始与结束位子开始反d

EaseBackIn:让目标动作赋予回力 , 且以目标动作起点位置作为回力点

EaseBackOut:让目标动作赋予回力 , 且以目标动作终点位置作为回力点

EaseBackInOut:让目标动作赋予回力 , 且以目标动作起点和终点位置作为回力点

JumpBy/JumpTo:跳的动作

RotateBy/Rotateto:旋转的动作

Spawn:让多个动作同时执行

Speed:让目标运行速度加倍

范例:

通过Action使开始按钮循环缩放,当按下按钮时停止缩放动作

local GameState=require(cc.PACKAGE_name .. ".cc.utils.GameState")require(cc.PACKAGE_name..".cc.ui.UIPushbutton")--创建游戏主页场景local HomeScene = class("HomeScene",function()    return display.newScene("HomeScene")end)GameData={}HomeScene.CHECKBox_button_IMAGES={    off="Images/menu_sound-sheet1.png",on="Images/menu_sound-sheet0.png",}HomeScene.PUSH_button_IMAGES={    normal="Images/day_start_btn.png",pressed="Images/day_start_btn_pressed.png",Disabled ="Images/day_start_btn_pressed.png",}function HomeScene:ctor()    self:addElement()    self:addMenuElement()endfunction HomeScene:addElement()    self.MainBg=display.newTilessprite("Background/day_buttom.png",cc.rect(display.left,display.bottom,display.wIDth,display.height)):addTo(self)    --align(target,anchorPoint,x,y)    self.MainBottomBg=display.newSprite("Background/day_tree_buttom.png"):align(display.BottOM_CENTER,display.cx,display.bottom):addTo(self)      self.MainTitleBg=display.newSprite("Background/day_Title_buttom.png"):align(display.top_CENTER,display.top-80):addTo(self)    self.MainRabbitBg=display.newSprite("Background/day_rabbit_buttom.png"):align(display.BottOM_CENTER,220,display.bottom+20):scale(0.8):addTo(self)endfunction HomeScene:addMenuElement()    self:initGameState()    --开始按钮    self.startBtn=cc.ui.UIPushbutton.new(HomeScene.PUSH_button_IMAGES,{scale9=true})        :setbuttonLabel("normal",cc.ui.UILabel.new({            UILabelType=1,text="开始",size=62,Font="Font/hero.fnt"        }))        :setbuttonLabel("pressed",Font="Font/hero.fnt",color=cc.c4b(255,64,100)           }))        :setbuttonLabel("Disabled",color=cc.c4b(0,100)           }))        :onbuttonClicked(function(event)            self:playSound(GAME_BGM.buttonClickSound)            event.target:stopAllActions()            end)        :align(display.CENTER,display.cy)        :addTo(self)    self:ActionScale()    --设置音乐开关    local function updateSoundCheckBox(checkBox)        local state= ""        if checkBox:isbuttonSelected() then            state="on"        else             state="off"            end        GameData.soundState=state        GameState.save(GameData)    end    --声音按钮    self.soundCheckBox=cc.ui.UICheckBoxbutton.new(HomeScene.CHECKBox_button_IMAGES)        :onbuttonStateChanged(function(event)            updateSoundCheckBox(event.target)        end)        :align(display.BottOM_RIGHT,display.wIDth-40,display.bottom+40)        :scale(0.9)        :addTo(self)    if  GameData.soundState =="on" then        self.soundCheckBox:setbuttonSelected(true)    else         self.soundCheckBox:setbuttonSelected(false)    endendfunction HomeScene:initGameState()    GameState.init(function(param)        local returnValue=nil        if param.errorCode then            printError("errorCode",param.errorCode)        else            if param.name==GAME_STATE_ENCRYPTION_OPERATION_SAVE then                local str=Json.encode(param.values)                str=crypto.encryptXXTEA(str,GAME_STATE_ENCRYPTION_XXTEA)                returnValue={data=str}            elseif param.name==GAME_STATE_ENCRYPTION_OPERATION_LOAD then                local str=crypto.decryptXXTEA(param.values.data,GAME_STATE_ENCRYPTION_XXTEA)                returnValue=Json.decode(str)            end          end        return returnValue    end,GAME_STATE_ENCRYPTION_filename,GAME_STATE_ENCRYPTION)    if io.exists(GameState.getGameStatePath()) then        GameData=GameState.load()        print("savePath:"..GameState.getGameStatePath())    end     local soundState=GameData.soundState    if soundState==nil then        GameData.soundState="on"        GameState.save(GameData)    end end--开始按钮缩放动画function HomeScene:ActionScale()    self.startBtn:runAction(cc.Sequence:create(         cc.EaseInOut:create(cc.Scaleto:create(1.2,1.2,1.2),cc.Scaleto:create(1.2,1,1),cc.CallFunc:create(function() self:ActionScale() end)))     end--播放音效function  HomeScene:playSound(sound)      if GameData.soundState=="on"  then         audio.playSound(sound)      else         print("sound","off")      endendfunction HomeScene:onEnter()endfunction HomeScene:onExit()endreturn HomeScene
总结

以上是内存溢出为你收集整理的【Cocos2d-x Lua笔记七】Action动作全部内容,希望文章能够帮你解决【Cocos2d-x Lua笔记七】Action动作所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1027486.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-23
下一篇 2022-05-23

发表评论

登录后才能评论

评论列表(0条)

保存