欢迎各位童鞋转载,转载请注明出处:http://blog.csdn.net/song_hui_xiang
作者新浪微博:http://weibo.com/u/3168848533
作者腾讯微博:http://t.qq.com/song_huixiang
--跟随动作 local function ActionFollow() centerSprite(1) man:setPosition(ccp(-200, size.height / 2)) local move = CCMoveBy:create(2, ccp(100, 0)) local moveBack = move:reverse() local scale = CCScaleBy:create(2,2) local seq = CCSequence:createWithTwoActions(move,scale) local rep = CCRepeatForever:create(seq) man:runAction(seq) --CCFollow动作,可以让一个节点跟随另一个节点做位移。CCFollow经常用来设置layer跟随sprite,可以实现类似摄像机跟拍的效果效果是精灵在地图上移动,地图也会跟着移动,但是精灵仍然是在整个界面的中心位置。 --参数1为跟随目标结点,参数2为边界矩形 layer:runAction(CCFollow:create(man,CCRectMake(0,0,size.width*2,30))) --下面写法代表无边界 layer:runAction(CCFollow:create(man)) --[[ local sp = CCSprite:create("Icon.png") sp:setPosition(ccp(100,200)) layer:addChild(sp) sp:runAction(CCFollow:create(man)) --sp:runAction(move:reverse()) ]]-- end --改变动作执行对象CCTargetedAction通常默认的动作执行对象是调用runAction的对象,而CCTargetedAction可以改变动作执行对象。CCTargetedAction* t = CCTargetedAction::create(sprite2, moveto);sprite->runAction(CCSequence::create(moveto, t, moveto, NULL));sprite先moveto,然后sprite2执行moveto,最后sprite执行moveto。 local function ActionsTargeted() centerSprite(2) local jump1 = CCJumpBy:create(2,ccp(0,0),300,3) local jump2 = CCJumpBy:create(2,ccp(0,0),300,3) local ro1 = CCRotateBy:create(2,360) local ro2 = CCRotateBy:create(2,360) local tar1 = CCTargetedAction:create(whitegirl,jump2) local tar2 = CCTargetedAction:create(whitegirl,ro2) local arr = CCArray:create() arr:addObject(jump1) arr:addObject(tar1) arr:addObject(tar2) arr:addObject(ro1) blackgirl:runAction(CCSequence:create(arr)) end