读一读

function MainScene:OnClick(sender)
    local mov1 = cc.MoveBy:create(2,cc.p(300,0))
    local rotate2 = cc.RotateBy:create(2,180)
    local mov3 = cc.MoveBy:create(2,cc.p(-300,0))

    local callback = cc.CallFunc:create(self.callBack)
    local seq = cc.Sequence:create(mov1,rotate2,callback,mov3)

    self.myImage:runAction(seq)
end

function MainScene:callBack()
    print(123)
end

local mov1 = cc.MoveBy:create(2,cc.p(300,0))

self.myImage:runAction(cc.EaseIn:create(mov1,3)) --以3倍速度由慢到快
self.myImage:runAction(cc.EaseOut:create(mov1,3)) --以3倍速度由快到慢
self.myImage:runAction(cc.EaseInOut:create(mov1,3)) --先慢到快再快到慢
self.myImage:runAction(cc.EaseSineOut:create(mov1)) 
self.myImage:runAction(cc.EaseExponentialOut:create(mov1))
self.myImage:runAction(cc.Speed:create(mov1,(math.random() * 5))) --随机速度运动

local mov1 = cc.MoveBy:create(2,cc.p(300,0))
local rotate2 = cc.RotateBy:create(2,180)
local mov3 = cc.MoveBy:create(2,cc.p(-300,0))

--顺序播放动作
self.myImage:runAction(cc.Sequence:create(mov1,rotate2,mov3))

--同步播放动作
self.myImage:runAction(cc.Spawn:create(mov1,rotate2))

local mov1 = mov1:reverse() --动作反转 xxxTo一般不支持
local seq = cc.Sequence:create(mov1,rotate2,mov3)

--重复播放动作 10 次
self.myImage:runAction(cc.Repeat:create(seq,10))

--无线重复播放动作
self.myImage:runAction( cc.RepeatForever:create(seq) )

--2秒钟移动到指定位置
local moveTo = cc.MoveTo:create(2,cc.p(display.cx * 2 ,display.cy * 2))
self.myImage:runAction(moveTo)

--2秒钟移动到相对自身的指定位置
local moveby = cc.MoveBy:create(2,cc.p(300,200))
self.myImage:runAction(moveby)

--上下串20px 10次后到指定位置
local jumpto = cc.JumpTo:create(2,cc.p(display.cx*2,display.cy),20,10)
self.myImage:runAction(jumpto)

--上下串20px 10次后到达相对自身的指定位置
local jumpby = cc.JumpBy:create(2,cc.p(-300,0),20,10)
self.myImage:runAction(jumpby)

--沿着相对自身位置的贝塞尔曲线运动
local bezier = {
    cc.p(0,0),
    cc.p(300,500),
    cc.p(600,0)
}
local bezierby = cc.BezierBy:create(2,bezier)
self.myImage:runAction(bezierby)

--2秒后缩放到 2x,3y
local scaleto = cc.ScaleTo:create(2,2,3) --duration,x,y
self.myImage:runAction(scaleto)

--2秒后顺时针旋转到180
local rotateto = cc.RotateTo:create(2,180)
self.myImage:runAction(rotateto)

--2秒内闪烁10次
local blink = cc.Blink:create(2,10)
self.myImage:runAction(blink)

--2秒后渐变到指定颜色
local tintto = cc.TintTo:create(2,255,0,0)
self.myImage:runAction(tintto)

--2秒后从指定颜色渐变到原来的颜色
local tintby = cc.TintBy:create(2,0,255,255) --从这个颜色到原来
self.myImage:runAction(tintby)

--2秒内逐渐变到指定透明度
local fadeto = cc.FadeTo:create(2,60)
self.myImage:runAction(fadeto)

--2秒逐渐显现出来
self.myImage:setOpacity(0)
local fadein = cc.FadeIn:create(2)
self.myImage:runAction(fadein)

--2秒逐渐隐藏
local fadeout = cc.FadeOut:create(2)
self.myImage:runAction(fadeout)

--瞬间到某个位置
local place = cc.Place:create(cc.p(display.cx,display.cy))
self.myImage:runAction(place)

--X轴翻转 不对ImageView生效
local flipX = cc.FlipX:create(true)
self.myImage:runAction(flipX)

--Y轴翻转 不对ImageView生效
local flipy = cc.FlipY:create(true)
self.myImage:runAction(flipy)

--显示或隐藏
local toogle = cc.ToggleVisibility:create()
self.myImage:runAction(toogle)

--瞬间隐藏
local hide = cc.Hide:create()
self.myImage:runAction(hide)

--瞬间显示
local show = cc.show:create()
self.myImage:runAction(show)

function MainScene:onCreate()

    --这一句
    self.uiRoot = cc.CSLoader:createNode("MainScene.csb")
    self.uiRoot:addTo(self)

    self.myImage = self.uiRoot:getChildByName("HelloWorld_2")

    local imgae = self.uiRoot:getChildByName("Image_2")

    imgae:addClickEventListener(handler(self,self.OnClick))

end

local aScene = cc.Scene:create()
local img = cc.Sprite:create("111.png")
img:setPosition(cc.p(display.cx,display.cy))
aScene:addChild(img)

