Cocos2d-android -- Vector

Source: Internet
Author: User

1. MainActivity

Package com. njupt. cocos2dvector; 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. cocos2dvector; import org. cocos2d. actions. interval. CCJumpBy; import org. cocos2d. actions. interval. CCJumpTo; import org. cocos2d. actions. interval. CCMoveBy; import org. cocos2d. layers. CCLayer; import org. cocos2d. nodes. CCSprite; import org. cocos2d. types. CGPoint; public class GameLayer extends CCLayer {// declare a Sprite object CCSprite aSprite; CCSprite bSprite; public GameLayer () {aSprite = CCSprite. sprite ("player.png"); bSprite = CCSprite. sprite ("player.png"); this. addChild (aSprite); this. addChild (bSprite); CGPoint initPoint = CGPoint. ccp (100,100); aSprite. setPosition (initPoint); bSprite. setPosition (initPoint); // CGPoint detaPoint = CGPoint. CPP (0,100); // CGPoint target = CGPoint. ccpAdd (initPoint, detaPoint); // addition of vectors /// bSprite. setPosition (target);/*** CCMoveBy. action (3, pos) * CCMoveBy adds the value of the current position of the genie to the value of pos * // CGPoint pos = CGPoint. ccp (100,100); // CCMoveBy MoveBy = CCMoveBy. action (3, pos); // aSprite. runAction (MoveBy);/*** CCJumpBy. action (3, pos, 200, 3); * four parameters are: action duration, increment, jump height, number of hops */CGPoint pos = CGPoint. CPP (300,400); CCJumpBy jumpBy = CCJumpBy. action (3, pos, 200, 3); aSprite. runAction (jumpBy );}}




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.