Cocos2d-android -- Action (4)

Source: Internet
Author: User

1. MainActivity

Package com. njupt. ccaction04; import org. cocos2d. layers. CCScene; import org. cocos2d. nodes. CCDirector; import org. cocos2d. opengl. CCGLSurfaceView; import android. OS. bundle; import android. app. activity; import android. view. menu; public class MainActivity extends Activity {// The cocos2d engine knows that the image is private CCGLSurfaceView view = null on the view object; @ Overrideprotected void onCreate (Bundle savedInstanceState) {super. onCreate (savedInstanceState); view = new CCGLSurfaceView (this); setContentView (view); CCDirector dire= CCDirector. sharedDirector (); // get the CCDirector object/*** set the properties of the game program */director. attachInView (view); // sets the view object director used in the current game program. setDisplayFPS (true); // sets whether the game program displays the FPS value director. setAnimationInterval (1.0f/60); // set the time required for rendering a frame in the game. // generate a game scenario object CCScene scene = CCScene. node (); // generate the set layer object GameLayer gameLayer = new GameLayer (); // Add the set layer object to scene in the game scene. addChild (gameLayer); // run game scenario ctor. runWithScene (scene) ;}@ Overridepublic boolean onCreateOptionsMenu (Menu menu) {// Inflate the menu; this adds items to the action bar if it is present. getMenuInflater (). inflate (R. menu. main, menu); return true ;}}



2. GameLayer

Package com. njupt. ccaction04; import org. cocos2d. actions. base. CCRepeatForever; import org. cocos2d. actions. interval. CCFadeIn; import org. cocos2d. actions. interval. CCFadeOut; import org. cocos2d. actions. interval. CCJumpBy; import org. cocos2d. actions. interval. CCJumpTo; import org. cocos2d. actions. interval. CCMoveBy; import org. cocos2d. actions. interval. CCMoveTo; import org. cocos2d. actions. interval. CCRepeat; import o Rg. 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"); sprite. setPos Ition (300,300); this. addChild (sprite); // CCFadeIn: fade in effect // CCFadeIn fadeIn = CCFadeIn. action (3); // sprite. runAction (fadeIn); // CCFadeOut: fade out effect // CCFadeOut fadeOut = CCFadeOut. action (3); // sprite. runAction (fadeOut);/*** CCTintTo and CCTintBy change the color. The former performs the = operation, and the latter performs the delta operation * // ccColor3B color3b = ccColor3B. ccc3( 255, 0, 0); // CCTintTo tintTo = CCTintTo. action (3, color3b); // sprite. runAction (tintTo); // ccColor3B color3b = ccColor3B. ccc3 (-255,120,120); // CCTintBy tintBy = CCTintBy. action (3, color3b); // sprite. runAction (tintBy);/*** CCRepeat repeat = CCRepeat. action (seq, 3) * The first parameter is the action to be cyclic * The second parameter is the number of times the loop is required ** CCRepeatForever. action (seq); * specify the action in a loop */CGPoint initPoint = CGPoint. ccp (300,300); CGPoint targetPoint = CGPoint. ccp (100,100); CCMoveTo moveTo1 = CCMoveTo. action (3, targetPoint); CCMoveTo moveTo2 = CCMoveTo. action (3, initPoint); CCSequence seq = CCSequence. actions (moveTo1, moveTo2); // CCRepeat repeat = CCRepeat. action (seq, 3); CCRepeatForever forever = CCRepeatForever. action (seq); sprite. runAction (forever );}}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.