【Cocos2D学习】Lua——动画动作、场景切换的基本应用

Cocox在动画这方面做的很好,果然很适合做游戏,我先研究了下以下几点的应用,

1、动作的平移旋转、缩放、串行和并行

    local people=display.newSprite("gamepic.png"):addTo(self):scale(0.5)
    people:setPosition(cc.p(0,100))
    people:setAnchorPoint(cc.p(0,0))
    -- people:runAction(cc.MoveTo:create(1,cc.p(display.width-250,100)))
    -- people:runAction(cc.MoveBy:create(1,cc.p(display.width-250,0)))

    local m1=cc.MoveBy:create(1,cc.p(display.width-450,0))
    --local m2=cc.MoveTo:create(1,cc.p(0,100))
    --local m2=m1:reverse()
    -- people:runAction(cc.Sequence:create(m1,m2))

    local m2=cc.ScaleTo:create(1,0.8)

    --people:runAction(cc.Spawn:create(m1,m2))

    people:runAction(cc.Sequence:create(cc.Spawn:create(m1,m2),cc.CallFunc:create(function()
    print("over")
    end)))

2、3D酷炫动作

    local role=cc.NodeGrid:create()
    role:addChild(display.newSprite("gamepic.png"))
    role:center():addTo(self)

    -- role:runAction(cc.Shaky3D:create(10,cc.size(50,50),5,false))
    -- role:runAction(cc.ShakyTiles3D:create(10,cc.size(50,50),5,false))
    -- role:runAction(cc.ShuffleTiles:create(5,cc.size(100,100),4))
    
    --local r1=cc.Shaky3D:create(1,cc.size(50,50),5,false)
    --local r2=cc.ShuffleTiles:create(1,cc.size(100,100),4)
    --role:runAction(cc.Sequence:create(r1,r2))
    
    --role:runAction(cc.Waves3D:create(2,cc.size(50,50),5,40))
    local r1=cc.Waves3D:create(2,cc.size(15,10),5,40)
    local r2=cc.Waves3D:create(2,cc.size(15,10),0,0)
    role:runAction(cc.Sequence:create(r1,r2))

3、场景过渡切换

    local b1=display.newSprite("r.jpg"):addTo(self)
    b1:setAnchorPoint(cc.p(0,0))
    local  scheduler=self:getScheduler()
    local s;
    s=scheduler:scheduleScriptFunc(function(f)
    scheduler:unscheduleScriptEntry(s)
            local ss=cc.Scene:create()
            local b2=display.newSprite("w.jpg"):addTo(ss):center()
            --   local transition=cc.TransitionCrossFade:create(1,ss);
            --        local transition=cc.TransitionZoomFlipAngular:create(1,ss);
            local transition=cc.TransitionPageTurn:create(1,ss,false);
            cc.Director:getInstance():replaceScene(transition);
    end ,2,false)


你可能感兴趣的:(Cocos)