bool LayerSetup::init() { CCLayer::init(); CCSprite *bg = CCSprite::create("Set_Music.png"); bg->setPosition(ccp(winSize.width / 2, winSize.height / 2)); addChild(bg); bg->setScale(0.75f); setTouchMode(kCCTouchesOneByOne); setTouchEnabled(true); setTouchPriority(kCCMenuHandlerPriority << 1); CCMenu *menu = CCMenu::create(); CCSprite *sp1 = CCSprite::create("music_on.png"); CCSprite *sp2 = CCSprite::create("music_off.png"); CCSprite *sp3 = CCSprite::create("sound_effect_on.png"); CCSprite *sp4 = CCSprite::create("sound_effect_off.png"); sp1->setScale(0.9f); sp2->setScale(0.9f); sp3->setScale(0.9f); sp4->setScale(0.9f); CCMenuItemSprite *_bgON = CCMenuItemSprite::create(sp1, sp1); CCMenuItemSprite *_bgOFF = CCMenuItemSprite::create(sp2, sp2); CCMenuItemSprite *_effectON = CCMenuItemSprite::create(sp3, sp3); CCMenuItemSprite *_effectOFF = CCMenuItemSprite::create(sp4, sp4); bool isBg = CCUserDefault::sharedUserDefault()->getBoolForKey("BGStatus", true); bool isEff = CCUserDefault::sharedUserDefault()->getBoolForKey("EffectStatus", true); isBg ? _bg = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setBG), _bgON, _bgOFF, NULL) : _bg = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setBG), _bgOFF, _bgON, NULL); isEff ? _effect = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setEffect), _effectON, _effectOFF, NULL) : _effect = CCMenuItemToggle::createWithTarget(this, menu_selector(LayerSetup::setEffect), _effectOFF, _effectON, NULL); CCScale9Sprite *bgButton = CCScale9Sprite::create("button.png"); CCScale9Sprite *bgButtonLighted = CCScale9Sprite::create("buttonHighlighted.png"); CCScale9Sprite *bgButton2 = CCScale9Sprite::create("button.png"); CCScale9Sprite *bgButtonLighted2 = CCScale9Sprite::create("buttonHighlighted.png"); CCLabelTTF * text1 = CCLabelTTF::create("back", "verdana", 20); CCLabelTTF * text2 = CCLabelTTF::create("home", "verdana", 20); _back = CCControlButton::create(text1, bgButton); _home = CCControlButton::create(text2, bgButton2); _back->setBackgroundSpriteForState(bgButtonLighted, CCControlStateHighlighted); _back->addTargetWithActionForControlEvents(this, cccontrol_selector(LayerSetup::backGame), CCControlEventTouchDown); _home->setBackgroundSpriteForState(bgButtonLighted2, CCControlStateHighlighted); _home->addTargetWithActionForControlEvents(this, cccontrol_selector(LayerSetup::backHome), CCControlEventTouchDown); _bg->setPosition(ccp(60, -20)); _effect->setPosition(ccp(60, 40)); _home->setPosition(ccp(winSize.width / 2 - 70, winSize.height / 2 - 70)); _back->setPosition(ccp(winSize.width / 2 + 70, winSize.height / 2 - 70)); menu->setTouchPriority(kCCMenuHandlerPriority << 2); _home->setTouchPriority(kCCMenuHandlerPriority << 2); _back->setTouchPriority(kCCMenuHandlerPriority << 2); menu->addChild(_bg); menu->addChild(_effect); addChild(menu); addChild(_home); addChild(_back); return true; }
void RenderContainer::updateBeforeAfterContentForContainer(RenderStyle::PseudoId type, RenderContainer* styledObject) { // In CSS2, before/after pseudo-content cannot nest. Check this first. if (style()->styleType() == RenderStyle::BEFORE || style()->styleType() == RenderStyle::AFTER) return; RenderStyle* pseudoElementStyle = styledObject->getCachedPseudoStyle(type); RenderObject* child = beforeAfterContainer(type); // Whether or not we currently have generated content attached. bool oldContentPresent = child; // Whether or not we now want generated content. bool newContentWanted = pseudoElementStyle && pseudoElementStyle->display() != NONE; // For <q><p/></q>, if this object is the inline continuation of the <q>, we only want to generate // :after content and not :before content. if (newContentWanted && type == RenderStyle::BEFORE && isInlineContinuation()) newContentWanted = false; // Similarly, if we're the beginning of a <q>, and there's an inline continuation for our object, // then we don't generate the :after content. if (newContentWanted && type == RenderStyle::AFTER && isRenderInline() && continuation()) newContentWanted = false; // If we don't want generated content any longer, or if we have generated content, but it's no longer // identical to the new content data we want to build render objects for, then we nuke all // of the old generated content. if (!newContentWanted || (oldContentPresent && !child->style()->contentDataEquivalent(pseudoElementStyle))) { // Nuke the child. if (child && child->style()->styleType() == type) { oldContentPresent = false; child->destroy(); child = (type == RenderStyle::BEFORE) ? m_firstChild : m_lastChild; } } // If we have no pseudo-element style or if the pseudo-element style's display type is NONE, then we // have no generated content and can now return. if (!newContentWanted) return; if (isInlineFlow() && !pseudoElementStyle->isDisplayInlineType() && pseudoElementStyle->floating() == FNONE && !(pseudoElementStyle->position() == AbsolutePosition || pseudoElementStyle->position() == FixedPosition)) // According to the CSS2 spec (the end of section 12.1), the only allowed // display values for the pseudo style are NONE and INLINE for inline flows. // FIXME: CSS2.1 lifted this restriction, but block display types will crash. // For now we at least relax the restriction to allow all inline types like inline-block // and inline-table. pseudoElementStyle->setDisplay(INLINE); if (oldContentPresent) { if (child && child->style()->styleType() == type) { // We have generated content present still. We want to walk this content and update our // style information with the new pseudo-element style. child->setStyle(pseudoElementStyle); // Note that if we ever support additional types of generated content (which should be way off // in the future), this code will need to be patched. for (RenderObject* genChild = child->firstChild(); genChild; genChild = genChild->nextSibling()) { if (genChild->isText()) // Generated text content is a child whose style also needs to be set to the pseudo-element style. genChild->setStyle(pseudoElementStyle); else if (genChild->isImage()) { // Images get an empty style that inherits from the pseudo. RefPtr<RenderStyle> style = RenderStyle::create(); style->inheritFrom(pseudoElementStyle); genChild->setStyle(style.release()); } else // Must be a first-letter container. updateFirstLetter() will take care of it. ASSERT(genChild->style()->styleType() == RenderStyle::FIRST_LETTER); } } return; // We've updated the generated content. That's all we needed to do. } RenderObject* insertBefore = (type == RenderStyle::BEFORE) ? firstChild() : 0; // Generated content consists of a single container that houses multiple children (specified // by the content property). This generated content container gets the pseudo-element style set on it. RenderObject* generatedContentContainer = 0; // Walk our list of generated content and create render objects for each. for (const ContentData* content = pseudoElementStyle->contentData(); content; content = content->m_next) { RenderObject* renderer = 0; switch (content->m_type) { case CONTENT_NONE: break; case CONTENT_TEXT: renderer = new (renderArena()) RenderTextFragment(document() /* anonymous object */, content->m_content.m_text); renderer->setStyle(pseudoElementStyle); break; case CONTENT_OBJECT: { RenderImageGeneratedContent* image = new (renderArena()) RenderImageGeneratedContent(document()); // anonymous object RefPtr<RenderStyle> style = RenderStyle::create(); style->inheritFrom(pseudoElementStyle); image->setStyle(style.release()); if (StyleImage* styleImage = content->m_content.m_image) image->setStyleImage(styleImage); renderer = image; break; } case CONTENT_COUNTER: renderer = new (renderArena()) RenderCounter(document(), *content->m_content.m_counter); renderer->setStyle(pseudoElementStyle); break; } if (renderer) { if (!generatedContentContainer) { // Make a generated box that might be any display type now that we are able to drill down into children // to find the original content properly. generatedContentContainer = RenderObject::createObject(document(), pseudoElementStyle); generatedContentContainer->setStyle(pseudoElementStyle); } generatedContentContainer->addChild(renderer); } } // Add the pseudo after we've installed all our content so that addChild will be able to find the text // inside the inline for e.g., first-letter styling. if (generatedContentContainer) addChild(generatedContentContainer, insertBefore); }
// on "init" you need to initialize your instance bool HelloWorld::init() { if ( !Layer::init() ) { return false; } Vec2 visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); timeSinceLastMouseUp = 9999; timeSinceLastNotifierUpdate = 0; timeSinceLastObjectCull = 0; // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen sprite->setPosition(Vec2(visibleSize.x/2 + origin.x, visibleSize.y/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); overlaySprite = Sprite::create(); overlaySprite->setPosition(visibleSize/2); this->addChild(overlaySprite, UI_DEPTH); auto label = Label::createWithTTF("Hello World", "fonts/Marker Felt.ttf", 24); // position the label on the center of the screen label->setPosition(Vec2(0,label->getContentSize().height/2)); // add the label as a child to this layer overlaySprite->addChild(label, 1); cursorSprite = Sprite::create("cursors/arrow.png"); addChild(cursorSprite, CURSOR_DEPTH); cursorSprite->setScale(0.7); protractor = (Sprite*) new Protractor("protractor", PROTRACTOR_SIZE); addChild(protractor, 1); commorose = (Sprite*) new Commorose("commorose"); addChild(commorose, CURSOR_DEPTH - 1); commorose->setVisible(false); TorpedoData::init("torpedos.jld"); playerSub = (Sprite*) new Submarine("player-sub.png"); auto s = (Submarine*)playerSub; s->setName(PLAYER_SUB_NAME); s->setPhysicsModel(PhysicsModel::Newtonian); s->setMass(300); s->setFriction(5); s->setMaxForce(20 * 1000); s->setPropulsionType(PropulsionType::Diesel); s->setNoisiness(40); addChild(playerSub, UI_DEPTH); playerDeltaForcePerSecond = 2000; playerTurning = false; ((Submarine*)playerSub)->addTorpedoPrototype(new TorpedoData("testpedo", "testpedo")); notifier = (Sprite*) new Notifier("notifier", visibleSize); ((Notifier*)notifier)->setThrustBar(0); ((Notifier*)notifier)->setNoiseBar(0); addChild(notifier, UI_DEPTH); moveScreenBy(Director::getInstance()->getVisibleSize()/-2); lookAt(Vec2::ZERO); this->scheduleUpdate(); return true; }
bool Barrier::init(int type) { Size visibleSize = Director::getInstance()->getVisibleSize(); m_barrierType = type; char filename[128]; sprintf(filename, "Images/Game/Barrier_%02d_01.png", m_barrierType); // Barrier_01_01 ui::Button *button = ui::Button::create(filename); button->addClickEventListener(CC_CALLBACK_1(Barrier::ClickBarrier, this)); button->setOpacity(0); addChild(button); // Barrier Area sprintf(filename, "Data/Barrier/Barrier_Type_%d.json", m_barrierType); char buffer[100]; FILE *file = fopen(filename, "r"); rapidjson::FileReadStream is(file, buffer, sizeof(buffer)); rapidjson::Document document; document.ParseStream(is); fclose(file); rapidjson::Value &positionArray = document["position"]; for (auto iter = positionArray.Begin(); iter != positionArray.End(); iter++) { Vec2 position; position.x = (float)(*iter)["x"].GetInt(); position.y = (float)(*iter)["y"].GetInt(); m_barrierArea.emplace_back(position); } rapidjson::Value &areaArray = document["area"]; for (auto iter = areaArray.Begin(); iter != areaArray.End(); iter++) { Vec2 position; Vec2 scale; position.x = (float)(*iter)["x"].GetInt(); position.y = (float)(*iter)["y"].GetInt(); scale.x = (float)(*iter)["scale_x"].GetDouble(); scale.y = (float)(*iter)["scale_y"].GetDouble(); //m_barrierArea.emplace_back(position); } // Animation Size buttonSize = button->getContentSize(); Sprite *sprite = Sprite::create(filename); sprite->setPosition(buttonSize.width / 2.0f, buttonSize.height / 2.0f); Animation *animation = Animation::create(); for (int i = 0; i < 6; i++) { sprintf(filename, "Images/Game/Barrier_%02d_%02d.png", m_barrierType, i + 1); animation->addSpriteFrameWithFile(filename); } animation->setDelayPerUnit(0.1f); animation->setRestoreOriginalFrame(true); Animate *animate = Animate::create(animation); RepeatForever *repeatForever = RepeatForever::create(animate); sprite->runAction(repeatForever); button->addChild(sprite); ui::Button *buttonDemolish = ui::Button::create("Images/Game/temp_x.png"); buttonDemolish->setPosition(Vec2(buttonSize.width, buttonSize.height)); buttonDemolish->setVisible(false); buttonDemolish->addClickEventListener(CC_CALLBACK_1(Barrier::ClickDemolish, this)); buttonDemolish->setName("Button_Demolish"); button->addChild(buttonDemolish, 1); // Event EventListenerCustom *eventListener = EventListenerCustom::create("Object_Menu_Close", CC_CALLBACK_1(Barrier::ObjectMenuClose, this)); _eventDispatcher->addEventListenerWithSceneGraphPriority(eventListener, this); return true; }
ColorSelector::ColorSelector() : PopupFramePin("Color Selector", false) , m_color(Color::fromMask()) , m_vbox(JI_VERTICAL) , m_topBox(JI_HORIZONTAL) , m_colorPalette(false) , m_indexButton("Index", 1, JI_BUTTON) , m_rgbButton("RGB", 1, JI_BUTTON) , m_hsvButton("HSB", 1, JI_BUTTON) , m_grayButton("Gray", 1, JI_BUTTON) , m_maskButton("Mask", 1, JI_BUTTON) , m_maskLabel("Transparent Color Selected") , m_disableHexUpdate(false) { m_topBox.setBorder(gfx::Border(0)); m_topBox.child_spacing = 0; m_colorPalette.setColumns(40); m_colorPalette.setBoxSize(6*jguiscale()); m_colorPaletteContainer.attachToView(&m_colorPalette); m_colorPaletteContainer.setExpansive(true); setup_mini_look(&m_indexButton); setup_mini_look(&m_rgbButton); setup_mini_look(&m_hsvButton); setup_mini_look(&m_grayButton); setup_mini_look(&m_maskButton); m_topBox.addChild(&m_indexButton); m_topBox.addChild(&m_rgbButton); m_topBox.addChild(&m_hsvButton); m_topBox.addChild(&m_grayButton); m_topBox.addChild(&m_maskButton); m_topBox.addChild(&m_hexColorEntry); { Box* miniVbox = new Box(JI_VERTICAL); miniVbox->addChild(getPin()); m_topBox.addChild(new BoxFiller); m_topBox.addChild(miniVbox); } m_vbox.addChild(&m_topBox); m_vbox.addChild(&m_colorPaletteContainer); m_vbox.addChild(&m_rgbSliders); m_vbox.addChild(&m_hsvSliders); m_vbox.addChild(&m_graySlider); m_vbox.addChild(&m_maskLabel); addChild(&m_vbox); m_indexButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_rgbButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_hsvButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_grayButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_maskButton.Click.connect(&ColorSelector::onColorTypeButtonClick, this); m_colorPalette.IndexChange.connect(&ColorSelector::onColorPaletteIndexChange, this); m_rgbSliders.ColorChange.connect(&ColorSelector::onColorSlidersChange, this); m_hsvSliders.ColorChange.connect(&ColorSelector::onColorSlidersChange, this); m_graySlider.ColorChange.connect(&ColorSelector::onColorSlidersChange, this); m_hexColorEntry.ColorChange.connect(&ColorSelector::onColorHexEntryChange, this); selectColorType(Color::RgbType); setPreferredSize(gfx::Size(300*jguiscale(), getPreferredSize().h)); m_onPaletteChangeSlot = App::instance()->PaletteChange.connect(&ColorSelector::onPaletteChange, this); initTheme(); }
void CompGachaBtn::addHead() { isExchangeAble =true; int specailH=0; if(cardLines == 1) specailH = 40; char buf[50]; for(int i=0;i<m_compGachaInfo->material->count();i++) { CCSprite *head = CGameData::Inst()->getHeadSprite(m_compGachaInfo->material->getObjectAtIndex(i)->cid); addChild(head,1000); head->setPosition(CCPoint(-190+105*(i%3),-80-(i/3)*110-specailH)); head->setTag(MATERIALTAG+i); if(!m_compGachaInfo->material->getObjectAtIndex(i)->isOwe) { head->setOpacity(128); isExchangeAble =false; } if(m_compGachaInfo->material->getObjectAtIndex(i)->isNew) { showNewCardEffect(head); } } CCSprite *targetHead; if(m_compGachaInfo->isHide) { sprintf(buf, "fr_query_box.PNG"); targetHead = CCSprite::spriteWithFile(buf); m_ret.isUnKnowHero = true; } else { targetHead = CGameData::Inst()->getHeadSprite(m_compGachaInfo->targetCid); m_ret.isUnKnowHero = false; } addChild(targetHead,1000); targetHead->setPosition(CCPoint(160,-80)); targetHead->setTag(SUPERHEROTAG); CCSprite *normalSp; CCSprite *selectedSp ; if(isExchangeAble) { normalSp = CCSprite::spriteWithFile("cg_button_1.png"); selectedSp = CCSprite::spriteWithFile("cg_button_1.png"); }else { normalSp = CCSprite::spriteWithFile("cg_button_2.png"); selectedSp = CCSprite::spriteWithFile("cg_button_2.png"); if(!m_compGachaInfo->isHide) { targetHead->setOpacity(128); } } CCMenuItem *item = CCMenuItemImage::itemFromNormalSprite(normalSp, selectedSp, this, menu_selector(CompGachaBtn::menuCallback)); item->setAnchorPoint(CCPoint(0, 0)); CCMenu *menu = CCMenu::menuWithItem(item); menu->setPosition(ccp(targetHead->getPosition().x-70,targetHead->getPosition().y-145)); addChild(menu); }
void GameMain::createHelp() { auto layer=LayerColor::create(Color4B::BLACK); auto winSize=Director::getInstance()->getWinSize(); Vector<Sprite*> helps; Vector<Sprite*> buttons; for(int i=1;i<=4;i++){ //ヘルプ作成 auto help=Sprite::create(StringUtils::format("help%d.png",i)); help->setPosition(winSize/2); help->setVisible(false); layer->addChild(help); helps.pushBack(help); //ヘルプ選択ボタン作成 auto button=Sprite::create("button_help_select_off.png"); auto onButton=Sprite::create("button_help_select_on.png"); onButton->setAnchorPoint(Vec2::ANCHOR_BOTTOM_LEFT); onButton->setPosition(Vec2::ZERO); onButton->setVisible(false); button->addChild(onButton); button->setPosition(HELP_SELECT+HELP_SELECT_DIFF*(i-1)); layer->addChild(button); buttons.pushBack(button); } helps.front()->setVisible(true); buttons.front()->getChildren().front()->setVisible(true); auto listener=EventListenerTouchOneByOne::create(); listener->onTouchBegan=[](Touch* touch,Event* event){return true;}; listener->onTouchEnded=[helps,buttons](Touch* touch,Event* event){ auto position=touch->getLocation(); for(int i=0;i<4;i++){ auto button=buttons.at(i); //どのボタンがタッチされたか調べる if(button->getBoundingBox().containsPoint(position)){ //タッチされたボタンに対応するヘルプを表示 helps.at(i)->setVisible(true); button->getChildren().front()->setVisible(true); //他のヘルプは消す for(int j=0;j<4;j++){ if(j==i){continue;}//表示するヘルプは飛ばす helps.at(j)->setVisible(false); buttons.at(j)->getChildren().front()->setVisible(false); } break; } } }; listener->setSwallowTouches(true); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,layer); auto close=MenuItemImage::create("button_close_off.png" ,"button_close_on.png" ,[layer](Ref* pButton){ layer->removeFromParent(); }); close->setPosition(Vec2(320,1200)); auto menu=Menu::create(close,NULL); menu->setPosition(Vec2::ZERO); layer->addChild(menu); this->addChild(layer,convertLayerZPositionIntoInt(LayerZPosition::HELP)); }
Scene* SplashScene::createScene() { auto scene = Scene::create(); auto layer = SplashScene::create(); scene->addChild(layer); return scene; }
Widget* CScrollList::AddItem(const char* strCaption, long long nUserData) { Widget *pBox = NULL; pBox = gCtrlAllocator->LoadCtrl(m_nItemBGID); if (!pBox) return NULL; pBox->setSize(Size(_size.width, pBox->getSize().height)); if (m_bItemSelectable) { ((CheckBox*)pBox)->addEventListenerCheckBox(this, SEL_SelectedStateEvent(&CScrollList::ClickButton)); } else { ((Button*)pBox)->addTouchEventListener(this, SEL_TouchEvent(&CScrollList::ClickButton)); } Text *pText = Text::create(); pText->setFontSize(m_nFontSize); pText->setSize(Size(_size.width, pBox->getSize().height)); pText->ignoreContentAdaptWithSize(false); pText->setTag(999); pText->setColor(m_clrTextNormal); pText->setText(strCaption); pText->setTextAreaSize(pText->getSize()); pText->setTextHorizontalAlignment(m_textAlign); pText->setTextVerticalAlignment(TextVAlignment::CENTER); pText->setPosition(Point(getSize().width / 2, pBox->getSize().height / 2)); if (!m_bTextShadow)((Label*)pText->getVirtualRenderer())->disableEffect(); pBox->addChild(pText); pBox->setAnchorPoint(Point(0.0f, 1.0f)); addChild(pBox); // 先将设定新行在组里面的信息 int nGlobalIndex = m_vtrButtons.size(); GroupInfo *pGroup = GetGroup(m_strCurGroup); if (pGroup) { if (pGroup->pStartItem == NULL) { pGroup->pStartItem = pBox; } else { nGlobalIndex = find(m_vtrButtons.begin(), m_vtrButtons.end(), pGroup->pStartItem) - m_vtrButtons.begin() + pGroup->nItemNum; } pGroup->nItemNum++; } // 再根据组的信息插入到该组最后一个位置 //m_vtrButtons.insert(nGlobalIndex, pBox); m_vtrButtons.insert(m_vtrButtons.begin()+nGlobalIndex,pBox); m_vtrUserData.insert(m_vtrUserData.begin() + nGlobalIndex, nUserData); LayOut(); return pBox; }
void PatchMap::initialize( PatchTable const & patchTable ) { int nfaces = 0, narrays = (int)patchTable.GetNumPatchArrays(), npatches = (int)patchTable.GetNumPatchesTotal(); if (not narrays or not npatches) return; // populate subpatch handles vector _handles.resize(npatches); for (int parray=0, current=0; parray<narrays; ++parray) { ConstPatchParamArray params = patchTable.GetPatchParams(parray); int ringsize = patchTable.GetPatchArrayDescriptor(parray).GetNumControlVertices(); for (Index j=0; j < patchTable.GetNumPatches(parray); ++j) { Handle & h = _handles[current]; h.arrayIndex = parray; h.patchIndex = current; h.vertIndex = j * ringsize; nfaces = std::max(nfaces, (int)params[j].faceIndex); ++current; } } ++nfaces; // temporary vector to hold the quadtree while under construction std::vector<QuadNode> quadtree; // reserve memory for the octree nodes (size is a worse-case approximation) quadtree.reserve( nfaces + npatches ); // each coarse face has a root node associated to it that we need to initialize quadtree.resize(nfaces); // populate the quadtree from the FarPatchArrays sub-patches for (Index parray=0, handleIndex=0; parray<narrays; ++parray) { ConstPatchParamArray params = patchTable.GetPatchParams(parray); for (int i=0; i < patchTable.GetNumPatches(parray); ++i, ++handleIndex) { PatchParam::BitField bits = params[i].bitField; unsigned char depth = bits.GetDepth(); QuadNode * node = &quadtree[ params[i].faceIndex ]; if (depth==(bits.NonQuadRoot() ? 1 : 0)) { // special case : regular BSpline face w/ no sub-patches node->SetChild( handleIndex ); continue; } int u = bits.GetU(), v = bits.GetV(), pdepth = bits.NonQuadRoot() ? depth-2 : depth-1, half = 1 << pdepth; for (unsigned char j=0; j<depth; ++j) { int delta = half >> 1; int quadrant = resolveQuadrant(half, u, v); assert(quadrant>=0); half = delta; if (j==pdepth) { // we have reached the depth of the sub-patch : add a leaf assert( not node->children[quadrant].isSet ); node->SetChild(quadrant, handleIndex, true); break; } else { // travel down the child node of the corresponding quadrant if (not node->children[quadrant].isSet) { // create a new branch in the quadrant node = addChild(quadtree, node, quadrant); } else { // travel down an existing branch node = &(quadtree[ node->children[quadrant].idx ]); } } } } } // copy the resulting quadtree to eliminate un-unused vector capacity _quadtree = quadtree; }
void NodeNameTest::test(float dt) { auto parent = Node::create(); // setName(), getName() and getChildByName() char name[20]; for (int i = 0; i < 10; ++i) { sprintf(name, "node%d", i); auto node = Node::create(); node->setName(name); parent->addChild(node); } for (int i = 0; i < 10; ++i) { sprintf(name, "node%d", i); auto node = parent->getChildByName(name); log("find child: %s", node->getName().c_str()); } // enumerateChildren() // name = regular expression int i = 0; parent = Node::create(); for (int i = 0; i < 100; ++i) { auto node = Node::create(); sprintf(name, "node%d", i); node->setName(name); parent->addChild(node); } i = 0; parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 100, ""); i = 0; parent->enumerateChildren("node[[:digit:]]+", [&i](Node* node) -> bool { ++i; return true; }); CCAssert(i == 1, ""); // enumerateChildren // name = node[[digit]]+/node parent = Node::create(); for (int i = 0; i < 100; ++i) { auto node = Node::create(); sprintf(name, "node%d", i); node->setName(name); parent->addChild(node); for (int j = 0; j < 100; ++j) { auto child = Node::create(); child->setName("node"); node->addChild(child); } } i = 0; parent->enumerateChildren("node1/node", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 100, ""); i = 0; parent->enumerateChildren("node1/node", [&i](Node* node) -> bool { ++i; return true; }); CCAssert(i == 1, ""); // search from root parent = Node::create(); for (int i = 0; i < 100; ++i) { auto node = Node::create(); sprintf(name, "node%d", i); node->setName(name); parent->addChild(node); for (int j = 0; j < 100; ++j) { auto child = Node::create(); child->setName("node"); node->addChild(child); } } i = 0; parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 10000, ""); i = 0; parent->enumerateChildren("node[[:digit:]]+/node", [&i](Node* node) -> bool { ++i; return true; }); CCAssert(i == 1, ""); // search from parent // name is xxx/.. i = 0; parent->enumerateChildren("node/..", [&i](Node* node) -> bool { ++i; return true; }); CCAssert(i == 1, ""); i = 0; parent->enumerateChildren("node/..", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 10000, ""); // name = //xxx : search recursively parent = Node::create(); for (int j = 0; j < 100; j++) { auto node = Node::create(); sprintf(name, "node%d", j); node->setName(name); parent->addChild(node); for (int k = 0; k < 100; ++k) { auto child = Node::create(); sprintf(name, "node%d", k); child->setName(name); node->addChild(child); } } i = 0; parent->enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 10100, ""); // 10000(children) + 100(parent) i = 0; parent->enumerateChildren("//node[[:digit:]]+", [&i](Node* node) -> bool { ++i; return true; }); CCAssert(i == 1, ""); i = 0; parent->enumerateChildren("//node[[:digit:]]+/..", [&i](Node* node) -> bool { ++i; return false; }); CCAssert(i == 10000, ""); // utils::findChildren() parent = Node::create(); for (int i = 0; i < 50; ++i) { auto child = Node::create(); child->setName("node"); parent->addChild(child); } auto findChildren = utils::findChildren(*parent, "node"); CCAssert(findChildren.size() == 50, ""); }
long aComboBox::init( FitIniFile* file, const char* blockName ) { file->seekBlock( blockName ); long x, y, width, height; x = y = width = height = 0; file->readIdLong( "XLocation", x ); file->readIdLong( "YLocation", y ); file->readIdLong( "Width", width ); file->readIdLong( "Height", height ); file->seekBlock( "Rects" ); file->readIdLong( "Rectcount", rectCount ); gosASSERT( rectCount > 1 ); { char blockName[64]; if ( rectCount ) { rects = new aRect[rectCount]; for ( int i = 0; i < rectCount; i++ ) { sprintf( blockName, "Rect%ld", i ); rects[i].init( file, blockName ); } } } // editbox rect = first rect // drop list outline = 2nd rect entry.init(file, "EditBox"); expandButton.init(*file, "ExpandButton"); expandButton.setPressFX( LOG_VIDEOBUTTONS ); expandButton.setHighlightFX( LOG_DIGITALHIGHLIGHT ); expandButton.setDisabledFX( LOG_WRONGBUTTON ); listBoxMaxHeight = rects[2].height(); //rects[2].resize(rects[2].width(), entry.height()); listBox.init( rects[2].globalX(), rects[2].globalY(), rects[2].width(), listBoxMaxHeight ); rects[2].showGUIWindow(false); listBox.showGUIWindow(false); if (width < entry.width()) { width = entry.width(); } if (height < entry.height()) { height = entry.height(); } aObject::init(0, 0, width, height); addChild( &listBox ); addChild( &entry ); addChild( &expandButton ); for ( int i = 0; i < rectCount; i++ ) addChild( &rects[i] ); templateItem.init( *file ); expandButton.setMessageOnRelease(); move(x, y); return 0; }
long aDropList::init( FitIniFile* file, const char* blockName ) { file->seekBlock( blockName ); long x, y, width, height; x = y = width = height = 0; file->readIdLong( "XLocation", x ); file->readIdLong( "YLocation", y ); file->readIdLong( "Width", width ); file->readIdLong( "Height", height ); expandButton.init(*file, "ExpandButton"); file->seekBlock( "Rects" ); file->readIdLong( "Rectcount", rectCount ); gosASSERT( rectCount > 1 ); char tmpBlockName[64]; if ( rectCount ) { rects = new aRect[rectCount]; for ( int i = 0; i < rectCount; i++ ) { sprintf( tmpBlockName, "Rect%ld", i ); rects[i].init( file, tmpBlockName ); } } listBoxMaxHeight = rects[2].height(); //rects[2].resize(rects[2].width(), rects[1].height()); listBox.init( rects[2].globalX(), rects[2].globalY(), rects[2].width(), listBoxMaxHeight ); rects[2].showGUIWindow(false); listBox.showGUIWindow(false); if (width < rects[1].width()) { width = rects[1].width(); } if (height < rects[1].height()) { height = rects[1].height(); } aObject::init(0, 0, width, height); textLeft = 0; textTop = 0; if ( NO_ERR == file->seekBlock( "Text0" ) ) { file->readIdLong( "XLocation", textLeft ); file->readIdLong( "YLocation", textTop ); } addChild( &rects[1] ); addChild( &listBox ); addChild( &rects[2] ); addChild( &expandButton ); addChild( &rects[0] ); expandButton.setPressFX( LOG_VIDEOBUTTONS ); expandButton.setHighlightFX( LOG_DIGITALHIGHLIGHT ); expandButton.setDisabledFX( LOG_WRONGBUTTON ); expandButton.setMessageOnRelease(); move(x, y); selectionIndex = -1; templateItem.init( *file ); return 0; }
bool GameMap::initWithLevel( int mainLevel, int viceLevel ) { Return_False_If(!Node::init()); this->makeMap(mainLevel, viceLevel); const int order = m_objects.size()*m_objects[0].size(); const Size size = this->getContentSize(); float x = 0; float up_height = 0; while (x<size.width) { Sprite* sp = Sprite::create("bound_up.png"); sp->setPosition(x, size.height); sp->setAnchorPoint(Point(0,0)); addChild(sp, order); x += sp->getContentSize().width; up_height = sp->getContentSize().height; } x = 0; float bottom_height = 0; while (x<size.width) { Sprite* sp = Sprite::create("bound_bottom.png"); sp->setPosition(x, 0); sp->setAnchorPoint(Point(0,1)); addChild(sp, order+1); x += sp->getContentSize().width; bottom_height = sp->getContentSize().height; } float y = -bottom_height; float left_width = 0; while (y<size.height) { Sprite* sp = Sprite::create("bound_left.png"); sp->setPosition(0, y); sp->setAnchorPoint(Point(1,0)); addChild(sp, order); left_width = sp->getContentSize().width; sp = Sprite::create("bound_left.png"); sp->setAnchorPoint(Point(0,0)); sp->setRotation(180); sp->setPosition(size.width+left_width, y+sp->getContentSize().height); addChild(sp, order); y += sp->getContentSize().height; } //init display number for (int r=0; r<m_objects.size(); ++r) { for (int c=0; c<m_objects[r].size(); ++c) { int mine_count = 0; for (auto&x : getSurrounding(Index2(r,c))) { if (m_objects[x.first][x.second]->isMine()) { ++mine_count; } } m_objects[ r ][ c ]->setSurroundMineCount(mine_count); } } CCAssert(NULL!=m_pPlayer, ""); dig(pointToIndex2(m_pPlayer->getPosition())); // Size size = this->getContentSize(); // -m_border.width, -m_border.height, size.width+m_border.width*2, size.height+m_border.height*2 const float tool = toolbar->getContentSize().height*4/5; this->runAction( Follow::create(m_pPlayer, Rect(-left_width, -bottom_height-tool, size.width+left_width*2, size.height+up_height+bottom_height+tool))); return true; }
//////////////////////////////////////////////////////// // // SpriteMainScene // //////////////////////////////////////////////////////// void SpriteMainScene::initWithSubTest(int asubtest, int nNodes) { //srandom(0); subtestNumber = asubtest; m_pSubTest = new SubTest; m_pSubTest->initWithSubTest(asubtest, this); CCSize s = CCDirector::sharedDirector()->getWinSize(); lastRenderedCount = 0; quantityNodes = 0; CCMenuItemFont::setFontSize(65); CCMenuItemFont *decrease = CCMenuItemFont::itemFromString(" - ", this, menu_selector(SpriteMainScene::onDecrease)); decrease->setColor(ccc3(0,200,20)); CCMenuItemFont *increase = CCMenuItemFont::itemFromString(" + ", this, menu_selector(SpriteMainScene::onIncrease)); increase->setColor(ccc3(0,200,20)); CCMenu *menu = CCMenu::menuWithItems(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(ccp(s.width/2, s.height-65)); addChild(menu, 1); CCLabelTTF *infoLabel = CCLabelTTF::labelWithString("0 nodes", "Marker Felt", 30); infoLabel->setColor(ccc3(0,200,20)); infoLabel->setPosition(ccp(s.width/2, s.height-90)); addChild(infoLabel, 1, kTagInfoLayer); // add menu SpriteMenuLayer* pMenu = new SpriteMenuLayer(true, TEST_COUNT, s_nSpriteCurCase); addChild(pMenu, 1, kTagMenuLayer); pMenu->release(); // Sub Tests CCMenuItemFont::setFontSize(32); CCMenu* pSubMenu = CCMenu::menuWithItems(NULL); for (int i = 1; i <= 9; ++i) { char str[10] = {0}; sprintf(str, "%d ", i); CCMenuItemFont* itemFont = CCMenuItemFont::itemFromString(str, this, menu_selector(SpriteMainScene::testNCallback)); itemFont->setTag(i); pSubMenu->addChild(itemFont, 10); if( i<= 3) itemFont->setColor(ccc3(200,20,20)); else if(i <= 6) itemFont->setColor(ccc3(0,200,20)); else itemFont->setColor(ccc3(0,20,200)); } pSubMenu->alignItemsHorizontally(); pSubMenu->setPosition(ccp(s.width/2, 80)); addChild(pSubMenu, 2); // add title label CCLabelTTF *label = CCLabelTTF::labelWithString(title().c_str(), "Arial", 40); addChild(label, 1); label->setPosition(ccp(s.width/2, s.height-32)); label->setColor(ccc3(255,255,40)); while(quantityNodes < nNodes) onIncrease(this); }
void CScrollList::LayOut() { int nItemHeight = (m_vtrButtons.size() ? m_vtrButtons.back()->getSize().height : 0); int nTitleHeight = (m_vtrGroupInfo.size() ? m_vtrGroupInfo.back().pGroupTitle->getSize().height : 0); float minHeight = 0; for (size_t i = 0; i < m_vtrGroupInfo.size(); i++) { if (m_vtrGroupInfo[i].bSpread && m_vtrGroupInfo[i].nItemNum) minHeight += (m_vtrGroupInfo[i].nItemNum * nItemHeight + (m_vtrGroupInfo[i].nItemNum - 1) * m_nRowInterval); minHeight += (nTitleHeight + m_nRowInterval); } if (minHeight == 0) { minHeight = m_vtrButtons.size() * nItemHeight + (nItemHeight ? (m_vtrButtons.size() - 1) * m_nRowInterval : 0); } float fRealHeight = MAX(minHeight, getContentSize().height); int nCurPlaceY = fRealHeight; // 计算全体成员的位置 vector<GroupInfo> vtrGroupTemp = m_vtrGroupInfo; int nGroupIndex = -1; for (ssize_t i = 0; i < m_vtrButtons.size(); i++) { bool bSpreadItem = true; for (size_t j = 0; j < vtrGroupTemp.size(); j++) { if (vtrGroupTemp[j].pStartItem == m_vtrButtons.at(i)) { // 排版没有列表项目的组标题栏 for (size_t k = 1; k <= j - nGroupIndex; k++) { vtrGroupTemp[nGroupIndex + k].pGroupTitle->setPosition(Point(_size.width / 2, nCurPlaceY)); nCurPlaceY -= (vtrGroupTemp[nGroupIndex + k].pGroupTitle->getSize().height + m_nRowInterval); } nGroupIndex = j; if (!vtrGroupTemp[j].bSpread) { // 隐藏折叠的项 for (ssize_t k = 0; k < vtrGroupTemp[j].nItemNum; k++) { m_vtrButtons.at(i + k)->removeFromParentAndCleanup(false); } i += (vtrGroupTemp[j].nItemNum - 1); bSpreadItem = false; } else if (vtrGroupTemp[j].nItemNum && vtrGroupTemp[j].pStartItem->getParent() == NULL) { // 显示之前折叠的项 for (ssize_t k = 0; k < vtrGroupTemp[j].nItemNum; k++) { addChild(m_vtrButtons.at(i + k)); } } break; //vtrGroupTemp.erase(vtrGroupTemp.begin() + j); } } if (bSpreadItem) { m_vtrButtons.at(i)->setPosition(Point(0, nCurPlaceY)); nCurPlaceY -= (nItemHeight + m_nRowInterval); } } // 排版剩下的没有列表项目的组标题栏 for (size_t k = nGroupIndex + 1; k < vtrGroupTemp.size(); k++) { vtrGroupTemp[k].pGroupTitle->setPosition(Point(_size.width / 2, nCurPlaceY)); nCurPlaceY -= (vtrGroupTemp[k].pGroupTitle->getSize().height + m_nRowInterval); } setInnerContainerSize(Size(getContentSize().width, fRealHeight)); }
CompGachaBtn::CompGachaBtn(CompGachaInfo *info,CCObject* target, SEL_CallFuncO selector) { isExchangeAble = true; m_compGachaInfo = info; m_pListener = target; m_pfnSelector = selector; int lines ; if(info->material->count()%3 ==0) lines=info->material->count()/3; else lines = info->material->count()/3+1; int scaleY = CELLHEIGHT*lines; if(lines == 1)//如果只有一行,给以按钮空间 { scaleY += EXCHANGEBTNHEIGHT; } cardLines = lines; btnBgTop = CCSprite::spriteWithFile("cg_panel_1.png"); CCPoint point = btnBgTop->getPosition(); this->addChild(btnBgTop); btnBgMiddle = CCSprite::spriteWithFile("cg_panel_2.png"); btnBgMiddle->setScaleY(scaleY); point.y-=btnBgTop->getContentSize().height/2+btnBgMiddle->getContentSize().height/2*scaleY; btnBgMiddle->setPosition(point); this->addChild(btnBgMiddle); btnBgBottom = CCSprite::spriteWithFile("cg_panel_3.png"); point.y-=btnBgMiddle->getContentSize().height/2*scaleY+btnBgBottom->getContentSize().height/2; btnBgBottom->setPosition(point); this->addChild(btnBgBottom); char buf[100]; long long time = m_compGachaInfo->rest_exchange_time; if(time>24*60*60) sprintf(buf,CGameData::Inst()->getLanguageValue("compGachaTip1"),time/(24*60*60)); if(time>60*60&&time<24*60*60) sprintf(buf, CGameData::Inst()->getLanguageValue("compGachaTip2"),time/(60*60)); if(time>60&&time<60*60) sprintf(buf, CGameData::Inst()->getLanguageValue("compGachaTip3"),time/60); exchangeCountDown = TextNode::textWithString(buf, 20); addChild(exchangeCountDown); exchangeCountDown->setColor(ccc3(255, 227, 70)); exchangeCountDown->setPosition(ccp(-100, 0)); //exchangeCountDown->setColor() sprintf(buf, CGameData::Inst()->getLanguageValue("compGachaTip4"),info->claimTimes); if(info->claimTimes == -1) { sprintf(buf,"%s",CGameData::Inst()->getLanguageValue("compGachaTip5")); } exchangeTimes = TextNode::textWithString(buf, 20); addChild(exchangeTimes); exchangeTimes->setColor(ccc3(255, 227, 70)); exchangeTimes->setPosition(ccp(155, 0)); addHead(); }
bool ModeSelectScene::init() { ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label //load backgroud auto background = Sprite::create("mode/mode.png"); background->setPosition(visibleSize.width / 2, visibleSize.height / 2); background->setScale(1); addChild(background, 10); //add button //add a menu // MenuItemFont::setFontName("fonts/Marker Felt.ttf"); // auto item1 = MenuItemFont::create("START", CC_CALLBACK_1(WelcomeScene::menuCallback, this)); // // auto menu = Menu::create(item1, nullptr); // menu->alignItemsVertically(); // // addChild(menu, 9); // menu->setPosition(Vec2(visibleSize.width / 2, visibleSize.height* 0.22)); auto item1 = MenuItemImage::create("mode/mode_practice.png", "mode/mode_practice_sel.png", [&](Ref *sender) { XMLParseUtil::ParseLevel("practice/practice4/practice4.xml"); Director::getInstance()->replaceScene(PracticeGameScene::createScene()); }); auto item2 = MenuItemImage::create("mode/mode_drum.png", "mode/mode_drum_sel.png", [&](Ref *sender) { Director::getInstance()->replaceScene(BandSelectScene::createScene()); }); item1->setPosition(550, 540); item2->setPosition(1300, 540); auto menu = Menu::create(item1, item2, nullptr); menu->setPosition(Vec2::ZERO); addChild(menu, 10); //label auto practice_label = Sprite::create("mode/practice_label.png"); practice_label->setPosition(500, 250); addChild(practice_label, 10); auto band_label = Sprite::create("mode/band_label.png"); band_label->setPosition(1300, 250); addChild(band_label, 10); // particle test //auto _emitter = CommonUtil::createParticle(); //addChild(_emitter, 10); //key board test auto listener = EventListenerKeyboard::create(); listener->onKeyPressed = [](EventKeyboard::KeyCode keyCode, Event* event) { char buf[100] = { 0 }; //log("Key %d was pressed!", (int)keyCode); }; listener->onKeyReleased = [](EventKeyboard::KeyCode keyCode, Event* event) { char buf[100] = { 0 }; //log("Key %d was released!", (int)keyCode); if (keyCode == EventKeyboard::KeyCode::KEY_BACK) { Director::getInstance()->end(); } }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); return true; }
void GameMain::createMenu() { Director::getInstance()->pause(); auto winSize=Director::getInstance()->getWinSize(); auto layer=Layer::create(); //プラットフォームがウィンドウズ系の場合は終了ボタンを設置しない #if !(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) auto sprite=Sprite::create("menuBoard_end.png"); #else auto sprite=Sprite::create("menuBoard.png"); #endif sprite->setPosition(winSize/2); layer->addChild(sprite); auto highScore=UserDefault::getInstance()->getIntegerForKey(HIGHSCORE_KEY,0); auto label=Label::createWithSystemFont(StringUtils::format("%d",highScore),"Marker Felt",48); label->setAnchorPoint(Vec2::ANCHOR_MIDDLE_RIGHT); label->setPosition(Vec2(650,1100)); layer->addChild(label); auto button=MenuItemImage::create("menu_open.png","menu_open.png",[layer](Ref* pButton){ layer->removeFromParent(); Director::getInstance()->resume(); }); button->setAnchorPoint(Vec2::ANCHOR_TOP_RIGHT); button->setPosition(Vec2(winSize.width-1,winSize.height-1)); //やり直し カードを初期配置に戻す auto resetButton=MenuItemImage::create("button_off.png" ,"button_on.png" ,[this](Ref* pButton){ this->resetGame(); }); resetButton->setPosition(Vec2(290,700)); //再配布 カードを配りなおす auto restartButton=MenuItemImage::create("button_off.png" ,"button_on.png" ,[this](Ref* pButton){ this->createCards(); this->resetGame(); }); restartButton->setPosition(Vec2(290,570)); //helpボタン auto helpButton=MenuItemImage::create("button_help_off.png" ,"button_help_on.png" ,[this](Ref* pButton){ this->createHelp(); }); helpButton->setPosition(Vec2(320,1200)); #if !(CC_TARGET_PLATFORM == CC_PLATFORM_WP8) || (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) //アプリ終了ボタン auto apEndButton=MenuItemImage::create("button_off.png", "button_on.png" ,[this](Ref* pButton){ this->unscheduleUpdate(); this->unschedule(DRAG_SCHEDULE); Director::getInstance()->getActionManager()->pauseAllRunningActions(); Director::getInstance()->getActionManager()->removeAllActions(); Director::getInstance()->end(); if(CC_TARGET_PLATFORM==CC_PLATFORM_IOS){ exit(0); } }); apEndButton->setPosition(Vec2(350,320)); auto menu=Menu::create(button,resetButton,restartButton,helpButton,apEndButton,NULL); #else auto menu=Menu::create(button,resetButton,restartButton,helpButton,NULL); #endif menu->setPosition(Vec2::ZERO); layer->addChild(menu); //山札からカードを引く枚数 auto oneButtonOff=Sprite::create("button_off.png"); oneButtonOff->setPosition(Vec2(290,850)); layer->addChild(oneButtonOff); auto oneButton=Sprite::create("button_on.png"); oneButton->setPosition(oneButtonOff->getPosition()); layer->addChild(oneButton); auto threeButtonOff=Sprite::create("button_off.png"); threeButtonOff->setPosition(Vec2(460,850)); layer->addChild(threeButtonOff); auto threeButton=Sprite::create("button_on.png"); threeButton->setPosition(threeButtonOff->getPosition()); layer->addChild(threeButton); if(_talonLayer->getPullCount()==1){//カードが1枚の場合onebuttonを点灯 threeButton->setVisible(false); }else{ oneButton->setVisible(false); } auto listener=EventListenerTouchOneByOne::create(); listener->onTouchBegan=[](Touch* touch,Event* event){return true;}; listener->onTouchEnded=[this,oneButton,threeButton](Touch* touch,Event* event){ auto position=touch->getLocation(); if(oneButton->getBoundingBox().containsPoint(position)){//onebuttonがタッチされた if(!oneButton->isVisible()){//onebuttonが点灯状態ではない UserDefault::getInstance()->setIntegerForKey(PULLCOUNT_KEY,1); oneButton->setVisible(true); threeButton->setVisible(false); this->resetGame(); } }else if(threeButton->getBoundingBox().containsPoint(position)){ if(!threeButton->isVisible()){ UserDefault::getInstance()->setIntegerForKey(PULLCOUNT_KEY,3); oneButton->setVisible(false); threeButton->setVisible(true); this->resetGame(); } } }; listener->setSwallowTouches(true); Director::getInstance()->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener,layer); this->addChild(layer,convertLayerZPositionIntoInt(LayerZPosition::MENU)); }
void ListView::pushBackCustomItem(Widget* item) { remedyLayoutParameter(item); addChild(item); requestDoLayout(); }
ActivePilotListItem::ActivePilotListItem( LogisticsPilot* pPilot ) { char tmpText[256]; char realText[256]; memset( medalIcons, 0, MAX_MEDAL * sizeof (aObject*) ); memset( medalTexts, 0, MAX_MEDAL * sizeof(aText*) ); promotionShown = 0; showingPromotion = 0; currentTime = 0; const bool* pMedals = pPilot->getNewMedalArray(); medalCount = 0; int offset = 0; int killCount = pPilot->killedIcons.Count(); if ( killCount > 32 ) offset = (killCount - 32)/8 + 1; offset *= s_killIconRect->height(); for( int i = 0; i < MAX_MEDAL; i++ ) { if ( pMedals[i] ) { medalIcons[medalCount] = new aObject; medalTexts[medalCount] = new aText; *medalIcons[medalCount] = *s_medals[i]; *medalTexts[medalCount] = *s_medalText; medalIcons[medalCount]->move( 0, medalCount* medalIcons[medalCount]->height() + offset ); medalTexts[medalCount]->move( 0, medalCount* medalIcons[medalCount]->height() + offset ); medalTexts[medalCount]->setText( IDS_MEDAL + i ); medalCount++; } } pilot = pPilot; showingPromotion = 0; int top = s_area->top(); killsText = *s_killsText; nameText = *s_nameText; rankText = *s_rankText; missionText = *s_missionText; pilotingText = *s_pilotingText; gunneryText = *s_gunneryText; promotionText = *s_promotionText; sensorText = *s_sensorText; jumpingText = *s_jumpingText; medalAwardedText = *s_medalAwardedText; if ( medalCount ) promotionText.moveTo( promotionText.left(), medalIcons[medalCount-1]->bottom() + 15 ); if ( medalCount > 1 ) medalAwardedText.setText( IDS_ONE_MEDAL_AWARD2 ); else medalAwardedText.setText( IDS_ONE_MEDAL_AWARD ); //Gotta promote the pilot before we decide what rank he/she is! bool pilotPromoted = pilot->promotePilot(); char text[256]; cLoadString( IDS_PILOT_PROMOTED, text, 255 ); char finalText[256]; char tmpRank[64]; //ACE not contiguous with other ranks. Added too late! if (pilot->getRank() != 4) cLoadString( IDS_GREEN + pilot->getRank(), tmpRank, 63 ); else cLoadString( IDS_ACE, tmpRank, 63 ); CharUpper( tmpRank ); sprintf( finalText, text, tmpRank ); promotionText.setText( finalText ); long bottom = promotionText.top() + promotionText.font.height() + 34; if ( !pilotPromoted ) { if ( medalCount ) bottom = medalIcons[medalCount-1]->bottom() + 34; else bottom = promotionText.top() + 34; } aObject::init( 30, top, s_area->width(), bottom ); int missions = pPilot->getNumberMissions(); cLoadString( IDS_PILOT_MISSIONS, tmpText, 255 ); sprintf( realText, tmpText, missions ); missionText.setText( realText); cLoadString( IDS_KILLS_NO_COUNT, tmpText, 255 ); killsText.setText( tmpText); const char* name = pPilot->getName(); cLoadString( IDS_PILOT_NAME, tmpText, 255 ); sprintf( realText, tmpText, name ); nameText.setText( realText); long rank = pPilot->getRank(); char rankStr[32]; //ACE not Contiguous with other Ranks. Added too late. if (rank != 4) cLoadString( rank + IDS_GREEN, rankStr, 31 ); else cLoadString( IDS_ACE, rankStr, 31 ); rankText.setText( rankStr); char buffer[32]; sprintf( buffer, "%ld", (long)pPilot->getGunnery() ); gunneryText.setText( buffer ); sprintf( buffer, "%ld", (long)pPilot->getPiloting() ); pilotingText.setText( buffer ); sprintf( buffer, "%ld", (long)pPilot->getSensorSkill() ); sensorText.setText( buffer ); sprintf( buffer, "%ld", (long)pPilot->getJumping() ); jumpingText.setText( buffer ); for ( i = 0; i < 4; i++ ) { icons[i] = *s_icons[i]; addChild( &icons[i] ); attributeMeters[i] = *s_attributeMeters[i]; } attributeMeters[0].setValue( pPilot->getGunnery()/100.f - pPilot->getNewGunnery()/100.f ); attributeMeters[1].setValue( pPilot->getPiloting()/100.f - pPilot->getNewPiloting()/100.f); attributeMeters[0].setAddedValue( pPilot->getNewGunnery()/100.f ); attributeMeters[1].setAddedValue( pPilot->getNewPiloting()/100.f ); attributeMeters[2].setValue( pPilot->getSensorSkill()/100.f - pPilot->getNewSensorSkill()/100.f ); attributeMeters[3].setValue( pPilot->getJumping()/100.f - pPilot->getNewJumping()/100.f); attributeMeters[2].setAddedValue( pPilot->getNewSensorSkill()/100.f ); attributeMeters[3].setAddedValue( pPilot->getNewJumping()/100.f ); //icons[3] = *s_icons[3 + pPilot->getRank()]; icons[4] = *s_icons[4 + pPilot->getRank()]; //magic 12042011 //addChild( &icons[3] ); addChild( &icons[4] ); //magic 12042011 addChild( &killsText ); addChild( &nameText ); addChild( &rankText ); addChild( &missionText ); addChild( &gunneryText ); addChild( &pilotingText ); addChild( &sensorText ); addChild( &jumpingText ); if ( medalCount ) { addChild( &medalAwardedText ); for ( int i = 0; i < medalCount; i++ ) { addChild( medalIcons[i] ); addChild( medalTexts[i] ); } } if ( pPilot->promotePilot() ) { addChild( &promotionText ); } pilotIcon = new PilotIcon( ); pilotIcon->setTextureIndex( pPilot->getPhotoIndex() ); s_itemCount++; showWindow = 0; }
void CustomUIImageView::attach_node(cocos2d::Node* node) { addChild(node); }
WindowManager::WindowManager( osgViewer::View* view, point_type width, point_type height, unsigned int nodeMask, unsigned int flags ): _width (width), _height (height), _windowWidth (width), _windowHeight (height), _flags (flags), _nodeMask (nodeMask), _view (view), _lastX (0.0f), _lastY (0.0f), _lastEvent (0), _lastPush (0), _lastVertical (PD_NONE), _lastHorizontal (PD_NONE), _focusMode (PFM_FOCUS), _leftDown (false), _middleDown (false), _rightDown (false), _scrolling (osgGA::GUIEventAdapter::SCROLL_NONE), _styleManager (new StyleManager()) { _name = generateRandomName("WindowManager"); if(_flags & WM_USE_LUA) { _lua = new LuaEngine(this); if(!_lua->initialize()) warn() << "Error creating LuaEngine." << std::endl; } if(_flags & WM_USE_PYTHON) { _python = new PythonEngine(this); if(!_python->initialize()) warn() << "Error creating PythonEngine." << std::endl; } if(_flags & WM_USE_RENDERBINS) getOrCreateStateSet()->setMode(GL_DEPTH_TEST, false); // Setup our picking debug (is debug the right word here?) Window... if(_flags & WM_PICK_DEBUG) { _pickWindow = new Box("PickWindow", Box::VERTICAL); Label* label = new Label("PickLabel"); label->setFontSize(13); label->setFontColor(1.0f, 1.0f, 1.0f, 1.0f); label->setFont("fonts/VeraMono.ttf"); label->setPadding(5.0f); label->setCanFill(true); _pickWindow->getBackground()->setColor(0.0f, 0.0f, 0.0f, 0.85f); _pickWindow->addWidget(label); _pickWindow->setNodeMask(~_nodeMask); _pickWindow->removeEventMask(EVENT_MASK_FOCUS); _pickWindow->setStrata(Window::STRATA_FOREGROUND); addChild(_pickWindow.get()); _updatePickWindow(0, 0, 0); } getOrCreateStateSet()->setMode( GL_BLEND, osg::StateAttribute::ON | osg::StateAttribute::OVERRIDE ); getOrCreateStateSet()->setRenderingHint(osg::StateSet::TRANSPARENT_BIN); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !Layer::init() ) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. auto lbl_title = LabelTTF::create("じゃんけんゲーム", "HiraKakuProN-W6", 30); lbl_title->setPosition(Point(origin.x +visibleSize.width/2, origin.y +visibleSize.height - lbl_title->getContentSize().height )); this->addChild(lbl_title); // グーだけの単一スプライトを表示する jangken_aite = Sprite::create("goo.png"); jangken_aite->setPosition(Point(origin.x+visibleSize.width/2, origin.y+visibleSize.height - lbl_title->getContentSize().height - jangken_aite->getContentSize().height -20)); this->addChild(jangken_aite); // アニメーションを生成する auto jangken_anime = Animation::create(); jangken_anime->addSpriteFrameWithFile("choki.png"); jangken_anime->addSpriteFrameWithFile("par.png"); jangken_anime->addSpriteFrameWithFile("goo.png"); jangken_anime->setDelayPerUnit(0.1f); jangken_anime->setLoops(-1); jangken_anime->setRestoreOriginalFrame(true); jangken_anime_run = (CCAnimate*)CCSequence::create( CCAnimate::create(jangken_anime), NULL); // アニメーション実行 jangken_aite->runAction(jangken_anime_run); // じゃんけんボタンを追加 auto btn_goo = MenuItemImage::create("goo.png", "goo.png", CC_CALLBACK_1(HelloWorld::pushGoo, this)); auto btn_choki = MenuItemImage::create("choki.png", "choki.png", CC_CALLBACK_1(HelloWorld::pushChoki, this)); auto btn_par = MenuItemImage::create("par.png", "par.png", CC_CALLBACK_1(HelloWorld::pushPar, this)); btn_goo->setPosition(Point(origin.x + btn_goo->getContentSize().width/2 + 10, origin.y + visibleSize.height/2 - 20)); btn_choki->setPosition(Point(btn_goo->getPosition().x + btn_choki->getContentSize().width + 10, origin.y + visibleSize.height/2 - 20)); btn_par->setPosition(Point(btn_choki->getPosition().x + btn_par->getContentSize().width + 10, origin.y + visibleSize.height/2 - 20)); auto btns = Menu::create(btn_goo, btn_choki, btn_par, NULL); btns->setPosition(Point::ZERO); this->addChild(btns); // 乱数を初期化 srand((unsigned)time(NULL)); lbl_dis = LabelTTF::create("", "HiraKakuProN-W6", 30); lbl_dis->setPosition(Point(origin.x + visibleSize.width/2, origin.y + 200)); addChild(lbl_dis); return true; }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } setTouchEnabled(true); CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize(); CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin(); ///////////////////////////// // 2. add a menu item with "X" image, which is clicked to quit the program // you may modify it. // add a "close" icon to exit the progress. it's an autorelease object CCMenuItemImage *pCloseItem = CCMenuItemImage::create( "CloseNormal.png", "CloseSelected.png", this, menu_selector(HelloWorld::menuCloseCallback)); pCloseItem->setPosition(ccp(origin.x + visibleSize.width - pCloseItem->getContentSize().width/2 , origin.y + pCloseItem->getContentSize().height/2)); // create menu, it's an autorelease object CCMenu* pMenu = CCMenu::create(pCloseItem, NULL); pMenu->setPosition(CCPointZero); this->addChild(pMenu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label m_lbl_CurrentPos = CCLabelTTF::create("轩辕剑--天之痕", "Arial", 36); // position the label on the center of the screen m_lbl_CurrentPos->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height - m_lbl_CurrentPos->getContentSize().height)); // add the label as a child to this layer this->addChild(m_lbl_CurrentPos, 1); m_mapSprite = CCSprite::create("resouces/Map/8-1.png"); m_mapSprite->setAnchorPoint(ccp(0,0)); m_mapSprite->setPosition(ccp(0,(visibleSize.height-m_mapSprite->getContentSize().height) /2)); m_mapSprite->setOpacityModifyRGB(true); m_mapSprite->setOpacity(200); this->addChild(m_mapSprite,0); cache = CCSpriteFrameCache::sharedSpriteFrameCache(); cache->addSpriteFramesWithFile("resouces/role/player.plist"); m_pSprite = CCSprite::createWithSpriteFrameName("walk_0_7.png"); // m_pSprite->setPosition(ccp(m_CurrentPos.x*64+32,(m_CurrentPos.y)*64+m_border)); spriteBatchNode=CCSpriteBatchNode::create("resouces/role/player.png"); spriteBatchNode->addChild(m_pSprite); addChild(spriteBatchNode); PlayerIsIdle = true; initmapdata(); return true; }
//////////////////////////////////////////////////////// // // PerformceAllocScene // //////////////////////////////////////////////////////// void PerformceAllocScene::initWithQuantityOfNodes(unsigned int nNodes) { //kdSrand(time()); auto s = Director::getInstance()->getWinSize(); // Title auto label = LabelTTF::create(title().c_str(), "Arial", 40); addChild(label, 1); label->setPosition(Point(s.width/2, s.height-32)); label->setColor(Color3B(255,255,40)); // Subtitle std::string strSubTitle = subtitle(); if(strSubTitle.length()) { auto l = LabelTTF::create(strSubTitle.c_str(), "Thonburi", 16); addChild(l, 1); l->setPosition(Point(s.width/2, s.height-80)); } lastRenderedCount = 0; currentQuantityOfNodes = 0; quantityOfNodes = nNodes; MenuItemFont::setFontSize(65); auto decrease = MenuItemFont::create(" - ", [&](Object *sender) { quantityOfNodes -= kNodesIncrease; if( quantityOfNodes < 0 ) quantityOfNodes = 0; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); kdSrand(0); }); decrease->setColor(Color3B(0,200,20)); auto increase = MenuItemFont::create(" + ", [&](Object *sender) { quantityOfNodes += kNodesIncrease; if( quantityOfNodes > kMaxNodes ) quantityOfNodes = kMaxNodes; updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); CC_PROFILER_PURGE_ALL(); kdSrand(0); }); increase->setColor(Color3B(0,200,20)); auto menu = Menu::create(decrease, increase, NULL); menu->alignItemsHorizontally(); menu->setPosition(Point(s.width/2, s.height/2+15)); addChild(menu, 1); auto infoLabel = LabelTTF::create("0 nodes", "Marker Felt", 30); infoLabel->setColor(Color3B(0,200,20)); infoLabel->setPosition(Point(s.width/2, s.height/2-15)); addChild(infoLabel, 1, kTagInfoLayer); auto menuLayer = new AllocBasicLayer(true, MAX_LAYER, g_curCase); addChild(menuLayer); menuLayer->release(); updateQuantityLabel(); updateQuantityOfNodes(); updateProfilerName(); kdSrand(0); }
void ClippingNodeTestScene::runThisTest() { auto layer = nextAction(); addChild(layer); Director::getInstance()->replaceScene(this); }
ChipmunkTestLayer::ChipmunkTestLayer() { #if CC_ENABLE_CHIPMUNK_INTEGRATION // enable events auto touchListener = EventListenerTouchAllAtOnce::create(); touchListener->onTouchesEnded = CC_CALLBACK_2(ChipmunkTestLayer::onTouchesEnded, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); Device::setAccelerometerEnabled(true); auto accListener = EventListenerAcceleration::create(CC_CALLBACK_2(ChipmunkTestLayer::onAcceleration, this)); _eventDispatcher->addEventListenerWithSceneGraphPriority(accListener, this); // title auto label = Label::createWithTTF("Multi touch the screen", "fonts/Marker Felt.ttf", 36.0f); label->setPosition(cocos2d::Vec2( VisibleRect::center().x, VisibleRect::top().y - 30)); this->addChild(label, -1); // reset button createResetButton(); // init physics initPhysics(); #if 1 // Use batch node. Faster auto parent = SpriteBatchNode::create("Images/dice_atlas.png", 100); //auto parent = SpriteBatchNode::create("Images/grossini_dance_atlas.png", 100); _spriteTexture = parent->getTexture(); #else // doesn't use batch node. Slower _spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/dice_atlas.png"); //_spriteTexture = Director::getInstance()->getTextureCache()->addImage("Images/grossini_dance_atlas.png"); auto parent = Node::create(); #endif addChild(parent, 0, kTagParentNode); addNewSpriteAtPosition(cocos2d::Vec2(200,200)); // menu for debug layer MenuItemFont::setFontSize(18); auto item = MenuItemFont::create("Toggle debug", CC_CALLBACK_1(ChipmunkTestLayer::toggleDebugCallback, this)); auto menu = Menu::create(item, nullptr); this->addChild(menu); menu->setPosition(cocos2d::Vec2(VisibleRect::right().x-100, VisibleRect::top().y-60)); scheduleUpdate(); #else auto label = Label::createWithTTF("Should define CC_ENABLE_CHIPMUNK_INTEGRATION=1\n to run this test case", "fonts/arial.ttf", 18); auto size = Director::getInstance()->getWinSize(); label->setPosition(Vec2(size.width/2, size.height/2)); addChild(label); #endif }
///all screen move functions should use this void HelloWorld::lookAt(Vec2 pos) { Vec2 visible = Director::getInstance()->getVisibleSize(); this->setPosition(-1*(pos - visible/2)); protractor->setPosition(lookingAt()); notifier->setPosition(lookingAt()); //draw grid Vec2 botleft = screenspaceToWorldspace(Vec2::ZERO); Vec2 topright = screenspaceToWorldspace(visible); Vec2 drawSpaceBotLeft = botleft - GRID_LABEL_SPACING; Vec2 drawSpaceTopRight = topright + GRID_LABEL_SPACING; DrawNode* gridSprite = (DrawNode*)getChildByName("gridSprite"); if (gridSprite) { gridSprite->clear(); std::vector<std::string> toRemove; for (auto child : gridSprite->getChildren()) { if (!onScreen(child->getPosition(), Vec2(GRID_LABEL_SPACING))) toRemove.push_back(child->getName()); } for (auto name : toRemove) { gridSprite->removeChildByName(name); } } else { gridSprite = DrawNode::create(); gridSprite->setName("gridSprite"); addChild(gridSprite, 0); } //vertical lines for (int i= drawSpaceBotLeft.x; i<drawSpaceTopRight.x; i++) { if(i % (int)GRID_SPACING.x) continue; gridSprite->drawSegment(Vec2(i, drawSpaceBotLeft.y), Vec2(i, drawSpaceBotLeft.y+visible.y+2*GRID_LABEL_SPACING.y), GRID_LINE_THICKNESS, Color4F(1,1,1,0.1)); if(!(i % (int)GRID_LABEL_SPACING.x)) { std::string txt = std::to_string(i); auto label = gridSprite->getChildByName("v" + txt); if (!label) { label = Label::createWithTTF(txt, "fonts/arial.ttf", GRID_LABEL_SIZE); label->setName("v" + txt); gridSprite->addChild(label); } label->setPosition(Vec2(i, topright.y - GRID_LABEL_SIZE * 2)); } } //horizontal lines for (int i= drawSpaceBotLeft.y; i<drawSpaceTopRight.y; i++) { if(i % (int)GRID_SPACING.y) continue; gridSprite->drawSegment(Vec2(drawSpaceBotLeft.x, i), Vec2(drawSpaceBotLeft.x+visible.x + 2 * GRID_LABEL_SPACING.x, i), GRID_LINE_THICKNESS, Color4F(1,1,1,0.1)); if(!(i % (int)GRID_LABEL_SPACING.y)) { std::string txt = std::to_string(i); auto label = gridSprite->getChildByName("h" + txt); if (!label) { label = Label::createWithTTF(txt, "fonts/arial.ttf", GRID_LABEL_SIZE); label->setName("h" + txt); gridSprite->addChild(label); } label->setPosition(Vec2(botleft.x + GRID_LABEL_SIZE * 2, i)); } } repaintCursor(); Commorose* c = (Commorose*)commorose; c->setPosition(screenspaceToWorldspace(c->getPositionOnScreen())); }
bool RewardGoodsNode::initWithKey( RewardGoodsKey key ) { if ( 0 == _nodeTag) setTag( -1 ); _goodeskey = key; switch ( key ) { case RewardKey_1: { int randCardIndex = random(1,9); if ( 0 != _nodeTag) randCardIndex = _nodeTag; setTag( randCardIndex ); std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString(); auto goods = Sprite::create( cardFilePath ); goods->setAnchorPoint( Vec2(0.5, 0.5) ); goods->setScale( 0.40f ); goods->setPosition( Vec2(0, 25 )); goods->setName( "goods" ); goods->setCascadeOpacityEnabled(true); addChild(goods); auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) ); goodsK->setScale( 1.7f); goodsK->setPosition(goods->getContentSize() / 2); goodsK->setCascadeOpacityEnabled(true); goods->addChild(goodsK); for ( int i = 0; i<4; i++ ) { auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" ); goodsStar->setPosition( Vec2( 309 - i*50, 408) ); goodsStar->setCascadeOpacityEnabled(true); goods->addChild(goodsStar); } } break; case RewardKey_2: { int randCardIndex = random(1,9); if ( 0 != _nodeTag) randCardIndex = _nodeTag; setTag( randCardIndex ); std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString(); auto goods = Sprite::create( cardFilePath ); goods->setAnchorPoint( Vec2(0.5, 0.5) ); goods->setScale( 0.40f ); goods->setPosition( Vec2(0, 25 )); goods->setName( "goods" ); goods->setCascadeOpacityEnabled(true); addChild(goods); auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) ); goodsK->setScale( 1.7f); goodsK->setPosition( goods->getContentSize()/2 ); goodsK->setCascadeOpacityEnabled(true); goods->addChild(goodsK); for ( int i = 0; i<3; i++ ) { auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" ); goodsStar->setPosition( Vec2( 309 - i*50, 408) ); goodsStar->setCascadeOpacityEnabled(true); goods->addChild(goodsStar); } } break; case RewardKey_3: case RewardKey_24: { auto goods = Sprite::create( "ccsRes/roleOptionLayer/juese5.png" ); goods->setName( "goods" ); goods->setPosition( Vec2(0, 10) ); goods->setScale( 1.3f ); addChild( goods ); } break; case RewardKey_4: case RewardKey_5: case RewardKey_14: case RewardKey_21: case RewardKey_22: case RewardKey_23: { auto goods = Sprite::create( "ccsRes/ShopLayer/goumai10.png" ); goods->setPosition( Vec2(0, 5) ); goods->setName( "goods" ); addChild( goods ); } break; case RewardKey_6: { auto goods = Sprite::create( "ccsRes/ShopLayer/goumai21.png" ); goods->setPosition( Vec2(0, 15) ); goods->setName( "goods" ); addChild( goods ); } break; case RewardKey_7: case RewardKey_15: { int randCardIndex = random(1,9); if ( 0 != _nodeTag) randCardIndex = _nodeTag; setTag( randCardIndex ); std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString(); auto goods = Sprite::create( cardFilePath ); goods->setAnchorPoint( Vec2(0.5, 0.5) ); goods->setScale( 0.40f ); goods->setPosition( Vec2(0, 25 )); goods->setName( "goods" ); goods->setCascadeOpacityEnabled(true); addChild(goods); auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) ); goodsK->setScale( 1.7f); goodsK->setPosition( goods->getContentSize()/2 ); goodsK->setCascadeOpacityEnabled(true); goods->addChild(goodsK); for ( int i = 0; i<1; i++ ) { auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" ); goodsStar->setPosition( Vec2( 309 - i*50, 408) ); goodsStar->setCascadeOpacityEnabled(true); goods->addChild(goodsStar); } } break; case RewardKey_8: case RewardKey_19: case RewardKey_20: { int randCardIndex = random(1,9); if ( 0 != _nodeTag) randCardIndex = _nodeTag; setTag( randCardIndex ); std::string cardFilePath = __String::createWithFormat("%s%d.png", Img_Card_FilePath, randCardIndex )->getCString(); auto goods = Sprite::create( cardFilePath ); goods->setAnchorPoint( Vec2(0.5, 0.5) ); goods->setScale( 0.40f ); goods->setPosition( Vec2(0, 25 )); goods->setName( "goods" ); goods->setCascadeOpacityEnabled(true); addChild(goods); auto goodsK = Sprite::create( StringUtils::format("ccsRes/cardOptionLayer/CardFrame%d.png", (randCardIndex-1)/3+1) ); goodsK->setScale( 1.7f); goodsK->setPosition( goods->getContentSize()/2 ); goodsK->setCascadeOpacityEnabled(true); goods->addChild(goodsK); for ( int i = 0; i<2; i++ ) { auto goodsStar = Sprite::create( "ccsRes/CompoundCardLayer/hecheng14.png" ); goodsStar->setPosition( Vec2( 309 - i*50, 408) ); goodsStar->setCascadeOpacityEnabled(true); goods->addChild(goodsStar); } } break; case RewardKey_9: { auto goods = Sprite::create( "ccsRes/roleOptionLayer/juese3.png" ); goods->setPosition( Vec2(0, 10) ); goods->setName( "goods" ); goods->setScale( 1.3f ); addChild( goods ); } break; case RewardKey_10: case RewardKey_16: case RewardKey_17: case RewardKey_18: { auto goods = Sprite::create( "ccsRes/roleOptionLayer/juese4.png" ); goods->setPosition( Vec2(0, 10) ); goods->setScale( 1.3f ); goods->setName( "goods" ); addChild( goods ); } break; case RewardKey_11: { auto goods = Sprite::create( "ccsRes/WujinModeLayer/goodschongci.png" ); goods->setPosition( Vec2(0, 25) ); goods->setName( "goods" ); addChild( goods ); } break; case RewardKey_12: { auto goods = Sprite::create( "ccsRes/WujinModeLayer/goodsHudun.png" ); goods->setPosition( Vec2(0, 25) ); goods->setName( "goods" ); addChild( goods ); } break; case RewardKey_13: { auto goods = Sprite::create( "ccsRes/WujinModeLayer/dazhao.png" ); goods->setPosition( Vec2(0, 25) ); goods->setName( "goods" ); addChild( goods ); } break; default: break; } _nodeTag = getTag(); // 数量 // auto goodsNum = TextAtlas::create( __String::createWithFormat(".%d", NewDataMgr::getInstance()->getRewardGoodsListWithKey( key )->GoodsNum )->getCString(), // "ccsRes/AtlasLabel/jiesuan22.png", 20,28, "."); // goodsNum->setPosition(Vec2(0, -60)); // addChild( goodsNum ); return true; }