bool StoreLayer::init() { if ( !CCLayer::init()) { return false; } createBg(); return true; }
bool Picnic2::init() { if ( !CCLayer::init()) { return false; } this->setTouchEnabled(true); createBg(); createMenu(); return true; }
bool Level19::init() { if ( !CCLayer::init()) { return false; } createBg(); createMenu(); schedule(schedule_selector(Level19::onTimer), 0.1f); return true; }
bool Level15::init() { if ( !CCLayer::init()) { return false; } this->setTouchEnabled(true); createBg(); createMenu(); schedule(schedule_selector(Level15::onTimer)); return true; }
void CWindowObject::setBackground(std::string filename) { OBJ_CONSTRUCTION_CAPTURING_ALL; delete background; background = createBg(filename, options & PLAYER_COLORED); if (background) pos = background->center(Point(pos.w/2 + pos.x, pos.h/2 + pos.y)); updateShadow(); }
std::vector<Sprite*> GameBackgroundLayer::tileBg(std::string res) { auto director = Director::getInstance(); Size winSize = director->getWinSize(); float doubleWinWidth = 2 * winSize.width; std::vector<Sprite*> tiles; float remainWidth = doubleWinWidth; do { Sprite* nearBg = createBg(res, Vec2(doubleWinWidth - remainWidth, 0)); remainWidth -= nearBg->getContentSize().width; tiles.push_back(nearBg); addChild(nearBg); } while (remainWidth > 0); if (tiles.size() < 2) { Sprite* nearBg = createBg(res, Vec2(doubleWinWidth - remainWidth, 0)); tiles.push_back(nearBg); addChild(nearBg); } return tiles; }
bool PlayScene::init() { if ( !CCLayer::init()) { return false; } // this->setTouchEnabled(true); g_lPlayScene = this; createBg(); createMenu(); return true; }
CWindowObject::CWindowObject(int options_, std::string imageName): CIntObject(getUsedEvents(options_), Point()), shadow(nullptr), options(options_), background(createBg(imageName, options & PLAYER_COLORED)) { assert(parent == nullptr); //Safe to remove, but windows should not have parent if (options & RCLICK_POPUP) CCS->curh->hide(); if (background) pos = background->center(); else center(Point(screen->w/2, screen->h/2)); if (!(options & SHADOW_DISABLED)) setShadow(true); }
bool MapView::init() { if (!Layer::init()) { return false; } m_mapW = MAP->mapW(); m_mapH = MAP->mapH(); m_gridW = MAP->gridW(); m_gridH = MAP->gridH(); m_displayW = MAP->displayW(); m_displayH = MAP->displayH(); createBg(); createGrid(); createTerrain(); // 注册点击事件; auto listener = EventListenerTouchAllAtOnce::create(); listener->onTouchesBegan = [=](const std::vector<Touch*> &touches, Event *event) { CCASSERT(!m_draggingTouch, ""); m_draggingTouch = touches[0]; }; listener->onTouchesMoved = [=](const std::vector<Touch*> &touches, Event *event) { CCASSERT(m_draggingTouch, ""); for (const auto &touch : touches) { if (m_draggingTouch == touch) { auto lastPoint = (touch->getPreviousLocation()); auto point = (touch->getLocation()); m_draggingMoveDistance2 += (point - lastPoint).lengthSquared(); if (m_draggingMoveDistance2 > DRAG_MIN_DISTANCE2) { GameLogic::getInstance()->handleDragMap(point - lastPoint); } } } }; listener->onTouchesEnded = [=](const std::vector<Touch*> &touches, Event *event) { CCASSERT(m_draggingTouch, ""); for (const auto &touch : touches) { auto lastPoint = (touch->getPreviousLocation()); auto point = (touch->getLocation()); m_draggingMoveDistance2 += (point - lastPoint).lengthSquared(); if (m_draggingMoveDistance2 < DRAG_MIN_DISTANCE2) { GameLogic::getInstance()->handleTouch(point); } if ( m_draggingTouch == touch ) { m_draggingTouch = nullptr; m_draggingMoveDistance2 = 0.0f; } } }; this->getEventDispatcher()->addEventListenerWithSceneGraphPriority(listener, this); return true; }