//------------------------------------------------------------------ // // MenuLayer2 // //------------------------------------------------------------------ MenuLayer2::MenuLayer2() { for( int i=0;i < 2;i++ ) { auto item1 = MenuItemImage::create(s_PlayNormal, s_PlaySelect, CC_CALLBACK_1(MenuLayer2::menuCallback, this)); auto item2 = MenuItemImage::create(s_HighNormal, s_HighSelect, CC_CALLBACK_1(MenuLayer2::menuCallbackOpacity, this)); auto item3 = MenuItemImage::create(s_AboutNormal, s_AboutSelect, CC_CALLBACK_1(MenuLayer2::menuCallbackAlign, this)); item1->setScaleX( 1.5f ); item2->setScaleX( 0.5f ); item3->setScaleX( 0.5f ); auto menu = Menu::create(item1, item2, item3, nullptr); auto s = Director::getInstance()->getWinSize(); menu->setPosition(Vec2(s.width/2, s.height/2)); menu->setTag( kTagMenu ); addChild(menu, 0, 100+i); _centeredMenu = menu->getPosition(); } _alignedH = true; alignMenusH(); }
void MonsterTwoSprite::AI(Point playerPos) { NPCSprite::AI(playerPos); //实现自己的AI Point pos = getPosition(); //怪物比玩家的x坐标大表示怪物在右边 if (pos.x > playerPos.x) { m_npc->changeDir(Left); setScaleX(1); } else { m_npc->changeDir(Right); setScaleX(-1); } float distance = pos.distance(playerPos); if (distance <= MONSTER_AI_SHOOT_DISTANCE) { this->startShoot(); } else { this->closeShoot(); } }
// on "init" you need to initialize your instance bool LoginScene::init() { ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } m_iCurMsgIndex = 0; Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); //背景 auto lsBg = Sprite::create("storybg.png"); lsBg->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + visibleSize.height / 2)); lsBg->setScaleX(visibleSize.width / 640); lsBg->setScaleY(visibleSize.height / 960); this->addChild(lsBg, 0, 0); //对话框 auto chatBg = Sprite::create("chatbg.png"); chatBg->setPosition(Vec2(origin.x + visibleSize.width / 2, origin.y + chatBg->getContentSize().height / 2)); chatBg->setScaleX(visibleSize.width / 640); chatBg->setScaleY(visibleSize.height / 960); this->addChild(chatBg, 1, TAG_CHAT_BG); // readStoryJson(); showNextMsg(); return true; }
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); }
void battbleScene::updatemonstermove(float dt) { std::vector<Monster*>::iterator t; for(t=monsterArr.begin();t!=monsterArr.end();t++) { auto monster=(*t); if(monster->fsm->_currentState=="beingHit") { continue; } if(hero->getPosition().x>monster->getPosition().x) { monster->setScaleX(-1); monster->boolstate->setScaleX(-1); } else { monster->setScaleX(1); monster->boolstate->setScaleX(1); } if((distance(hero->getPosition(),monster->getPosition()))<500) { if((distance(hero->getPosition(),monster->getPosition()))<100) { monster->fsm->doEvent("attack1"); hero->stopAllActions(); hero->resumestate(); hero->currentblood-=monster->attck; if(hero->currentblood<=0) { hero->fsm->doEvent("die"); scheduleOnce([this](float dt){ this->getParent()->getParent()->addChild(Interfactionlayer::create(402)); Director::getInstance()->pause(); }, 1, "gameover"); } else { hero->fsm->doEvent("beHit"); } ((Movehandler*) this->getParent()->getChildByTag(998))->updatedetal(); continue; } monster->fsm->doEvent("run"); movemonster(monster); } else { monster->fsm->doEvent("stop"); } } }
void Skin::setSkinData(const Node& var) { m_sSkinData = var; setScaleX(m_sSkinData.scaleX); setScaleY(m_sSkinData.scaleY); setScaleX(m_sSkinData.scaleX); setScaleY(m_sSkinData.scaleY); setRotation(CC_RADIANS_TO_DEGREES(m_sSkinData.skewX)); setPosition(ccp(m_sSkinData.x, m_sSkinData.y)); m_tSkinTransform = nodeToParentTransform(); }
void WarriorNode::update_ui() { const std::string direction_str = _current_direction == up ? "B" : (_current_direction == down ? "F" : "S"); const std::string state_str = _current_state == stand ? "stand" : (_current_state == run ? "run" : "fight"); getAnimation()->play(direction_str + state_str); if (_current_direction == left || _current_direction == right) setScaleX(_current_direction == right ? -1.0f : 1.0f); else setScaleX(1.0f); }
void FDirSprite::chgDir(float dx, float dy) { const cocos2d::Vec2& pos = getPosition(); bool left = (m_curDir == FDIR_LEFT_UP || m_curDir == FDIR_LEFT_DOWN); bool up = (m_curDir == FDIR_RIGHT_UP || m_curDir == FDIR_LEFT_UP); if (pos.x > dx) { left = true; } else if (pos.x < dx) { left = false; } if (pos.y > dy) { up = false; } else if (pos.y < dy) { up = true; } int dir = left ? (up ? FDIR_LEFT_UP : FDIR_LEFT_DOWN) : (up ? FDIR_RIGHT_UP : FDIR_RIGHT_DOWN); if (dir != m_curDir) { m_curDir = dir; setScaleX(left ? -1 : 1); setSpriteFrame(m_lstFrames[up ? (m_frameNums + m_curIndex) : m_curIndex]); } }
bool GameOver::init(){ if(!Layer::init()) return false; //定义背景 auto sprite = Sprite::create("background.jpg"); //float windowWidth=Director::getInstance()->getWinSize().width; //float windowHeight=Director::getInstance()->getWinSize().height; float imgWidth=sprite->getTextureRect().getMaxX(); float imgHeight=sprite->getTextureRect().getMaxY(); sprite->setScaleX(GAME_SCREEN_WIDTH/imgWidth); sprite->setScaleY(GAME_SCREEN_HEIGHT/imgHeight); sprite->setPosition(GAME_SCREEN_WIDTH/2,GAME_SCREEN_HEIGHT/2); this->addChild(sprite, 0); //定义标题 auto labelTitle=Label::createWithTTF("GAME OVER", "fonts/showg.ttf", FONT_SUPER_LARGE); labelTitle->setPosition(Point(GAME_SCREEN_WIDTH/2,GAME_SCREEN_HEIGHT*3/4)); labelTitle->setColor(Color3B(238,149,114)); this->addChild(labelTitle); //定义restart auto labelRestart=Label::createWithTTF("Restart", "fonts/arial.ttf", FONT_SMALL); labelRestart->setColor(Color3B(238,149,114)); auto menuItemLabel=MenuItemLabel::create(labelRestart,CC_CALLBACK_1(GameOver::restart,this)); menuItemLabel->setPosition(Point(GAME_SCREEN_WIDTH-labelRestart->getContentSize().width,GAME_SCREEN_HEIGHT*3/5)); auto menu=Menu::create(menuItemLabel,NULL); menu->setPosition(Point::ZERO); this->addChild(menu); return true; }
void UIWidget::copyProperties(UIWidget *widget) { setEnabled(widget->isEnabled()); setVisible(widget->isVisible()); setBright(widget->isBright()); setTouchEnabled(widget->isTouchEnabled()); m_bTouchPassedEnabled = false; setZOrder(widget->getZOrder()); setUpdateEnabled(widget->isUpdateEnabled()); setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); m_bIgnoreSize = widget->m_bIgnoreSize; m_tSize = widget->m_tSize; m_tCustomSize = widget->m_tCustomSize; copySpecialProperties(widget); m_eSizeType = widget->getSizeType(); m_tSizePercent = widget->m_tSizePercent; m_ePositionType = widget->m_ePositionType; m_tPositionPercent = widget->m_tPositionPercent; setPosition(widget->getPosition()); setAnchorPoint(widget->getAnchorPoint()); setScaleX(widget->getScaleX()); setScaleY(widget->getScaleY()); setRotation(widget->getRotation()); setRotationX(widget->getRotationX()); setRotationY(widget->getRotationY()); setFlipX(widget->isFlipX()); setFlipY(widget->isFlipY()); setColor(widget->getColor()); setOpacity(widget->getOpacity()); setCascadeOpacityEnabled(widget->isCascadeOpacityEnabled()); setCascadeColorEnabled(widget->isCascadeColorEnabled()); onSizeChanged(); }
bool QuitMenu::init() { if (!Layer::init()) { //auto label = Label::createWithSystemFont("Hello World", "Arial", 96); //label->setAnchorPoint(cocos2d::Vec2(0.0, 0.0)); //this->addChild(label, 1); return false; } auto bg = Sprite::create("MainMenuScreen/BackgroundTemp.jpeg"); auto areYouSureItem = MenuItemImage::create("QuitScreen/AreYouSureText.png", "QuitScreen/AreYouSureText.png"); auto yesItem = MenuItemImage::create("QuitScreen/YesButton.png", "QuitScreen/YesButton.png", CC_CALLBACK_1(QuitMenu::menuCloseCallback, this)); auto noItem = MenuItemImage::create("QuitScreen/NoButton.png", "QuitScreen/NoButton.png", CC_CALLBACK_1(QuitMenu::resume, this)); Size visibleSize = Director::getInstance()->getVisibleSize(); bg->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); bg->setScaleX(visibleSize.width / bg->getContentSize().width); bg->setScaleY(visibleSize.height / bg->getContentSize().height); auto menu = Menu::create(areYouSureItem, yesItem, noItem, NULL); menu->alignItemsVerticallyWithPadding(visibleSize.height / 4); this->addChild(bg); this->addChild(menu); return true; }
bool GameNext::init() { ////////////////////////////// // 1. super init first if (!Scene::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// if(game_round<=9) { gr_pic = "0" + Value(game_round).asString(); }else if(game_round>=10) { gr_pic = Value(game_round).asString(); } if((game_level-1)<=9) { gl_pic = "0" + Value(game_level-1).asString(); }else if((game_level-1)>=10) { gl_pic = Value(game_level-1).asString(); } //被弄成灰色的截图 auto ac = Sprite::create(picNext); ac->setAnchorPoint(Vec2(0,0)); ac->setPosition(Vec2(0,0)); ac->setScaleX(visibleSize.width/ac->getTextureRect().getMaxX()); //设置精灵宽度缩放比例 ac->setScaleY(visibleSize.height/ac->getTextureRect().getMaxY()); this->addChild(ac,100); //半透明层,在截图之上 LayerColor* layerColor = CCLayerColor::create(); layerColor->setColor(cocos2d::Color3B(0, 0, 0)); layerColor->setOpacity(150); layerColor->setContentSize(Size(visibleSize.width, visibleSize.height)); this->addChild(layerColor,101); //next小方块的背景 auto gameover = Sprite::create("setting/gamenext.png"); gameover->setPosition(Vec2(origin.x + visibleSize.width/2,origin.y + visibleSize.height/2)); this->addChild(gameover,102); scheduleUpdate(); return true; }
bool PlanetSprite::init() { if(!Sprite3D::init()) return false; //Loads the mesh from cache loadFromCache(PLANET_MESH_MARS); //Loads the texture setTexture(PLANET_TEXTURE_MARS); //Calculates a random rotation speed and Z axis inclination int rotationSpeed = RandomHelper::random_int(1, 3); unsigned int axisInclinitation = RandomHelper::random_int(-90, 90); //Calculates a random sacale float scale = RandomHelper::random_real(1.f, 3.f); //Calculates a irregular scale float scaleX = RandomHelper::random_real(1.0f, 1.25f) * scale; float scaleY = RandomHelper::random_real(1.0f, 1.25f) * scale; float scaleZ = RandomHelper::random_real(1.0f, 1.25f) * scale; setScaleX(scaleX); setScaleY(scaleY); setScaleZ(scaleZ); setRotation3D(Vec3(0, 0, axisInclinitation)); runAction(RepeatForever::create(RotateBy::create(rotationSpeed, Vec3(0, 360, 0)))); return true; }
bool UpgradeMenu::init() { if (!Layer::init()) { return false; } CCSize s = CCDirector::sharedDirector()->getWinSize(); auto mySprite = Sprite::create("UpgradeScreen/tutorial.png"); mySprite->setScaleX((s.width / mySprite->getContentSize().width)); mySprite->setScaleY((s.height / mySprite->getContentSize().height)); // bottom left mySprite->setAnchorPoint(cocos2d::Vec2(0, 0)); this->addChild(mySprite, -1); auto mainMenuItem = MenuItemImage::create("UpgradeScreen/Menu_Button.png", "UpgradeScreen/Menu_Button(Click).png", CC_CALLBACK_1(UpgradeMenu::activateMainMenuScene, this)); auto menu = Menu::create(mainMenuItem, NULL); // Returns visible size of OpenGL window in points. Size visibleSize = Director::getInstance()->getVisibleSize(); menu->setPosition(150, s.height - 100); this->addChild(menu); return true; }
CoreElementBullet::CoreElementBullet(const std::string& armatureName, const std::string& effectArmatureName, float radian, float speed, const cocos2d::Vec2& position) { _speedX = std::cos(radian) * speed; _speedY = -std::sin(radian) * speed; _armature = CoreElementGame::instance->factory.buildArmature(armatureName); _armatureDisplay = (dragonBones::CCArmatureDisplay*)_armature->getDisplay(); _armatureDisplay->setPosition(position); _armatureDisplay->setRotation(radian * dragonBones::RADIAN_TO_ANGLE); _armature->getAnimation().play("idle"); if (!effectArmatureName.empty()) { _effect = CoreElementGame::instance->factory.buildArmature(effectArmatureName); const auto effectDisplay = (dragonBones::CCArmatureDisplay*)_effect->getDisplay(); effectDisplay->setPosition(position); effectDisplay->setRotation(radian * dragonBones::RADIAN_TO_ANGLE); effectDisplay->setScaleX(cocos2d::random(1.f, 2.f)); effectDisplay->setScaleY(cocos2d::random(1.f, 1.5f)); if (cocos2d::random(0.f, 1.f) < 0.5f) { effectDisplay->setScaleY(effectDisplay->getScaleY()); } _effect->getAnimation().play("idle"); dragonBones::WorldClock::clock.add(_effect); CoreElementGame::instance->addChild(effectDisplay); } dragonBones::WorldClock::clock.add(_armature); CoreElementGame::instance->addChild(_armatureDisplay); }
void PageManager::changeBackGround(const std::string &pic) { auto backLlayer = rootPage()->_backLayer; if ( backLlayer ) { backLlayer->removeAllChildren(); if ( pic.empty() ) { // empty pic name will delete the background. return; } auto background = CCSprite::create(pic.c_str()); if ( !background ) { // invalid pic name will delete the background. return; } auto size = background->getContentSize(); auto winSize = CocosWindow::size(); background->setScaleX(winSize.width / size.width); background->setScaleY(winSize.height / size.height); background->setPosition(CocosWindow::center()); backLlayer->addChild(background); } }
// on "init" you need to initialize your instance bool SplashScene::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); //定时器设置停留2秒后自动跳转到主界面 this->scheduleOnce( schedule_selector( SplashScene::GoToMainMenuScene ), DISPLAY_TIME_SPLASH_SCENE ); auto backgroundSprite = Sprite::create( "splash.jpg" ); Size size = Director::getInstance()->getWinSize(); backgroundSprite->setPosition(Vec2(size.width / 2, size.height / 2)); float winw = size.width; //获取屏幕宽度 float winh = size.height;//获取屏幕高度 float spx = backgroundSprite->getTextureRect().getMaxX(); float spy = backgroundSprite->getTextureRect().getMaxY(); backgroundSprite->setScaleX(winw / spx); //设置精灵宽度缩放比例 backgroundSprite->setScaleY(winh / spy); //backgroundSprite->setPosition( Point( visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y) ); this->addChild( backgroundSprite ); return true; }
bool GuideScene::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); cocos2d::Vec2 center((cocos2d::Director::getInstance()->getVisibleSize().width / 2 + cocos2d::Director::getInstance()->getVisibleOrigin().x), (cocos2d::Director::getInstance()->getVisibleSize().height / 2 + cocos2d::Director::getInstance()->getVisibleOrigin().y)); auto welcomePic=Sprite::create("Starter_bg.png"); welcomePic->setPosition(Point(visibleSize.width/2+origin.x, visibleSize.height/2+origin.y)); welcomePic->setScaleX(visibleSize.width/welcomePic->getContentSize().width); welcomePic->setScaleY(visibleSize.height/welcomePic->getContentSize().height); this->addChild(welcomePic); auto menuItem = MenuItemImage::create("Exit (1).png", "Exit (2).png", CC_CALLBACK_1(GuideScene::goToMainMenu, this)); menuItem->setPosition(center.x, center.y - visibleSize.height*0.35); auto menu = Menu::create(menuItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu); Guide_move(); return true; }
void Rolelayer::playAnimationByname(Node *bs,std::string jsonfile,std::string filename,std::string animationName,bool isloop,bool isscal,Vec2 p){ auto armature =Armature::create(filename.c_str()); if(isloop==true){ armature->getAnimation()->play(animationName.c_str(),-1,1); } armature->removeFromParentAndCleanup(true); armature->setPosition(p); armature->setTag(100); armature->setLocalZOrder(100); bs->addChild(armature); //xx_sly if(getUnitTypeByArmatureName(filename) == unittype_Actor){ auto yinying_img=Sprite::create(hero_yingyin_img); //(hero_yingyin_img); yinying_img->setAnchorPoint(Vec2(0.5,0)); yinying_img->setScaleX(1.5f); yinying_img->setPosition(Vec2(p.x,-armature->getContentSize().height/2+40)); bs->addChild(yinying_img); // xkongz.xx_action=armature; // xkongz.time=0; // xkongz.xxtime[0]=20; // xkongz.xxtime[1]=1; // xkongz.change=false; } else if(getUnitTypeByArmatureName(filename) == unittype_Pet){ auto yinying_img=Sprite::create(hero_yingyin_img); //(hero_yingyin_img); yinying_img->setAnchorPoint(Vec2(0.5,0)); yinying_img->setPosition(Vec2(p.x,-armature->getContentSize().height/2+30)); bs->addChild(yinying_img); } else if(getUnitTypeByArmatureName(filename) == unittype_Magic){ armature->setScale(0.5f); } }
void Stage1Scene::menuSubmitCallback(Ref* pSender) { currentAnswer = mAnswerBox->getText(); CCLOG("%s",currentAnswer.c_str()); if (currentAnswer != answer[questionIndex] ) { pictureIndex++; if (pictureIndex >= 5) { CCLOG("f**k"); Director::getInstance()->replaceScene(MapScene::create()); } } else { // wining UserDefault::getInstance()->setStringForKey(UserDefault::getInstance()->getStringForKey("CurrentCityName").c_str(), "win"); UserDefault::getInstance()->setIntegerForKey("CurrentCityNo",questionIndex + 1); UserDefault::getInstance()->setStringForKey("CurrentCityName", __String::createWithFormat("city0%d", questionIndex + 1)->getCString()); Director::getInstance()->replaceScene(MapScene::create()); } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); auto cluePicture = Sprite::create(__String::createWithFormat("%s%d.jpg", cluePictures[questionIndex].c_str(), pictureIndex)->getCString()); cluePicture->setPosition(Point(visibleSize.width / 2 + origin.x, visibleSize.height / 2 + origin.y+visibleSize.height/5)); cluePicture->setScaleX(visibleSize.width / 2 / cluePicture->getContentSize().width); cluePicture->setScaleY(visibleSize.height / 2 / cluePicture->getContentSize().height); // add the sprite as a child to this layer mStage1Layer->addChild(cluePicture); currentAnswer = "sai"; }
int32_t LuaDrawable::setScaleX(lua_State *L) { auto drawable = Lua::getObject<Drawable>(L, 1, LuaType::Drawable); auto scaleX = static_cast<float>(Lua::getNumber(L, 2)); drawable->setScaleX(scaleX); return 0; }
MenuItem* MenuScene::displayPlayBtn() { auto spriteNormal = Sprite::create("base.png"); spriteNormal->setColor(Color3B(170, 226, 246)); auto spriteSelected = Sprite::create("base.png"); spriteSelected->setColor(Color3B(182, 230, 246)); auto spriteDisabled = Sprite::create("base.png"); spriteDisabled->setColor(Color3B::GRAY); auto btn = MenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, CC_CALLBACK_1(MenuScene::onClickPlay, this) ); btn->setScale(3.6f, 1.8f); btn->setPosition(Vec2(-170, 0)); btn->setOpacity(200); auto cupIcon = Label::createWithTTF(FC_ICON_BIG, FA_MGR->getContent(FAPlayCircle)); if (cupIcon) { cupIcon->setTextColor(Color4B::WHITE); cupIcon->enableOutline(Color4B::GRAY); cupIcon->setScaleX(1.0f / 3.6f); cupIcon->setScaleY(1.0f / 1.8f); auto size = btn->getContentSize(); cupIcon->setPosition(Vec2(size.width / 2, size.height / 2)); btn->addChild(cupIcon, 10); } return btn; }
void alert(const std::string &text){ auto title=Label::create(text,"fonts/hyz.ttf", 28); cocos2d::Size titleSize=title->getBoundingBox().size; title->setPosition((titleSize.width+40)/2, (titleSize.height+40)/2); auto box=Sprite::create(); box->setTextureRect(cocos2d::Rect(0, 0, titleSize.width+40, titleSize.height+40)); box->setPosition(WIDTH/2, HEIGHT/8*3+100); box->setColor(ccc3(0, 0, 0)); box->addChild(title); title->setScaleX(1./box->getScaleX()); title->setScaleY(1./box->getScaleY()); auto scene = Director::getInstance()->getRunningScene(); scene->addChild(box,100); auto fade = FadeIn::create(1); auto delay = DelayTime::create(2); auto fadeOut = FadeOut::create(1); auto seque = Sequence::create(fade,delay,fadeOut,NULL); auto fade2 = FadeIn::create(1); auto delay2 = DelayTime::create(2); auto fadeOut2 = FadeOut::create(1); auto seque2 = Sequence::create(fade2,delay2,fadeOut2,NULL); box->runAction(seque); title->runAction(seque2); }
void Widget::copyProperties(Widget *widget) { setEnabled(widget->isEnabled()); setVisible(widget->isVisible()); setBright(widget->isBright()); setTouchEnabled(widget->isTouchEnabled()); _touchPassedEnabled = false; setLocalZOrder(widget->getLocalZOrder()); setTag(widget->getTag()); setName(widget->getName()); setActionTag(widget->getActionTag()); _ignoreSize = widget->_ignoreSize; _size = widget->_size; _customSize = widget->_customSize; copySpecialProperties(widget); _sizeType = widget->getSizeType(); _sizePercent = widget->_sizePercent; _positionType = widget->_positionType; _positionPercent = widget->_positionPercent; setPosition(widget->getPosition()); setAnchorPoint(widget->getAnchorPoint()); setScaleX(widget->getScaleX()); setScaleY(widget->getScaleY()); setRotation(widget->getRotation()); setRotationX(widget->getRotationX()); setRotationY(widget->getRotationY()); setFlipX(widget->isFlipX()); setFlipY(widget->isFlipY()); setColor(widget->getColor()); setOpacity(widget->getOpacity()); setCascadeOpacityEnabled(widget->isCascadeOpacityEnabled()); setCascadeColorEnabled(widget->isCascadeColorEnabled()); onSizeChanged(); }
void GameCharacterShape::floatNumber(int num, GameCharacterShape::FloatNumberTypeEnum type ) { char numStr[10]; sprintf(numStr, "-%d", num); // 选择使用的文字样式 auto tmpFntSrc = ""; switch (type) { case GameCharacterShape::FLOAT_NUMBER_GREEN: tmpFntSrc = "font/greennumber.fnt"; break; case GameCharacterShape::FLOAT_NUMBER_RED: tmpFntSrc = "font/rednumber.fnt"; break; case GameCharacterShape::FLOAT_NUMBER_YELLOW: tmpFntSrc = "font/yellownumber.fnt"; break; default: break; } // 创建标签 auto tmpText = Label::createWithBMFont(tmpFntSrc, numStr); tmpText->setPositionY(_armature->getContentSize().height / 2); this->addChild(tmpText, 4); tmpText->setScaleX(this->getScaleX()); // 绑定浮动的动画,播放动画 auto tmpMoveBy = MoveBy::create(FLOATNUMBERDIRATION, Vec2(0, FLOATNUMBERMOVEBYY)); tmpText->runAction(Sequence::create(tmpMoveBy, CallFuncN::create(std::bind(&GameCharacterShape::onFloatNumberMoveOver, this, std::placeholders::_1)), nullptr)); }
MenuItem* GameOverLayer::displayGameCenterBtn() { auto spriteNormal = Sprite::create("base.png"); spriteNormal->setColor(Color3B(246, 222, 160)); auto spriteSelected = Sprite::create("base.png"); spriteSelected->setColor(Color3B(248, 224, 164)); auto spriteDisabled = Sprite::create("base.png"); spriteDisabled->setColor(Color3B::GRAY); auto btn = MenuItemSprite::create(spriteNormal, spriteSelected, spriteDisabled, CC_CALLBACK_1(GameOverLayer::onClickGameCenter, this) ); btn->setScale(3.6f, 1.8f); btn->setPosition(Vec2(170, -110)); btn->setOpacity(200); auto cupIcon = Label::createWithTTF(FC_ICON_BIG, FA_MGR->getContent(FAGamepad)); if (cupIcon) { cupIcon->setTextColor(Color4B::WHITE); cupIcon->enableOutline(Color4B::GRAY); cupIcon->setScaleX(1.0f / 3.6f); cupIcon->setScaleY(1.0f / 1.8f); auto size = btn->getContentSize(); cupIcon->setPosition(Vec2(size.width / 2, size.height / 2)); btn->addChild(cupIcon, 10); } return btn; }
void UIWidget::adaptSize(float xProportion,float yProportion) { m_fAdaptScaleX = xProportion; m_fAdaptScaleY = yProportion; setScaleX(m_fAdaptScaleX*getScaleX()); setScaleY(m_fAdaptScaleY*getScaleY()); }
// on "init" you need to initialize your instance bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); auto sb = GameLayer::create(); sb->setTag(123); sb->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); addChild(sb); auto fog = Sprite::createWithSpriteFrameName("fog.png"); addChild(fog); fog->setPosition(visibleSize.width/2,visibleSize.height/2+285); fog->setScaleX(visibleSize.width/10); //HP auto lefttopUI = Sprite::createWithSpriteFrameName("hp_empty.png"); lefttopUI->setAnchorPoint(Point(0,1)); lefttopUI->setPosition(Point(0, visibleSize.height+origin.y)); addChild(lefttopUI); hpView = ProgressTimer::create(Sprite::createWithSpriteFrameName("hp.png")); hpView->setType(ProgressTimer::Type::BAR); hpView->setMidpoint(Point(0,0)); hpView->setPercentage(1); hpView->setBarChangeRate(Point(0, 1)); hpView->setPercentage(100); hpView->setAnchorPoint(Point(0,1)); hpView->setPosition(Point(18, visibleSize.height+origin.y-32)); addChild(hpView); auto hpAbove = Sprite::createWithSpriteFrameName("hp_above.png"); hpAbove->setAnchorPoint(Point(0,1)); hpAbove->setPosition(Point(18, visibleSize.height+origin.y-32)); addChild(hpAbove); //Score auto rightTopUI = Sprite::createWithSpriteFrameName("right_top_ui.png"); rightTopUI->setAnchorPoint(Point(1,1)); rightTopUI->setPosition(origin+Point(visibleSize)); this->addChild(rightTopUI); //the menuitem to show score scoreLabel = LabelAtlas::create("0", "score_right_top.png", 23, 28, '0'); scoreLabel->setAnchorPoint(Point(1,0.5)); scoreLabel->setPosition(visibleSize.width-40,visibleSize.height-45); this->addChild(scoreLabel); this->schedule(schedule_selector(HelloWorld::increaseScore), (float)1/10); //this->addChild(scoreLabel); NotificationCenter::getInstance()->destroyInstance(); NotificationCenter::getInstance()->addObserver(this,callfuncO_selector(HelloWorld::ShowGameOver),"ShowGameOver",NULL); return true; }
void MainScreen::draw() { auto sprite = Sprite::create("img/ScreenProjectFon.png"); sprite->setScaleX(_size.width/sprite->getContentSize().width); sprite->setScaleY(_size.height/sprite->getContentSize().height); sprite->setPosition(Point(_size.width/2, _size.height/2)); root->addChild(sprite, 0); }
bool Plane::init(){ CCSprite::initWithFile(getPlaneRes()); addPlane(this); speed = CCRANDOM_0_1()*4+1; if(rand()%100<50){ setScaleX(1); setPosition(ccp(570, 370)); speed = -speed; }else{ setScaleX(-1); setPosition(ccp(-20, 370)); } scheduleUpdate(); return true; }