bool ScheduleUpdatePriority::onTouchBegan(Touch* touch, Event* event) { int priority = static_cast<int>(CCRANDOM_0_1() * 11) - 5; // -5 ~ 5 CCLOG("change update priority to %d", priority); scheduleUpdateWithPriority(priority); return true; }
void MapLayer::onEnter() { Node::onEnter(); auto mapSize = MapUtil::getInstance()->getMapSize(); auto scaleFactor = GameManager::getInstance()->getScaleFactor(); auto winSize = Director::getInstance()->getWinSize(); auto isScroll = false; // if(mapSize.width - DESIGN_TILES_HORIZONTAL_NUMS>0) // { _rangeWidth = (mapSize.width-1)*TILE_WIDTH*scaleFactor-winSize.width; isScroll = true; // } // if(mapSize.height - DESIGN_TILES_VERTICAL_NUMS>0) // { _rangeHeight = (mapSize.height-1)*TILE_HEIGHT*scaleFactor-winSize.height; // isScroll = true; // } if(isScroll) { scheduleUpdateWithPriority(1); _originPosition = getPosition(); _offset = Point::ZERO; } }
virtual bool init() { if (!Node::init()) { return false; } _maps[cocos2d::EventKeyboard::KeyCode::KEY_A] = key::codes::a; _maps[cocos2d::EventKeyboard::KeyCode::KEY_S] = key::codes::b; _maps[cocos2d::EventKeyboard::KeyCode::KEY_D] = key::codes::c; _maps[cocos2d::EventKeyboard::KeyCode::KEY_ENTER] = key::codes::start; _maps[cocos2d::EventKeyboard::KeyCode::KEY_UP_ARROW] = key::codes::up; _maps[cocos2d::EventKeyboard::KeyCode::KEY_DOWN_ARROW] = key::codes::down; _maps[cocos2d::EventKeyboard::KeyCode::KEY_LEFT_ARROW] = key::codes::left; _maps[cocos2d::EventKeyboard::KeyCode::KEY_RIGHT_ARROW] = key::codes::right; for (auto mapping : _maps) { _keys[mapping.second] = std::make_shared<key>(); } auto listener = cocos2d::EventListenerKeyboard::create(); listener->onKeyPressed = CC_CALLBACK_2(joypad::onKeyPressed, this); listener->onKeyReleased = CC_CALLBACK_2(joypad::onKeyReleased, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); scheduleUpdateWithPriority(1024); // largest priority possible to ensure it cleans keys in the end return true; }
bool Mage::init() { Actor::init(); _useWeaponId = ReSkin.mage.weapon; _useArmourId = ReSkin.mage.armour; _useHelmetId = ReSkin.mage.helmet; //init data copyData_Mage(); //init bloodbar and avatar if (uiLayer != NULL) { _bloodBar = uiLayer->MageBlood; _bloodBarClone = uiLayer->MageBloodClone; _avatar = uiLayer->MagePng; } //init image init3D(); initActions(); _AIEnabled = true; scheduleUpdateWithPriority(0); auto specialAttack = [&]() { if (_specialAttackChance == 1) return; _specialAttackChance = 1; }; MessageDispatchCenter::getInstance()->registerMessage(MessageType::SPECIAL_MAGE, [](Actor* data) { if (data->getSpecialAttackChance() == 1) return; data->setSpecialAttackChance(1); }); return true; }
//------------------------------------------------------------------ // // TestNode // //------------------------------------------------------------------ void TestNode::initWithString(const std::string& str, int priority) { _string = str; scheduleUpdateWithPriority(priority); }
void Node::scheduleUpdate() { scheduleUpdateWithPriority(0); }
//------------------------------------------------------------------ // // TestNode // //------------------------------------------------------------------ void TestNode::initWithString(CCString* pStr, int priority) { m_pstring = pStr; m_pstring->retain(); scheduleUpdateWithPriority(priority); }