[Cocos2dx 3.2] tile map creation, cocos2dx Tile
Use Tiled to edit a map
- Each layer can only contain one tile.
- The tile size should be a multiple of 32*32.
- Set path coordinates in the object Layer
- Obtain the coordinates in the object Layer in the main program and perform corresponding operations.
Set the pocket genie class:
Monster. h
# Include "cocos2d. h "USING_NS_CC; class Monster: public Sprite {public: virtual bool init (Vector <Node *> points); static Monster * create (Vector <Node *> points ); // obtain the coordinate Vector <Node *> p; Vector <Node *>: iterator start; // Sprite * s of the Object layer; // move void moveByPath () by path; // random int ranNum ;};
Monster. cpp
# Include "Monster. h "Monster * Monster: create (Vector <Node *> points) {auto monster = new Monster (); monster-> init (points); monster-> autorelease (); return monster;} bool Monster: init (Vector <Node *> points) {Sprite: init (); // you can specify a random number, control out-of-Game Genie types srand (time (NULL); ranNum = rand () % 5; p = points; start = p. begin (); switch (ranNum) {case 0: {s = Sprite: create ("1.png"); break;} case 1: {s = Sprite :: create ("2.png"); break;} case 2: {s = Sprite: create (" 3.png"); break;} case 3: {s = Sprite :: create ("4.png"); break;} case 4: {s = Sprite: create (" 5.png"); break;} s-> setPosition (* start) -> getPosition (); addChild (s); return true;} // move void Monster: moveByPath () {++ start; if (start = p. end () {s-> removeFromParent ();} else {Point a = Point (* start)-> getPosition (); s-> runAction (Sequence :: create (MoveTo: create (2, a), CallFuncN: create (CC_CALLBACK_0 (Monster: moveByPath, this), NULL ));}}
Main scenario
HelloWorldScene. h
# Ifndef _ HELLOWORLD_SCENE_H __# define _ HELLOWORLD_SCENE_H __# include "cocos2d. h "# include" Monster. h "USING_NS_CC; class HelloWorld: public cocos2d: LayerColor {public: static cocos2d: Scene * createScene (); virtual bool init (); CREATE_FUNC (HelloWorld ); void menuCloseCallback (cocos2d: Ref * pSender); // stores the coordinate Vector <Node *> points; Vector <Node *>: iterator startPoint In the Object layer; // Add the object void addMonster (); // used to control the time interval int oldTime; int curTime; void resetTime (); void update (float dt ); // Sprite * s;}; # endif // _ HELLOWORLD_SCENE_H __
HelloWorldScene. cpp
# Include "HelloWorldScene. h "USING_NS_CC; Scene * HelloWorld: createScene () {auto scene = Scene: createWithPhysics (); auto layer = HelloWorld: create (); scene-> getPhysicsWorld () -> setDebugDrawMask (PhysicsWorld: DEBUGDRAW_ALL); scene-> getPhysicsWorld ()-> setGravity (Point (0,-1000); scene-> addChild (layer ); return scene;} // on "init" you need to initialize your instancebool HelloWorld: init (){////////////// /// // 1. super init firstif (! LayerColor: initWithColor (Color4B (255,255,255,255) {return false;} Size visibleSize = Director: getInstance ()-> getVisibleSize (); Point origin = Director: getInstance () -> getVisibleOrigin (); // Add the physical boundary auto body = PhysicsBody: createEdgeBox (visibleSize, PHYSICSBODY_MATERIAL_DEFAULT, 3); auto node = Node: create (); node-> setPhysicsBody (body); node-> setPosition (visibleSize. width/2, visibleSize. height/2); ad DChild (node); // Add the map File auto map = TMXTiledMap: create ("pokamon. tmx "); map-> setPosition (, 0); addChild (map); // obtain the coordinates in the Object layer, exist in the vector TMXObjectGroup * objectGroup = map-> getObjectGroup ("monster"); ValueVector object = objectGroup-> getObjects (); for (ValueVector: iterator it = object. begin (); it! = Object. end (); it ++) {Value obj = * it; ValueMap m = obj. asValueMap (); auto node = Node: create (); node-> setPosition (m. at ("x "). asFloat () + 200, m. at ("y "). asFloat (); points. pushBack (node) ;}// reset time resetTime (); // enable the timer scheduleUpdate (); return true ;} void HelloWorld: update (float dt) {++ oldTime; if (oldTime = curTime) {resetTime (); addMonster () ;}} void HelloWorld: resetTime () {oldTime = 0; curTime = 40;} void HelloWorld :: addMonster () {auto hero = Monster: create (points); hero-> moveByPath (); addChild (hero);} void HelloWorld: menuCloseCallback (Ref * pSender) {# if (CC_TARGET_PLATFORM = CC_PLATFORM_WP8) | (CC_TARGET_PLATFORM = CC_PLATFORM_WINRT) MessageBox ("You pressed the close button. windows Store Apps do not implement a close button. "," Alert "); return; # endif Director: getInstance ()-> end (); # if (CC_TARGET_PLATFORM = CC_PLATFORM_IOS) exit (0); # endif}
Effect:
Problems encountered when porting cocos2d-x32 WIN32 to Android Compilation
My blog has questions about cocos2dx-3.2 about Android program porting. Column CSDN and windvix.
Reference: blog.csdn.net/windvix/article/details/38337003
What are the functions of the BIGEMAP Google satellite map download tool Free Edition? What can he do to express his specific merits?
1. Download global satellite images
1.1 supports download of HD video clips in the administrative area, rectangular box selection, and polygon area, and along the route. All download clips are 1.2 high-definition, accurate, and without watermarks.
2. Map superposition and seamless stitching
2.1 supports multi-mode switching and superposition of Google street maps, 3d cities, and 3d maps;
2.2 Efficient seamless stitching, lossless compression, and segmented stitching;
2.3 allows you to customize landmarks to build a spliced big image for you to map, edit, and apply.
3. Professional correction and Ultra-High Precision
3.1 supports data downloading at any scale and in any format, and the downloading data is perfectly corrected. The data after correction is intensive within 5 meters;
3.2 perfect correction and skewness for different projection maps, and Kml or Excel formats are provided to facilitate loading and editing of various tools.
Iv. Easy map coordinate System Conversion
4.1 Support for map coordinate System Conversion of WGS84;
4.2 support map coordinate System Conversion in beijing 54;
4.3 Map Coordinate System Conversion in Xi'an 80 is supported.
V. Map Data Analysis
5.1 provide distance measurement, area and perimeter calculation;
5.2 contour lines are automatically generated and can be exported to multiple formats, such as excel, txt, and kml;
5.3 terrain profile generation and analysis tools;
5.4 elevation can be extracted along the route and rectangle;
5.5 extract the generated elevation file and directly import the contour map;
5.6 multi-format data import and export, including kml, mysql, gpx, plt, and shp.
5.7 provide distance measurement, area and perimeter calculation;
5.8 contour lines are automatically generated and can be exported to multiple formats, such as excel, txt, and kml;
5.9 terrain profile generation and analysis tools;
5.10 elevation can be extracted along the route and rectangle;
5.11 extract the generated elevation file and directly import the contour map;
5.12 multi-format data import and export, including kml, mysql, gpx, plt, and shp.
5.13 3D terrain rendering and 3D terrain display;
5.14 export the 3D model from the 3D terrain model file in the rectangle area;
6. The Map Publishing Service supports real-time cache publishing and offline publishing.
6.1 create offline websites and export offline pyramid tiles.
6.2 3D terrain rendering and 3D terrain display;
6.3 export the 3D model from the 3D terrain model file in the rectangle area;
6.4 Map Publishing Service, supporting real-time cache publishing and offline publishing;
6.5 create offline websites and export offline pyramid tiles.
VII. Real-Time query of Geographic Names
7.1 support bus line query, station name query, line Overlay display, splicing and export, kml export;
7.2 border query: kml export is supported;
7.3 weather display;
7.4 real-time cloud map display, splicing and export.
8. multi-thread high-speed download and resumable Data Transfer
8.1 multi-thread tile download is supported. The number of download connections is intelligently allocated based on the network status and user PC configuration, ensuring the maximum download efficiency without affecting other operations;
8.2 resumable download: The current download task is interrupted due to human resources, power outages, or other factors. When you download the task again, it continues from the interrupted location, instead of starting from scratch.
IX. Online update and lifetime escort
9.1 automatic online upgrades ensure that users can obtain the latest map data and enjoy the latest features immediately;
9.2 large and professional after-sales service team to protect your career for life.