How to Implement the route control of the role in the map of different high and low steps of the cocos2d-x

Source: Internet
Author: User

What I want to say is that the role jumps from one step to another. The two steps are different. The result is that the role is parked on another step rather than falling down!

Void MapLayer: mapCreate () {this-> _ allMap = CCTMXTiledMap: create ("map/rosemap. tmx "); this-> _ allMap-> setScale (0.5); this-> addChild (this-> _ allMap ); this-> _ allMap-> layerNamed ("fangluoxia")-> setVisible (true ); // prevent falling invisible CCTMXObjectGroup * objGroup = this-> _ allMap-> objectGroupNamed ("pengzhuang"); 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 for obtaining the key value float x = playerPointDic-> valueForKey ("x ") -> floatValue (); this-> _ y = playerPointDic-> valueForKey ("y")-> floatValue () ;}} void MapLayer: jlmInRoad (float dt) {if (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ isJlmCreate) {CCSize mapTiledNum = this-> _ allMap-> getMapSize (); CCSize tiledSize = this-> _ allMap-> getTileSi Ze (); CCPoint point1 = (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> getPosition (); int x = point1.x * 2/tiledSize. width; int y = point1.y * 2/tiledSize. height;/* the default Y coordinate of the Cocos2d-x is from bottom to top, so do a subtraction operation */y = mapTiledNum. height-y; int tiledGid = _ allMap-> layerNamed ("fangluoxia")-> tileGIDAt (ccp (x, y); if (tiledGid! = 0) {CCDictionary * propertiesDict = _ allMap-> propertiesForGID (tiledGid ); /* obtain the zhezhao attribute value of the grid */const CCString * prop = propertiesDict-> valueForKey ("flx");/* determine whether the zhezhao attribute is true. If yes, do not move players */if (prop-> m_sString.compare ("true") = 0) {// (PmdInAllLayer *) this-> getParent ()) -> _ jlmLayer-> _ jlmSprite-> setPosition (ccp (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> getPosition (). x, 80); // (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> _ jumpdownhweigh = 90; // (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> setPosition (ccp (PmdInAllLayer *) this-> getParent ()) -> _ jlmLayer-> _ jlmSprite-> getPosition (). x + 0.1 * dt, 100); (PmdInAllLayer *) this-> getParent ()) -> _ jlmLayer-> _ jlmSprite-> setPosition (ccp (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> getPosition (). x + 0.1 * dt, 0.5 * this-> _ y) ;}} else {(PmdInAllLayer *) this-> getParent ()) -> _ jlmLayer-> _ jlmSprite-> setPosition (ccp (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> getPosition (). x, (PmdInAllLayer *) this-> getParent ()-> _ jlmLayer-> _ jlmSprite-> getPosition (). y-100.0 * dt ));}}}
This is basically the case!


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.