local ts = cc.TransitionTurnOffTiles:create(1,aScene) --场景转换动画
cc.Director:getInstance():replaceScene(ts)

如果是首次加载场景,调用runWithScene()方法,除了这两个方法,还有pushScene和popScene等


--直接使用图片
local spr1 = cc.Sprite:create("HelloWorld.png")
spr1:setPosition(cc.p(display.cx - 300,display.cy + 100))
spr1:setTexture("111.png") --更改图片
self:addChild(spr1)

--预先加载图集到缓存中
cc.SpriteFrameCache:getInstance():addSpriteFrames("plist/testPlist.plist")

--在缓存中获取一个精灵图片
local cash =  cc.SpriteFrameCache:getInstance():getSpriteFrame("logo/HelloWorld.png")
local spr2 = cc.Sprite:createWithSpriteFrame(cash) --通过精灵图片创建Sprite
spr2:setPosition(cc.p(display.cx - 100,display.cy))
self:addChild(spr2)

--通过图集的名字创建Sprite
local spr3 = cc.Sprite:createWithSpriteFrameName("logo/HelloWorld.png")
spr3:setPosition(cc.p(display.cx,display.cy-100))
spr3:setSpriteFrame(cash) --改变图片为图集中的图片
self:addChild(spr3)

--[[

Copyright (c) 2011-2014 chukong-inc.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

]]

--------------------------------
-- @module scheduler


--[[--

全局计时器、计划任务

«该模块在框架初始化时不会自动载入» 

加载方式: local scheduler = require(cc.PACKAGE_NAME .. ".scheduler")

]]
local scheduler = {}
local sharedScheduler = cc.Director:getInstance():getScheduler()

scheduler.m_schedulerHandlers = {}--所有调度的 
-- start --

--------------------------------
-- 计划一个全局帧事件回调,并返回该计划的句柄。
-- @function [parent=#scheduler] scheduleUpdateGlobal
-- @param function 回调函数
-- @return mixed#mixed ret (return value: mixed)  schedule句柄

--[[--

计划一个全局帧事件回调,并返回该计划的句柄。

全局帧事件在任何场景中都会执行,因此可以在整个应用程序范围内实现较为精确的全局计时器。

该函数返回的句柄用作 scheduler.unscheduleGlobal() 的参数,可以取消指定的计划。 

]]

-- end --

function scheduler.scheduleUpdateGlobal(listener)
    local handle = sharedScheduler:scheduleScriptFunc(listener, 0, false)
    table.insert(scheduler.m_schedulerHandlers, handle)
    return handle
end

-- start --

--------------------------------
-- 计划一个以指定时间间隔执行的全局事件回调,并返回该计划的句柄。
-- @function [parent=#scheduler] scheduleGlobal
-- @param function listener 回调函数
-- @param number interval 间隔时间
-- @return mixed#mixed ret (return value: mixed)  schedule句柄

--[[--

计划一个以指定时间间隔执行的全局事件回调,并返回该计划的句柄。 

~~~ lua

local function onInterval(dt)
end
 
-- 每 0.5 秒执行一次 onInterval()
local handle = scheduler.scheduleGlobal(onInterval, 0.5) 

~~~

]]

-- end --

function scheduler.scheduleGlobal(listener, interval)
    local handle = sharedScheduler:scheduleScriptFunc(listener, interval, false)
    table.insert(scheduler.m_schedulerHandlers, handle)
    return handle
end

-- start --

--------------------------------
-- 取消一个全局计划
-- @function [parent=#scheduler] unscheduleGlobal
-- @param mixed schedule句柄

--[[--

取消一个全局计划 

scheduler.unscheduleGlobal() 的参数就是 scheduler.scheduleUpdateGlobal() 和 scheduler.scheduleGlobal() 的返回值。

]]

-- end --

function scheduler.unscheduleGlobal(handle)
    sharedScheduler:unscheduleScriptEntry(handle)
    for i,v in ipairs(scheduler.m_schedulerHandlers) do
        if v == handle then
            table.remove(scheduler.m_schedulerHandlers, i)
            break
        end
    end
end

-- start --

--------------------------------
-- 计划一个全局延时回调,并返回该计划的句柄。
-- @function [parent=#scheduler] performWithDelayGlobal
-- @param function listener 回调函数
-- @param number time 延迟时间
-- @return mixed#mixed ret (return value: mixed)  schedule句柄

--[[--

计划一个全局延时回调,并返回该计划的句柄。

scheduler.performWithDelayGlobal() 会在等待指定时间后执行一次回调函数,然后自动取消该计划。

]]

-- end --

function scheduler.performWithDelayGlobal(listener, time)
    local handle
    handle = sharedScheduler:scheduleScriptFunc(function()
        scheduler.unscheduleGlobal(handle)
        listener()
    end, time, false)
    return handle
end

function scheduler.unscheduleAll()
    for i=#scheduler.m_schedulerHandlers,1,-1 do
        scheduler.unscheduleGlobal(scheduler.m_schedulerHandlers[i])
    end
end

return scheduler

local ske = sp.SkeletonAnimation:create("ske/blink.json", "ske/blink.atlas", 1.0)
ske:setAnimation(0, "blink", true)
self:addChild(ske)
ske:setPosition(cc.p(display.cx,display.cy + 200))