If you have time, write it. Then,
Create a new JlmLayer class and declare it in. h:
# Pragma once # include "e: \ cocos2d-x \ cocos2d-x-2.2 \ cocos2d-x-2.2 \ cocos2dx \ layers_scenes_transitions_nodes \ cclayer. h "# include" cocos2d. h "# include" JlmSprite. h "class JlmLayer: public cocos2d: CCLayer {public: JlmLayer (void );~ JlmLayer (void); virtual bool init (); CREATE_FUNC (JlmLayer); cocos2d: worker * _ jlmCache; // cocos2d: CCSpriteBatchNode * _ jlmBatchNode; // The batch processing node void jlmSpriteCreate (float dt); JlmSprite * _ jlmSprite; bool _ isJlmCreate; // determines whether the role has generated void setJlmInMap ();};
Define in its. cpp file:
# Include "JlmLayer. h "# include" PmdInAllLayer. h "USING_NS_CC; JlmLayer: JlmLayer (void) {this-> _ jlmCache = CCSpriteFrameCache: equals (); this-> _ jlmCache-> combine (" yuandi/yuandi. plist "); this-> _ jlmCache-> retain (); this-> _ jlmBatchNode = CCSpriteBatchNode: create (" yuandi/yuandi. pvr. ccz "); this-> addChild (this-> _ jlmBatchNode); this-> _ jlmBatchNode-> retain (); this-> _ jlmSprite = NULL; this-> _ IsJlmCreate = false;} JlmLayer ::~ JlmLayer (void) {this-> _ jlmBatchNode-> release (); this-> _ jlmCache-> release ();} bool JlmLayer: init () {if (! CCLayer: init () {return false;} schedule (schedule_selector (JlmLayer: jlmSpriteCreate), 0.1f); return true;} void JlmLayer: jlmSpriteCreate (float dt) {this-> _ jlmSprite = JlmSprite: create (); this-> _ jlmBatchNode-> addChild (this-> _ jlmSprite); this-> setJlmInMap (); this-> _ jlmSprite-> setScale (0.42); this-> _ isJlmCreate = true; if (this-> _ isJlmCreate) {unschedule (schedule_selector (JlmLayer :: jlmSpriteCreate);} void JlmLayer: setJlmInMap () {CCTMXObjectGroup * objGroup = (PmdInAllLayer *) this-> getParent ()) -> _ mapLayer-> _ allMap-> objectGroupNamed ("jlmPoint"); CCArray * objArray = objGroup-> getObjects (); if (objArray & objArray-> count ()> 0) {CCObject * pObj = NULL; CCARRAY_FOREACH (objArray, pObj) {CCDictionary * playerPointDic = (CCDictionary *) pObj; // converts an object to a dictionary, it is easy to obtain the key value float x = playerPointDic-> valueForKey ("x")-> floatValue (); float y = playerPointDic-> valueForKey ("y")-> floatValue (); this-> _ jlmSprite-> setPosition (ccp (0.5 * x, 0.5 * y ));}}}
Then we will create its subnode, The JlmSprite class: in the header file, make the following declaration:
#pragma once#include "e:\cocos2d-x\cocos2d-x-2.2\cocos2d-x-2.2\cocos2dx\sprite_nodes\ccsprite.h"#include "cocos2d.h"class JlmSprite :public cocos2d::CCSprite{public:JlmSprite(void);~JlmSprite(void);virtual bool init();CREATE_FUNC(JlmSprite);void yuanDiAnimation();};
In its. cpp, perform the following definition:
# Include "JlmSprite. h" USING_NS_CC; JlmSprite: JlmSprite (void) {} JlmSprite ::~ JlmSprite (void) {} bool JlmSprite: init () {if (! CCSprite: initWithSpriteFrameName ("zoulu2.png") {return false;} this-> yuanDiAnimation (); return true;} void JlmSprite: yuanDiAnimation () {// In-situ animation of the sprite cat; CCArray * jlmArray = CCArray: create (); jlmArray-> retain (); int I; for (I = 1; I <25; I ++) {CCSpriteFrame * jlmFrames = CCSpriteFrameCache: equals ()-> spriteFrameByName (CCString: createWithFormat ("zouluw.d.png", I)-> getCString ()); jlmArray-> addObject (jlmFrames);} CCAnimation * jlmAnination = CCAnimation: Unknown (jlmArray, 0.02); this-> runAction (CCRepeatForever: create (CCAnimate :: create (jlmAnination )));}
In this way, the ghost cat on the map will generate:
See the following results:
I will leave a QQ group here. You are welcome to join the discussion: 367086379