Foundation of cocos2d-android-instantaneous action and delayed action

Source: Internet
Author: User

1. MaInActivity

Package com. njupt. actioncc; 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. actioncc; import org. cocos2d. actions. instant. CCFlipX; import org. cocos2d. actions. instant. CCHide; import org. cocos2d. actions. interval. CCJumpTo; import org. cocos2d. actions. interval. CCMoveTo; import org. cocos2d. actions. interval. CCRotateTo; import org. cocos2d. layers. CCLayer; import org. cocos2d. nodes. CCSprite; import org. cocos2d. types. CGPoint; public class GameLayer extends CCLayer {// declare a genie object CCSprite player; public GameLayer () {// declare the file player = CCSprite. sprite ("player.png"); this. addChild (player); // sets the location of the genie object player. setPosition (100,100);/*** the following two sets of instantaneous actions: * CCFlipX * CCHide * // generate the action object // CCFlipX flipX = CCFlipX. action (true); // executes the action object // player. runAction (flipX); // CCHide hide = CCHide. action (); // player. runAction (hide);/*** the following two are delayed actions: * CCMoveTo * CCRotateTo * // *** CCMoveTo. action (3, pos): the first parameter indicates the duration of the action, and the second parameter indicates the end * // CGPoint pos = CGPoint. ccp (200,200); // CCMoveTo moveTo = CCMoveTo. action (3, pos); // player. runAction (moveTo);/*** CCRotateTo. action (3,-180): the first parameter indicates the duration of the action, and the second parameter indicates the rotation angle. * a negative number indicates clockwise rotation. A positive number indicates clockwise rotation... */CCRotateTo rotateTo = CCRotateTo. action (3,-180); player. runAction (rotateTo );}}





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.