// // RPGMapSkillMenuLayer.cpp // OzgGameRPG // // Created by ozg on 14-4-10. // // #include "RPGMapSkillMenuLayer.h" #include "RPGMapMenuLayer.h" #include "RPGMapSceneLayer.h" RPGMapSkillMenuLayer::RPGMapSkillMenuLayer() { } RPGMapSkillMenuLayer::~RPGMapSkillMenuLayer() { this->m_stringList->release(); CCLog("RPGMapSkillMenuLayer 释放"); } bool RPGMapSkillMenuLayer::init(cocos2d::CCDictionary *stringList, CppSQLite3DB *db, float width, float height) { if(CCLayerColor::initWithColor(ccc4(0, 0, 0, 200), width, height)) { this->m_stringList = stringList; this->m_stringList->retain(); this->m_db = db; CCMenu *mainMenu = CCMenu::create(); mainMenu->setTag(kRPGMapSkillMenuLayerTagMainMenu); mainMenu->setAnchorPoint(CCPointZero); mainMenu->setPosition(CCPointZero); this->addChild(mainMenu); CCMenuItemSprite *menuBack = (CCMenuItemSprite*)mainMenu->getChildByTag(kRPGMapSkillMenuLayerTagMainMenuBack); if(!menuBack) { menuBack = CCMenuItemSprite::create(CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), CCSprite::createWithSpriteFrameName("commons_btn_back_04.png"), this, menu_selector(RPGMapSkillMenuLayer::onMenu)); menuBack->setPosition(ccp(40, 600)); menuBack->setTag(kRPGMapSkillMenuLayerTagMainMenuBack); menuBack->setScale(0.5); mainMenu->addChild(menuBack); } CCTMXTiledMap *mainBg = CCTMXTiledMap::create("map_menu5_style1.tmx"); mainBg->setPosition(CCPointZero); mainBg->setTag(kRPGMapSkillMenuLayerTagBg); this->addChild(mainBg); return true; } return false; } RPGMapSkillMenuLayer* RPGMapSkillMenuLayer::create(cocos2d::CCDictionary *stringList, CppSQLite3DB *db, float width, float height) { RPGMapSkillMenuLayer *obj = new RPGMapSkillMenuLayer(); if(obj && obj->init(stringList, db, width, height)) { obj->autorelease(); return obj; } CC_SAFE_DELETE(obj); return NULL; } //private void RPGMapSkillMenuLayer::onMenu(cocos2d::CCObject *pObject) { CCMenuItem *menuItem = (CCMenuItem*)pObject; SimpleAudioEngine::sharedEngine()->playEffect("audio_effect_btn.wav"); switch (menuItem->getTag()) { case kRPGMapSkillMenuLayerTagMainMenuBack: { // CCLog("后退"); //因为动态获取地图的大小会导致了菜单层显示错位,所以定死了 float width = 960; float height = 640; RPGMapMenuLayer *menuLayer = menuLayer = RPGMapMenuLayer::create(this->m_stringList, this->m_db, width, height); menuLayer->setPosition(ccp((CCDirector::sharedDirector()->getWinSize().width - width) / 2.0, (CCDirector::sharedDirector()->getWinSize().height - height) / 2.0)); menuLayer->setTag(kRPGMapSceneLayerTagMenuLayer); this->getParent()->addChild(menuLayer); this->removeFromParentAndCleanup(true); } break; default: break; } }