![]() ![]() ![]() It’s simple stuff and I’m sure you’ll get the hang of it quickly. To follow along, please get the source code and project files for SpriteDraggerX. It's a minimal Cocos2d-X project showing how to drag a sprite around the screen. ![]() Make sure you have Node and Git, then: sudo npm install rapidgame -g SpriteDraggerX uses RapidGame's prebuilt Cocos2D-X libraries. This will symlink a lib folder to RapidGame's prebuilt headers and libraries. You'll then be able to compile and run SpriteDraggerX. Note that SpriteDraggerX is an iOS-only project. The point is to teach you the basics of Cocos2d-X without overwhelming you with the details of creating multiple projects for multiple platforms. The SpriteDraggerX project opened in Xcode A Basic Cocos2d-X Project Rest assured though, we will be covering multiple platforms in a later chapter. Open up the project's SpriteDragger.xcodeproj file. main.m: Launches the app and creates the application delegate.This project is intended to be the simplest possible Cocos2d-X code, so there are no extraneous files whatsoever. SpriteDragger.h/.cpp: A subclass of Cocos2d-X's Application object.Sets up Cocos2d-X and passes control to SpriteDragger. MyLayer.h/.cpp: A Layer subclass containing a sprite and a background layer object.Creates a blank Scene and a Layer object as its child. For click event of these three item, three function are added for handling the click event.The MyLayer object handles the touch input and drags the sprite around the screen, animating a little drop effect when the sprite is finished dragging. And added to the layer for displaying on the screen. Init() function will create a menu with 3 menu items( CCMenuItemFont). Scene() function will create a scene and return the pointer to the director.Īnd MainMenu::create() will create a MainMenu layer and you want to add it to the scene. Void MainMenu::onOptions(CCObject* pSender) Void MainMenu::onNewGame(CCObject* pSender) combine to form a menu and allign VerticallyĬCMenu* menu = CCMenu::create( item1, item2, item3, NULL ) on “init” you need to initialize your instanceĬCMenuItemFont* item1 = CCMenuItemFont::create( “New Game”, this, menu_selector(MainMenu::onNewGame) ) ĬCMenuItemFont* item2 = CCMenuItemFont::create( “Options”, this, menu_selector(MainMenu::onOptions) ) ĬCMenuItemFont* item3 = CCMenuItemFont::create( “Quit”, this, menu_selector(MainMenu::onQuit) ) If you remember this is exactly similar to the HelloWorldScene class which is created automatically by the cocos2dx template.įollowing is the contents of MainmenuScene.cpp And assigned three function for 3 buttons in the menu as designed by us in the beginning of this chapter. We had created MainMenu layer from CCLayer. ![]() implement the “static node()” method manually there’s no ‘id’ in cpp, so we recommand to return the exactly class pointer Method ‘init’ in cocos2d-x returns bool, instead of returning ‘id’ in cocos2d-iphone Create 2 files MainmenuScene.h and MainmenuScene.cpp.ĭownload the code here for this tutorial.įollowing is the contents of MainmenuScene.h For this we have to create a main menu layer and attach it to a main menu scene. We can set the window title by function setViewName. ![]()
0 Comments
Leave a Reply. |