void BattleFieldUI::touchButtonInit() {//init touch buttons auto _setBtn = Sprite::createWithSpriteFrameName("UI-1136-640_06.png"); _setBtn->setPosition3D(Vec3(VisibleSize.width - 50, VisibleSize.height - 50, 3)); _setBtn->setScale(0.8); _setBtn->setGlobalZOrder(10); addChild(_setBtn, 3); auto _chest = Sprite::createWithSpriteFrameName("chest.png"); _chest->setPosition3D(Vec3(VisibleSize.width - 100, VisibleSize.height - 50, 3)); _chest->setScale(0.8); _chest->setGlobalZOrder(10); addChild(_chest, 3); auto _coin = Sprite::createWithSpriteFrameName("coins.png"); _coin->setPosition3D(Vec3(VisibleSize.width - 300, VisibleSize.height - 50, 3)); _coin->setScaleX(0.8); _coin->setScaleY(0.8); _coin->setGlobalZOrder(10); addChild(_coin, 3); auto _chestAmount = Sprite::createWithSpriteFrameName("UI-1.png"); _chestAmount->setPosition3D(Vec3(VisibleSize.width - 170, VisibleSize.height - 50, 3)); _chestAmount->setScaleX(0.8); _chestAmount->setScaleY(0.7); _chestAmount->setGlobalZOrder(9); addChild(_chestAmount, 2); auto _coinAmount = Sprite::createWithSpriteFrameName("UI-1.png"); _coinAmount->setPosition3D(Vec3(VisibleSize.width - 370, VisibleSize.height - 50, 3)); _coinAmount->setScaleX(0.8); _coinAmount->setScaleY(0.7); _coinAmount->setGlobalZOrder(9); addChild(_coinAmount, 2); }
GameMenuUI::GameMenuUI(Layer* _layer) :m_hp(100), m_coin(0) { Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto upbar = Sprite::create("upbar.png"); upbar->retain(); upbar->setScale(4.0f); upbar->setPosition(Point(320.0f, 22.0f)); _layer->addChild(upbar); progresshpbar = ProgressTimer::create(Sprite::create("hpbar_.png")); progresshpbar->retain(); progresshpbar->setType(ProgressTimerType::BAR); progresshpbar->setScale(2.8f); progresshpbar->setBarChangeRate(Point(1, 0)); progresshpbar->setMidpoint(Point(0.0f, 20.0f)); progresshpbar->setPosition(Point(105.0f, 20.0f)); progresshpbar->setPercentage(m_hp); progresshpbar->setTag(TAG_HPBAR); _layer->addChild(progresshpbar); auto menuhpbar = Sprite::create("hpbar.png"); menuhpbar->retain(); menuhpbar->setScale(3.0f); menuhpbar->setPosition(Point(95.0f, 20.0f)); _layer->addChild(menuhpbar); auto border = Sprite::create("border.png"); border->retain(); border->setScale(2.0f); border->setPosition(Point(320.0f, 180.0f)); _layer->addChild(border); auto coin = Sprite::create("coin.png"); coin->retain(); coin->setScale(1.5f); coin->setPosition(Point(visibleSize.width * 3 / 4, visibleSize.height * 9 / 10)); _layer->addChild(coin); coinLabel = Label::createWithTTF(StringUtils::format("%d",m_coin),"fonts/arial.ttf",20); coinLabel->setPosition(Point(visibleSize.width * 5 / 6, visibleSize.height * 9 / 10)); coinLabel->setAlignment(TextHAlignment::LEFT); // coinLabel->setAlignment(TextHAlignment::RIGHT); coinLabel->setTag(TAG_COIN); _layer->addChild(coinLabel); coin->setGlobalZOrder(11); border->setGlobalZOrder(11); menuhpbar->setGlobalZOrder(11); progresshpbar->setGlobalZOrder(11); upbar->setGlobalZOrder(11); coinLabel->setGlobalZOrder(11); }
void BattleFieldUI::showVictoryUI() {//show the victory UI when win //diable AI //color layer auto layer = LayerColor::create(Color4B(10, 10, 10, 150)); layer->ignoreAnchorPointForPosition(false); layer->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 0)); //add victory auto victory = Sprite::createWithSpriteFrameName("victory.png"); victory->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 3)); victory->setScale(0.1); layer->addChild(victory, 1); layer->setGlobalZOrder(100); victory->setGlobalZOrder(100); //victory runaction auto action = EaseElasticOut::create(ScaleTo::create(1.5, 1)); victory->runAction(action); auto listener = EventListenerTouchOneByOne::create(); //touch event listener->onTouchBegan = [](Touch*, Event*) { return true; }; listener->onTouchEnded = [this](Touch*, Event*) { //clear GlobalVaribals HeroPool.clear(); DragonPool.clear(); SlimePool.clear(); RatPool.clear(); BossPool.clear(); PigletPool.clear(); HeroManager.clear(); MonsterManager.clear(); GameMaster::reset(); //stop schedule currentLayer->unscheduleUpdate(); Director::getInstance()->getScheduler()->unschedule("gameController", currentLayer); //stop sound experimental::AudioEngine::stop(AUDIO_ID.BATTLEFIELDBGM); //replace scene Director::getInstance()->replaceScene(ChooseRoleScene::createScene()); }; victory->setCameraMask(2); auto eventDispatcher = layer->getEventDispatcher(); eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layer); addChild(layer); }
bool GameScene::init(){ if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); auto background = Sprite::create("bg_cell.png", Rect(0, 0, visibleSize.width, visibleSize.height)); background->getTexture()->setTexParameters({GL_LINEAR, GL_LINEAR, GL_REPEAT,GL_REPEAT}); background->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2)); this->addChild(background,-1); background->setGlobalZOrder(-1); waveCount = 1; lvl = 1; GameScene::addNewEnemyByLevel(1); g_rGemertricRecognizer=new GeometricRecognizer; g_rGemertricRecognizer->loadTemplates(); auto listener1 = EventListenerTouchOneByOne::create();//创建一个触摸监听 listener1->setSwallowTouches(true); //设置是否想下传递触摸 // listener1->onTouchBegan = [](Touch* touch, Event* event){ // Point location = touch->getLocation(); // pre_point = cur_point = location; // return true; // }; listener1->onTouchBegan = CC_CALLBACK_2(GameScene::onTouchBegan, this); listener1->onTouchMoved = CC_CALLBACK_2(GameScene::onTouchMoved, this); listener1->onTouchEnded = CC_CALLBACK_2(GameScene::onTouchEnded, this); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener1, this); return true; }
bool CCGSpell::initAdditional(void) { CCGSprite::initAdditional(); scheduleUpdate(); setGlobalZOrder(ZORDER_SPELL); CCString* shaderCode = CCString::createWithContentsOfFile(std::string("Shaders/tansparent.fsh")); // 加载顶点着色器和片元着色器 _pShaderProgram = new CCGLProgram(); _pShaderProgram->initWithVertexShaderByteArray(ccPositionTextureA8Color_vert, shaderCode->getCString()); // 启用顶点着色器的attribute变量,坐标、纹理坐标、颜色 _pShaderProgram->addAttribute(GLProgram::ATTRIBUTE_NAME_POSITION, GLProgram::VERTEX_ATTRIB_POSITION); _pShaderProgram->addAttribute(GLProgram::ATTRIBUTE_NAME_COLOR, GLProgram::VERTEX_ATTRIB_COLOR); _pShaderProgram->addAttribute(GLProgram::ATTRIBUTE_NAME_TEX_COORD, GLProgram::VERTEX_ATTRIB_TEX_COORD); // 自定义着色器链接 _pShaderProgram->link(); // 设置移动、缩放、旋转矩阵 _pShaderProgram->updateUniforms(); return true; }
void TopData::addStep(cocos2d::Node *node, int step, int time) { this->restStep += step; auto topNode = node->getChildByTag(MAIN_SCENE_TOP_NODE); auto textLimit = topNode->getChildByName<ui::Text *>("TextLimit"); textLimit->setString(Value(this->restStep).asString()); auto text = textLimit->clone(); text->setGlobalZOrder(100); text->setOpacity(200); topNode->addChild(text); auto scale = ScaleTo::create(0.5, 2.5); auto fade = FadeOut::create(0.5); auto callFunc = CallFunc::create([=]{ text->removeFromParent(); }); text->runAction(scale); text->runAction(Sequence::create(fade, callFunc, NULL)); if(UserData::getInstance()->challenges == 1) { this->restime += time; auto textTime = topNode->getChildByName<ui::Text *>("TextTime"); textTime->setString(Value(this->restime).asString()); auto text1 = textTime->clone(); text1->setGlobalZOrder(100); text1->setOpacity(200); topNode->addChild(text1); auto scale1 = ScaleTo::create(0.5, 2.5); auto fade1 = FadeOut::create(0.5); auto callFunc1 = CallFunc::create([=]{ text1->removeFromParent(); }); text1->runAction(scale1); text1->runAction(Sequence::create(fade1, callFunc1, NULL)); } }
void SelectScene::initBowLayer() { std::string nameList[11] = BOW_LIST; __Array *preSkill[11] = PRESKILLS_LIST; Vec2 v[11] = ICON_POSLIST; preSkill[10]->addObject(__String::create(MULTPLE_3_BOW)); preSkill[10]->addObject(__String::create(SPEED_3_BOW)); preSkill[10]->addObject(__String::create(POWER_3_BOW)); for (int i = 0; i < 11; i++) { auto button = BowButton::createButton(nameList[i], v[i], preSkill[i], this); button->setGlobalZOrder(10); _bowLayer->addChild(button, 0, nameList[i]); } }
void Node::setPositionZ(float positionZ) { if (_positionZ == positionZ) return; _transformUpdated = _transformDirty = _inverseDirty = true; _positionZ = positionZ; // XXX BUG // Global Z Order should based on the modelViewTransform setGlobalZOrder(positionZ); }
void LoadingScene::InitCoco() { Size visibleSize = Director::getInstance()->getVisibleSize(); auto coco = EffectSprite3D::createFromObjFileAndTexture("coconut.c3b", "coco.png"); if(coco) { coco->setRotation3D(Vec3(90,0,180)); coco->setPosition(Vec2(visibleSize.width/2, visibleSize.height/2-150)); GameEntity::UseOutlineEffect(static_cast<Sprite3D*>(coco), 0.03, Color3B(0,0,0)); addChild(coco,1); coco->runAction(RepeatForever::create(RotateBy::create(0.8f,Vec3(0,360,0)))); coco->setGlobalZOrder(1); } }
bool BattleFieldUI::init() { Layer::init(); avatarInit(); bloodbarInit(); angrybarInit(); touchButtonInit(); timeInit(); setGlobalZOrder(10); setCameraMask(2); experimental::AudioEngine::stopAll(); AUDIO_ID.BATTLEFIELDBGM = experimental::AudioEngine::play2d(BGM_RES.BATTLEFIELDBGM, true, 0.6); return true; }
void Camera3DTestDemo::addNewSpriteWithCoords(Vec3 p,std::string fileName,bool playAnimation,float scale,bool bindCamera) { auto sprite = Sprite3D::create(fileName); _layer3D->addChild(sprite); float globalZOrder=sprite->getGlobalZOrder(); sprite->setPosition3D( Vec3( p.x, p.y,p.z) ); sprite->setGlobalZOrder(globalZOrder); if(playAnimation) { auto animation = Animation3D::create(fileName,"Take 001"); if (animation) { auto animate = Animate3D::create(animation); sprite->runAction(RepeatForever::create(animate)); } } if(bindCamera) { _sprite3D=sprite; } sprite->setScale(scale); }
/** * 购买回调 * * @param idx 购买那个主题 */ void ZRBPageView::callBuy( LayerColor * layer , int idx ) { if ( ZRBUserDate::getInstance( )->getDateBool( KEY_CHECK_SOUND ) ) { CocosDenshion::SimpleAudioEngine::getInstance( )->playEffect( ZRBLanguage::getValue( "Music_Btclick" ) ); } // 购买 主题 auto gold = ZRBUserDate::getInstance( )->getDateInt( KEY_DATA_GOLDNUM ); if ( gold < PagePrice [ idx ] ) { auto mes = ZRBMessageLayer::create( ); mes->setMessageLabel( ZRBLanguage::getString( "Message_market_fail_1" ) + "\n" + ZRBLanguage::getString( "Message_market_fail_2" ) , ZRBLanguage::getValue( "BuyGold" ) , [ &] ( ) { auto market = ZRBMenuMarket::create( ); this->addChild( market , 10 ); market->call_buy( ); } ); mes->setGlobalZOrder( 200 ); mes->setName("page_message"); pageView->addChild( mes ); return; } gold -= PagePrice [ idx ]; ZRBUserDate::getInstance( )->saveData( KEY_DATA_GOLDNUM , &gold ); // 发送通知 NotificationCenter::getInstance( )->postNotification( "NOTIFICATION_Gold" , Integer::create( gold ) ); // 解锁购买的主题 switch ( idx ) { case 0: break; case 1: // 保存 page1 = true; ZRBUserDate::getInstance( )->saveData( KEY_MATERIAL_SWEET , &page1 ); break; case 2: page2 = true; ZRBUserDate::getInstance( )->saveData( KEY_MATERIAL_BLUESKY , &page2 ); break; case 3: page3 = true; break; default: break; } auto mes = ZRBMessageLayer::create( ); mes->setMessageLabel( ZRBLanguage::getValue( "Unlock_success" ) ); mes->setGlobalZOrder( 200 ); pageView->addChild( mes ); // 解锁后可以游戏 pMenu->pMenuDown->setEnabled( true ); pMenu->pMenuUp->setEnabled( true ); pMenu->pMenuDown->setOpacity( 255 ); pMenu->pMenuUp->setOpacity( 255 ); // 清理 layer->removeAllChildren( ); layer->setOpacity( 0 ); }
void Rolelayer::drawLeftlayer(){ float x_width= getDelwithint(200,0); layertag=Rolelayertag::left; if(this->getChildByTag(layer_left_tag)==nullptr){ left_layer=Layer::create(); left_layer->setContentSize(Size(Actual_x,Actual_y)); left_layer->setTag(layer_left_tag); left_layer->setPosition(Vec2(0,0)); addChild(left_layer); auto herobutton=MenuItemImage::create(hero_img,hero_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); herobutton->setPosition(Vec2(herobutton->getContentSize().width/2,getContentSize().height*0.8)); herobutton->setTag(Buton::hero_b); fillOuty(herobutton,hero_img); if(getUimove()==Isteachmove::teacher){ /* auto p_s=GuideLayer::createWithPrama(GuideLayer::MaskType::MaskType_Rectangle,herobutton->getPosition()); p_s->setSize(herobutton->getContentSize()); addChild(p_s); */ auto p=Sprite::create(teacher_shozhi); p->setAnchorPoint(Vec2(0.5,0.5)); p->setRotation(-90); p->setPosition(Vec2(herobutton->getContentSize().width,herobutton->getPositionY()+herobutton->getContentSize().height/2)); addChild(p); p->setGlobalZOrder(1000); p->runAction(RepeatForever::create(Sequence::create( FadeOut::create(0.5f),FadeIn::create(0.5f),nullptr))); } auto petbutton=MenuItemImage::create(pet_img,pet_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); petbutton->setPosition(Vec2(petbutton->getContentSize().width/2,getContentSize().height*0.60)); petbutton->setTag(Buton::pet_b); fillOuty(petbutton,pet_img); auto magicbutton=MenuItemImage::create(magic_img,magic_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); magicbutton->setPosition(Vec2(magicbutton->getContentSize().width/2,getContentSize().height*0.4)); magicbutton->setTag(Buton::magic_b); fillOuty(magicbutton,magic_img); auto menu=Menu::create( herobutton,petbutton,magicbutton, nullptr); menu->setPosition(Vec2::ZERO); menu->setTag(menu_zb1); left_layer->addChild(menu, 1000); tollgate_zb_menu=MenuItemImage::create(tollgatezbItem_img,tollgatezbItem_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); tollgate_zb_menu->setTag(Buton::tollgateItem_tag); tollgate_zb_menu->setPosition(Vec2(getContentSize().width*0.8,tollgate_zb_menu->getContentSize().height*0.5)); fillOuty(tollgate_zb_menu,tollgatezbItem_img); if(getUimove()!=Isteachmove::teacher) { auto armature =Armature::create("Run_UI_zhuye_anniu_xiaoguo"); armature->getAnimation()->play("chuxian",-1,1); armature->setPosition(Vec2(tollgate_zb_menu->getContentSize().width/2,tollgate_zb_menu->getContentSize().height/2)); tollgate_zb_menu->addChild(armature); } zb_menu=MenuItemImage::create(zb_img,zb_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); zb_menu->setTag(Buton::zb_b); zb_menu->setPosition(Vec2(tollgate_zb_menu->getPositionX(),tollgate_zb_menu->getPositionY()+zb_menu->getContentSize().height*1.2)); fillOuty(zb_menu,zb_img); auto menutag=Menu::create(tollgate_zb_menu,zb_menu,nullptr); menutag->setPosition(Vec2::ZERO); left_layer->addChild(menutag); auto back_img2=Sprite::create(tiao_img); back_img2->setTag(tiao_sp); back_img2->setAnchorPoint(Vec2(0,0)); back_img2->setPosition(Vec2(70,10));//zb_menu->getPositionY()-50)); left_layer->addChild(back_img2); auto hy_bt=MenuItemImage::create(hy_img,hy_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); hy_bt->setTag(hy_b); hy_bt->setPosition(Vec2(back_img2->getContentSize().width*0.23,back_img2->getContentSize().height*0.65)); fillOuty(hy_bt,hy_img); auto text_hy=Label::createWithSystemFont(FX::StringsMap::getValue("active"),"minijiankatong.ttf", 24); text_hy->setColor(yellow_c); text_hy->setPosition(Vec2(hy_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_hy); auto xiaoxi_bt=MenuItemImage::create(xiaoxi_img,xiaoxi_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); xiaoxi_bt->setTag(msg_b); xiaoxi_bt->setPosition(Vec2(back_img2->getContentSize().width*0.4,back_img2->getContentSize().height*0.65)); fillOuty(xiaoxi_bt,xiaoxi_img); auto text_xx=Label::createWithSystemFont(FX::StringsMap::getValue("msg"),"minijiankatong.ttf", 24); text_xx->setColor(yellow_c); text_xx->setPosition(Vec2(xiaoxi_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_xx); auto login_bt=MenuItemImage::create(denglu_img,denglu_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); login_bt->setTag(login_b); login_bt->setPosition(Vec2(back_img2->getContentSize().width*0.55,back_img2->getContentSize().height*0.65)); fillOuty(login_bt,denglu_img); auto text_lg=Label::createWithSystemFont(FX::StringsMap::getValue("logg"),"minijiankatong.ttf", 24); text_lg->setColor(yellow_c); text_lg->setPosition(Vec2(login_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_lg); auto activ_bt=MenuItemImage::create(huodon_img,huodon_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); activ_bt->setTag(huodong_b); activ_bt->setPosition(Vec2(back_img2->getContentSize().width*0.72,back_img2->getContentSize().height*0.65)); fillOuty(activ_bt,huodon_img); auto text_ac=Label::createWithSystemFont(FX::StringsMap::getValue("huodong"),"minijiankatong.ttf", 24); text_ac->setColor(yellow_c); text_ac->setPosition(Vec2(activ_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_ac); auto shezi_bt=MenuItemImage::create(shezi_img,shezi_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); shezi_bt->setTag(shezhi_b); shezi_bt->setPosition(Vec2(back_img2->getContentSize().width*0.88,back_img2->getContentSize().height*0.65)); fillOuty(shezi_bt,shezi_img); auto text_sz=Label::createWithSystemFont(FX::StringsMap::getValue("set"),"minijiankatong.ttf", 24); text_sz->setColor(yellow_c); text_sz->setPosition(Vec2(shezi_bt->getPositionX(),back_img2->getContentSize().height*0.25)); back_img2->addChild(text_sz); auto menu1=Menu::create(hy_bt,xiaoxi_bt,login_bt,activ_bt,shezi_bt, nullptr); menu1->setPosition(Vec2::ZERO); back_img2->addChild(menu1); //默认为减 oprate_bt=MenuItemImage::create(jia_img,jia_img,CC_CALLBACK_1(Rolelayer::allCallbackm,this)); oprate_bt->setAnchorPoint(Vec2(0.5,0)); oprate_bt->setPosition(Vec2(oprate_bt->getContentSize().width/2,10));//zb_menu->getPositionY()-50)); oprate_bt->setLocalZOrder(100); oprate_bt->setTag(jian_mark); auto menu2=Menu::create(oprate_bt,nullptr); menu2->setPosition(Vec2::ZERO); menu2->setTag(menu_zb2); left_layer->addChild(menu2); allCallbackm(oprate_bt); } }
void BattleFieldUI::showGameOverUI() {//show the gameover UI when loss //diable AI //color layer auto layer = LayerColor::create(Color4B(255, 10, 10, 150)); layer->ignoreAnchorPointForPosition(false); layer->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 0)); //add gameover auto gameOver = Sprite::create("battlefieldUI/gameover.png"); gameOver->setPosition3D(Vec3(VisibleSize.width*0.5, VisibleSize.height*0.5, 3)); gameOver->setScale(0.001); layer->addChild(gameOver, 1); layer->setGlobalZOrder(100); gameOver->setGlobalZOrder(100); auto listener = EventListenerTouchOneByOne::create(); //touch event listener->onTouchBegan = [](Touch*, Event*) { return true; }; listener->onTouchEnded = [this](Touch*, Event*) { //clear GlobalVaribals HeroPool.clear(); DragonPool.clear(); SlimePool.clear(); RatPool.clear(); BossPool.clear(); PigletPool.clear(); HeroManager.clear(); MonsterManager.clear(); GameMaster::reset(); //stop schedule currentLayer->unscheduleUpdate(); Director::getInstance()->getScheduler()->unschedule("gameController", currentLayer); //stop sound experimental::AudioEngine::stop(AUDIO_ID.BATTLEFIELDBGM); //replace scene Director::getInstance()->replaceScene(ChooseRoleScene::createScene()); }; gameOver->setCameraMask(2); auto eventDispatcher = layer->getEventDispatcher(); eventDispatcher->addEventListenerWithSceneGraphPriority(listener, layer); listener->setEnabled(false); auto enableListener = [=]() { listener->setEnabled(true); experimental::AudioEngine::stopAll(); experimental::AudioEngine::play2d("audios/effects/gameover.mp3"); }; //runaction auto action = Sequence::create(DelayTime::create(3), EaseElasticOut::create(ScaleTo::create(1.5, 1)), CallFunc::create(enableListener),NULL); gameOver->runAction(action); addChild(layer); }
bool GameScene::init(){ if (!Layer::init()){ return false; } //此处测试MyMap地图 sGlobal->mapNum = 0; sGlobal->caseNum = 0; MyMap* myMap = MyMap::create(); sGlobal->map = myMap->m_map; sGlobal->myMap = myMap; this->addChild(myMap,5,sGlobal->mapNum); this->addChild(myMap->m_map,6,"map"); ////加载Tiled地图,添加到层中 ////地图是层的child //TMXTiledMap*map = TMXTiledMap::create("scene12test.tmx"); ///*map->setAnchorPoint(Point(0, 0));*/ ///*map->setPosition(Point(0,0));*/ //this->addChild(map,5,"map"); //sGlobal->map = map; ControllerLayer*controllerLayer = ControllerLayer::create(); this->addChild(controllerLayer,20); //测试Hero类,包括对其的添加和动画的正常运行 addHero(myMap->m_map,Point(100,100)); log("这是斜杠n/n,而这是反斜杠n\nhehe"); //此处正式测试菜单 //创建精灵便于getContentSize()函数调用 auto menuLogo = Sprite::create("MenuWhenTouched.png"); Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); auto menuLogoBag = Menu::create(MenuItemImage::create("MenuWhenEased.png", "MenuWhenTouched.png", [&](Object* obj){ //此处切换成菜单层 auto menuLayer = MenuLayer::create();//创建菜单层 this->getParent()->addChild(menuLayer, 10, "tag");//把菜单层添加到游戏场景中 }), NULL); menuLogoBag->setGlobalZOrder(128); //设置位置锚点并添加 menuLogoBag->setAnchorPoint(Point(0, 0)); menuLogoBag->setPosition(Point(menuLogo->getContentSize().width / 2, (visibleSize.height) - (menuLogo->getContentSize().height / 2 + 10))); this->addChild(menuLogoBag, 6); ///*此处测试对话 //TalkLayer* talkLayer = TalkLayer::create(); //this->addChild(talkLayer,60);*/ ////此处测试菜单窗口 //MenuLayer*menuLayer = MenuLayer::create(); //this->addChild(menuLayer, 200); ////此处测试动画 //Sprite*runSp = Sprite::createWithSpriteFrame(SpriteFrame::create("Hero_Down_0.png", Rect(0, 0, 32, 32))); //runSp->setPosition(Point(300, 500)); //this->addChild(runSp,7); ////加载图片帧到缓存池 //SpriteFrameCache*frameCache = SpriteFrameCache::getInstance(); //frameCache->addSpriteFramesWithFile("Hero.plist", "Hero.png"); ////用 AnimationUtil类创建动画 //Animation*animation = AnimationUtil::createWithSingleFrameNameSmall("Hero", "Up", 0.1f, -1); //runSp->runAction(Animate::create(animation)); //auto menu1 = Menu::create(MenuItemImage::create("LoadWhenEased.png", "LoadWhenTouched.png", [&](Object* obj){ // //此处测试切换成菜单层 // /*auto layer2 = Layer::create();*/ // auto layer2 = Layer::create(); // TMXTiledMap*map1 = TMXTiledMap::create("scene13.tmx"); // layer2->addChild(map1); // // this->getParent()->addChild(layer2,10,"tag"); // //此处测试菜单层的删除 // auto menu2 = Menu::create(MenuItemImage::create("LoadWhenEased.png", "LoadWhenTouched.png", [&](Object* obj){ // this->getParent()->removeChildByName("tag"); // }), NULL); // Size size2 = Director::sharedDirector()->getWinSize(); // menu2->setPosition(ccp(size2.width / 4, size2.height / 2)); // layer2->addChild(menu2, 6); //载入按钮 //}), NULL); //Size size = Director::sharedDirector()->getWinSize(); //menu1->setPosition(ccp(size.width / 4, size.height / 3)); //this->addChild(menu1, 6); //载入按钮 /*bool s = sGlobal->load; if (sGlobal->load){ Point loadPosition = Point(CCUserDefault::sharedUserDefault()->getIntegerForKey("heroPositionX"), CCUserDefault::sharedUserDefault()->getIntegerForKey("heroPositionY")); int mapNum = CCUserDefault::sharedUserDefault()->getIntegerForKey("mapNum"); for (int i = 0; i <= 17; i++){ bool a = CCUserDefault::sharedUserDefault()->getBoolForKey((StringUtils::format("bool_%d", i)).c_str()); sGlobal->hero->plot[i] = CCUserDefault::sharedUserDefault()->getBoolForKey((StringUtils::format("bool_%d", i)).c_str()); } this->changeMap(loadPosition, mapNum); sGlobal->load = 0; }*/ return true; }