bool CityScene::init() { Layer::init(); char szRound[260]; sprintf(szRound, "Round%d.tmx", mRound); TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile(szRound); TMXTiledMap* tmxTileMap = tileMapInfo->getTileMap(); this->addChild(tmxTileMap); mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo); mPlayerTank[0]->setObjType(PlayerTank); mPlayerTank[0]->getBullet(); Size tileSize = tmxTileMap->getTileSize(); Size mapSize = tmxTileMap->getContentSize(); mPlayerTank[0]->setPosition(Point(mapSize.width / 2 - tileSize.width * 3, tileSize.height)); // mLayerPanel = Panel::create(); addChild(mLayerPanel, 3); // mEnemyAI = EnemyAI::createEnemyAIWithTank(mPlayerTank[0]); return true; }
bool CityScene::init() { TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile("Round1.tmx"); CCTMXTiledMap* tmxTileMap = tileMapInfo->getTileMap(); this->addChild(tmxTileMap); mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo); //将地图放到屏幕中间 CCSize tileSize = tmxTileMap->getTileSize(); CCSize mapSize = tmxTileMap->getContentSize(); mPlayerTank[0]->setPosition(ccp(mapSize.width / 2 - tileSize.width * 3, tileSize.height)); //将坦克缩放到合适大小,然后放到地图中合适位置 /*CCSize tileSize = tmxFile->getTileSize(); Tank* tank = Tank::createTankWithTankType("player2U.png"); mPlayerTank[0] = tank; CCSize tankSize = tank->getContentSize(); tank->setScaleX(tileSize.width*2/tankSize.width); tank->setScaleY(tileSize.height*2/tankSize.height); tank->setPosition(ccp(winSize.width/2 - tileSize.width*2, tileSize.height)); this->addChild(tank);*/ //添加手柄 mLayerPanel = Panel::create(); addChild(mLayerPanel, 3); return true; }
bool CityScene::init() { CCLayer::init(); //初始化地图信息 char szRound[260]; sprintf(szRound, "Round%d.tmx", mRound); TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile(szRound); CCTMXTiledMap* tmxTileMap = tileMapInfo->getTileMap(); this->addChild(tmxTileMap); //在已有的地图上,创建玩家坦克 mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo); //设置坦克类型为玩家坦克 mPlayerTank[0]->setObjType(enumPlayerTank); mPlayerTank[0]->getBullet(); //放到地图中初始化位置 CCSize tileSize = tmxTileMap->getTileSize(); CCSize mapSize = tmxTileMap->getContentSize(); mPlayerTank[0]->setPosition(ccp(mapSize.width / 2 - tileSize.width * 3, tileSize.height)); //添加虚拟手柄的显示 mLayerPanel = Panel::create(); addChild(mLayerPanel, 3); //创建敌人坦克的AI mEnemyAI = EnemyAI::createEnemyAIWithTank(mPlayerTank[0]); return true; }
TileMapInfo* TileMapInfo::createMapInfoWithFile(const char *tmxFile) { TileMapInfo* tileMapInfo = new TileMapInfo(); tileMapInfo->initMapInfoWithFile(tmxFile); return tileMapInfo; }
bool CityScene::init() { if (!Layer::init()) { return false; } char szRound[260]; sprintf(szRound, "Round%d.tmx", mRound); TileMapInfo* tileMapInfo = TileMapInfo::createMapInfoWithFile(szRound); TMXTiledMap* tmxTileMap = tileMapInfo->getTileMap(); this->addChild(tmxTileMap); mPlayerTank[0] = Tank::createTankWithTankType("player2U.png", tileMapInfo); Size tileSize = tmxTileMap->getTileSize(); Size mapSize = tmxTileMap->getContentSize(); mPlayerTank[0]->setPosition(Vec2(mapSize.width / 2 - tileSize.width * 3, tileSize.height)); mLayerPanel = Panel::create(); addChild(mLayerPanel, 3); return true; }