HelloWorldScene.h文件:
#ifndef __HELLOWORLD_SCENE_H__#define __HELLOWORLD_SCENE_H__#include "cocos2d.h"class HelloWorld : public cocos2d::Layer{public: // there's no 'ID' in cpp,so we recommend returning the class instance pointer static cocos2d::Scene* createScene(); // Here's a difference. Method 'init' in cocos2d-x returns bool,instead of returning 'ID' in cocos2d-iphone virtual bool init(); // implement the "static create()" method manually CREATE_FUNC(HelloWorld);};#endif // __HELLOWORLD_SCENE_H__
HelloWorldScene.cpp文件:
#include "HelloWorldScene.h"#include "cocostudio/CocoStudio.h"#include "ui/CocosGUI.h"USING_NS_CC;using namespace cocostudio::timeline;Scene* HelloWorld::createScene(){ // 'scene' is an autorelease object auto scene = Scene::create(); // 'layer' is an autorelease object auto layer = HelloWorld::create(); // add layer as a child to scene scene->addChild(layer); // return the scene return scene;}// on "init" you need to initialize your instancebool HelloWorld::init(){ ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } auto rootNode = csloader::createNode("MainScene.csb");//瓦片地图编辑器生成瓦片地图map.tmx;把相关资源放到工程文件夹下 auto map1 = TMXTiledMap::create("map.tmx"); addChild(map1); Vector<Node*> maps = map1->getChildren(); SpriteBatchNode* child = NulL; Ref* pObject = NulL; for (Vector<Node*>::iterator item = maps.begin(); item != maps.end();item++) { pObject = *item; child = (SpriteBatchNode*)pObject; //cclOG("%d",child->get)); } TMXLayer* layer = map1->getLayer("scene"); addChild(rootNode); return true;}总结
以上是内存溢出为你收集整理的24.Cocos2d-x瓦片地图TMXTiledMap全部内容,希望文章能够帮你解决24.Cocos2d-x瓦片地图TMXTiledMap所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)