现在的位置: 首页 > 综合 > 正文

cocos2d-x Lua 之 CCMoveTo 误区

2013年12月22日 ⁄ 综合 ⁄ 共 901字 ⁄ 字号 评论关闭

欢迎各位童鞋转载,转载请注明出处:http://blog.csdn.net/song_hui_xiang

作者新浪微博:http://weibo.com/u/3168848533

作者腾讯微博:http://t.qq.com/song_huixiang

local sprite = CCSprite:create("Icon.png")
sprite:setPosition(ccp(300,400))
menuLayer:addChild(sprite)

local function getNowXY(sender)
    print("sprite x , y ==",sender:getPositionX(),sender:getPositionY())
end
local moveto1 = CCMoveTo:create(1,ccp(sprite:getPositionX(),sprite:getPositionY()+200))  --sprite:getPositionY()+200已经等于600
local call1 = CCCallFuncN:create(getNowXY)
local moveto2 = CCMoveTo:create(1,ccp(sprite:getPositionX(),sprite:getPositionY()-200))  --sprite:getPositionY()-200已经等于200
local call2 = CCCallFuncN:create(getNowXY)

local array = CCArray:create()
array:addObject(moveto1)
array:addObject(call1)
array:addObject(moveto2)
array:addObject(call2)

sprite:runAction(CCSequence:create(array))
--打印结果如下,而不是所认为的300 400,在执行动画之前两个CCMoveTo的坐标就已经固定值
-- [LUA-print] sprite x , y ==	300	600
-- [LUA-print] sprite x , y ==	300	200

抱歉!评论已关闭.