Cocos2d-android (05) 渐变动画(颜色,淡入淡出。。。)
淡入淡出、颜色渐变及动作重复执行
import org.cocos2d.actions.base.CCRepeatForever; import org.cocos2d.actions.interval.CCFadeIn; import org.cocos2d.actions.interval.CCFadeOut; import org.cocos2d.actions.interval.CCMoveTo; import org.cocos2d.actions.interval.CCRepeat; import org.cocos2d.actions.interval.CCSequence; import org.cocos2d.actions.interval.CCTintBy; import org.cocos2d.actions.interval.CCTintTo; import org.cocos2d.layers.CCLayer; import org.cocos2d.nodes.CCSprite; import org.cocos2d.types.CGPoint; import org.cocos2d.types.ccColor3B; public class GameLayer extends CCLayer { private CCSprite sprite; public GameLayer() { sprite = CCSprite.sprite("player.png"); CGPoint startPoint = CGPoint.ccp(300, 300); sprite.setPosition(startPoint); this.addChild(sprite); // 三秒钟内逐渐淡出 CCFadeOut fadeOut = CCFadeOut.action(3); // 三秒钟内逐渐淡入 CCFadeIn fadeIn = CCFadeIn.action(3); // 三秒钟内颜色逐渐变为红色 ccColor3B color3b1 = ccColor3B.ccc3(255, 0, 0); CCTintTo tintTo = CCTintTo.action(3, color3b1); // 三秒钟内颜色逐渐变化(0, -255, -255) ccColor3B color3b2 = ccColor3B.ccc3(0, -255, -255); CCTintBy tintBy = CCTintBy.action(3, color3b2); //动作执行次数 CGPoint targetPoint = CGPoint.ccp(600, 800); CCMoveTo moveTo1 = CCMoveTo.action(3, targetPoint); CCMoveTo moveTo2 = CCMoveTo.action(3, startPoint); CCSequence sequence = CCSequence.actions(moveTo1, moveTo2); CCRepeat repeat = CCRepeat.action(sequence, 3); //动作一直执行 CCRepeatForever repeatForever = CCRepeatForever.action(sequence); sprite.runAction(repeatForever); } }
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。