ShadeSprite* ShadeSprite::create(Sprite* srcS,Sprite* maskS, shde_action_type type) { auto sha = new ShadeSprite(); sha->autorelease(); sha->curentType = type; sha->initSprite(srcS, maskS); return sha; }
void CMovement::Init(CXMLParser::TXML* movementData, CCharacter *owner) { _owner = owner; _characterPosition = owner->getPosition(); _position = new Vector2(0,0); _position->setXY(_characterPosition->getX(),_characterPosition->getY()); char *auxTag; for(vu8 i = 0; i < movementData->numChilds; ++i){ auxTag = movementData->childs[i]->tag; if(strcmp(auxTag, "name") == 0){ strcpy(_name, movementData->childs[i]->value); }else if(strcmp(auxTag, "command") == 0){ _command = CInputs::getInstance()->stringToCommand(movementData->childs[i]->value); }else if(strcmp(auxTag, "priority") == 0){ _priority = atoi(movementData->childs[i]->value); }else if(strcmp(auxTag, "sprite") == 0){ initSprite(movementData->childs[i]); }else if(strcmp(auxTag, "totalDuration") == 0){ _totalDuration = atof(movementData->childs[i]->value); }else if(strcmp(auxTag, "loopable") == 0){ _loopeable = strcmp(movementData->childs[i]->value, "true") == 0?true:false; }else if(strcmp(auxTag, "canBeBlocked") == 0){ _canBeBlock = strcmp(movementData->childs[i]->value, "true") == 0?true:false; }else if(strcmp(auxTag, "movementData") == 0){ initFrames(movementData->childs[i]); } // end if } // end for _sprite->setDurationPerFrame(_durationPerFrame); } // Init
bool GameBgLayer::init(){ if (Layer::init()) { initSprite(); return true; } return false; }
bool Hero::init() { if (!Entity::init()) { return false; } setState(NORMAL); //初始化状态 setHP(100); setSP(100); TP = 0; //初始化三大数据 m_mode = SHIELD; //初始化模式状态 velocityY = 0; //初始化水平和竖直方向的速度 faceto = false; inTheAir_flag = true; initSprite(); //初始化动画 initBlock(); //初始化碰撞框 CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/Cloak.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/Clock.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/e.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/ea.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/en.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/haaaaa.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/heng.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/kale.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/maxArmor.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/seiya.ogg"); CocosDenshion::SimpleAudioEngine::sharedEngine()->preloadEffect("Audio/souyuken.ogg"); return true; }
bool Button::init() { initSprite(); enable=true;disaDistr=0; setControllerListener(NULL); return true; }
bool PadControlLayer::init() { if(!Layer::init()) return false; _visibleSize = Director::getInstance()->getVisibleSize(); _origin = Director::getInstance()->getVisibleOrigin(); initSprite(); gameMenu = NesGameMenuLayer::create(); this->addChild(gameMenu,3); gameMenu->setVisible(false); gameMenu->setShow(false); auto touchListener = EventListenerTouchAllAtOnce::create(); touchListener->onTouchesBegan = CC_CALLBACK_2(PadControlLayer::onTouchesBegan, this); touchListener->onTouchesMoved = CC_CALLBACK_2(PadControlLayer::onTouchesMoved, this); touchListener->onTouchesEnded = CC_CALLBACK_2(PadControlLayer::onTouchesEnded, this); touchListener->onTouchesEnded = CC_CALLBACK_2(PadControlLayer::onTouchesCancelled, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(touchListener, this); auto keyListener = EventListenerKeyboard::create(); keyListener->onKeyPressed = CC_CALLBACK_2(PadControlLayer::onKeyPressed, this); keyListener->onKeyReleased = CC_CALLBACK_2(PadControlLayer::onKeyRelease, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(keyListener, this); scheduleUpdate(); return true; }
void VisualMatrix::init() { initSprite(); initEffect(); initMatrix(); initStats(); initState(); }
void RenderComponent::initWith(Json::Value _val) { std::string tstr = _val["Type"].asString(); if (tstr == "Sprite") initSprite( _val); if (tstr == "SpriteSheet") initSpriteSheet( _val); //Other }
Sprite *ComposerEngine::addSprite(uint16 id, uint16 animId, uint16 zorder, const Common::Point &pos) { Sprite sprite; bool foundSprite = false; // re-use old sprite, if any (the BMAP for this id might well have // changed in the meantime, but the scripts depend on that!) for (Common::List<Sprite>::iterator i = _sprites.begin(); i != _sprites.end(); i++) { if (i->_id != id) continue; if (getGameType() == GType_ComposerV1) { if (i->_animId != animId) continue; } else if (i->_animId && animId && (i->_animId != animId)) continue; dirtySprite(*i); // if the zordering is identical, modify it in-place if (i->_zorder == zorder) { i->_animId = animId; i->_pos = pos; dirtySprite(*i); return &(*i); } // otherwise, take a copy and remove it from the list sprite = *i; foundSprite = true; _sprites.erase(i); break; } sprite._animId = animId; sprite._zorder = zorder; sprite._pos = pos; if (!foundSprite) { sprite._id = id; if (!initSprite(sprite)) { debug(1, "ignoring addSprite on invalid sprite %d", id); return NULL; } } dirtySprite(sprite); for (Common::List<Sprite>::iterator i = _sprites.begin(); i != _sprites.end(); i++) { if (sprite._zorder <= i->_zorder) continue; // insert *before* this sprite _sprites.insert(i, sprite); --i; return &(*i); } _sprites.push_back(sprite); return &_sprites.back(); }
ShadeSprite* ShadeSprite::create(string fileName,string maskName, Vec2 srcVec ,Vec2 maskVec,shde_action_type type) { auto sha = new ShadeSprite(); if(sha&&sha->initSprite(fileName, maskName,srcVec,maskVec,type)) { sha->autorelease(); return sha; } return nullptr; }
bool BBWelcomeScene::init() { if ( !Layer::init() ) { return false; } initData(); initSprite(); return true; }
bool BBHandleLayer::init() { if ( !Layer::init() ) { return false; } initData(); initSprite(); return true; }
RasterVsVectorState::RasterVsVectorState() { //Sets up the raster circle (aka the circle with pixels). initSprite(rastercircle, sprites, RectInt(0, 16, 32, 48), 1, VectorFloat(SCREEN.GetWidth()/4, CENTER.y)); //Sets up the vector circle vectorcircle = Shape::Circle(Window.GetWidth()*.75, CENTER.y, 16, Color::Blue); //Sets the title text rastertitle.SetText("Raster Vs. Vector Graphics"); }
Asteroid::Asteroid(int size, b2Vec2 location, b2World* pWorld) :Object(pWorld) { mShouldDeleteBody = true; this->size = static_cast<Size>(size); health = (size + 1) * (size + 1); initPhysics(location); initSprite(); }
void Tile::initSprite(cocos2d::Size spriteSize) { for(int yIdx = 0; yIdx < spriteSize.height; yIdx += GET_DATA_MANAGER()->getTileSize().height) { for(int xIdx = 0; xIdx < spriteSize.width; xIdx += GET_DATA_MANAGER()->getTileSize().width) { auto spriteComp = GET_COMPONENT_MANAGER()->createComponent<SpriteComponent>(); spriteComp->initSprite(m_SpriteType, this, cocos2d::Point(xIdx, yIdx), cocos2d::Point(0,0)); addComponent(spriteComp); spriteComp->enter(); } } }
Asteroid::Asteroid(int size, b2World* pWorld) :Object(pWorld) { mShouldDeleteBody = true; this->size = static_cast<Size>(size); health = (size + 1) * (size + 1); b2Vec2 position; int xRand = rand() % 2, yRand = rand() % 2; xRand == 0 ? position.x = static_cast<float>(rand() % 150 - 300) : position.x = static_cast<float>(SCREEN_WIDTH + (rand() % 150 + 150)); yRand == 0 ? position.y = static_cast<float>(rand() % 150 - 300) : position.y = static_cast<float>(SCREEN_HEIGHT + (rand() % 150 + 150)); initPhysics(position); initSprite(rand() % 3); };
void Asteroid::initAlreadyCreated(int size, b2Vec2 position, b2Vec2 velocity, float rotVel, float angle, int type) { this->size = static_cast<Size>(size); health = (size + 1) * (size + 1); initPhysics(position); body->SetLinearVelocity(velocity); body->SetAngularVelocity(rotVel); body->SetTransform(position, angle); initSprite(type); mShouldDeleteBody = true; }
void Asteroid::init() { mShouldDeleteBody = true; initSize(); b2Vec2 position; //position.x = SCREEN_WIDTH / 2.0f; //position.y = SCREEN_HEIGHT / 2.0f; int xRand = rand() % 2, yRand = rand() % 2; xRand == 0 ? position.x = static_cast<float>(rand() % 150 - 300) : position.x = static_cast<float>(SCREEN_WIDTH + (rand() % 150 + 150)); yRand == 0 ? position.y = static_cast<float>(rand() % 150 - 300) : position.y = static_cast<float>(SCREEN_HEIGHT + (rand() % 150 + 150)); initPhysics(position); initSprite(rand() % 3); }
void Game::loadFont(int num, int h, int w, int spacing, int16_t fontKey) { assert(num < kFontTableSize); Font *ft = &_fontsTable[num]; memset(ft, 0, sizeof(Font)); ft->h = h; ft->w = w; ft->spacing = spacing; int16_t key = fontKey; for (int i = 0; key != 0 && i < kFontGlyphsCount; ++i) { initSprite(kResType_SPR, key, &ft->glyphs[i]); ft->glyphs[i].data = _spriteCache.getData(key, ft->glyphs[i].data); ft->glyphs[i].key = key; _res.unload(kResType_SPR, key); key = _res.getNext(kResType_SPR, key); } }
void ComposerEngine::setBackground(uint16 id) { for (Common::List<Sprite>::iterator i = _sprites.begin(); i != _sprites.end(); i++) { if (i->_id) continue; dirtySprite(*i); i->_surface.free(); i->_id = id; if (!initSprite(*i)) error("failed to set background %d", id); dirtySprite(*i); i->_id = 0; return; } Sprite *background = addSprite(id, 0, 0xffff, Common::Point()); if (background) background->_id = 0; }
DotProductState::DotProductState() { //The Blue Falcon spritesheet is big enough to justify a new image file bfsprites.LoadFromFile("./gfx/bluefalcon.png"); bfsprites.SetSmooth(false); //Puts all the frames into this array. Order's weird due to the ordering of the sprites frames[19] = RectInt( 0, 0, 49, 43); frames[20] = RectInt( 55, 0, 106, 42); frames[21] = RectInt(114, 0, 167, 42); frames[22] = RectInt(175, 0, 229, 42); frames[23] = RectInt(237, 2, 293, 42); frames[24] = RectInt(301, 4, 363, 42); frames[25] = RectInt(371, 4, 435, 42); frames[26] = RectInt(443, 6, 507, 42); frames[27] = RectInt(515, 5, 579, 42); frames[28] = RectInt(587, 1, 649, 42); frames[29] = RectInt(656, 0, 711, 45); frames[30] = RectInt(713, 0, 758, 46); frames[31] = RectInt(766, 0, 806, 46); frames[ 0] = RectInt(814, 0, 852, 46); frames[ 1] = RectInt(860, 0, 900, 46); frames[ 2] = RectInt(903, 0, 948, 46); frames[ 3] = RectInt( 0, 43, 55, 88); frames[ 4] = RectInt( 61, 43, 122, 84); frames[ 5] = RectInt(130, 47, 194, 84); frames[ 6] = RectInt(202, 48, 266, 84); frames[ 7] = RectInt(274, 46, 338, 84); frames[ 8] = RectInt(346, 46, 408, 84); frames[ 9] = RectInt(416, 44, 472, 84); frames[10] = RectInt(480, 42, 534, 84); frames[11] = RectInt(542, 42, 595, 83); frames[12] = RectInt(604, 42, 656, 84); frames[13] = RectInt(665, 45, 713, 88); frames[14] = RectInt(715, 46, 767, 88); frames[15] = RectInt(775, 48, 831, 88); frames[16] = RectInt(839, 50, 897, 87); frames[17] = RectInt(900, 46, 955, 85); frames[18] = RectInt( 0, 88, 50, 129); //Prepares the actual sprite for on-screen display initSprite(bluefalcon, bfsprites, frames[0], BLUE_FALCON_SCALE); setSpriteBuffer(bluefalcon, buffer); //Adjust the collision boundaries based on the BF's frame }
void GuildMemberManager::addMember(int dex) { // json char filename[20] = "Pokemon_"; char num[20]; char extension[20] = ".png"; sprintf(num, "%d", dex); strcat(num, extension); strcat(filename,num); std::string finalname = filename; auto Unit = Member::create(); Unit->initSprite(finalname); Unit->setID(*(pool.newData())); Unit->setDex(dex); MemberLayer->addChild(Unit); MemberList.push_back(Unit); }
Duck::Duck() { frames[DuckFrame::UP_1 ] = RectInt( 0, 197, 29, 229); frames[DuckFrame::UP_2 ] = RectInt( 35, 197, 64, 229); frames[DuckFrame::UP_3 ] = RectInt( 67, 197, 96, 229); frames[DuckFrame::NORM_1 ] = RectInt( 98, 198, 132, 229); frames[DuckFrame::NORM_2 ] = RectInt(136, 199, 170, 230); frames[DuckFrame::NORM_3 ] = RectInt(173, 198, 206, 229); frames[DuckFrame::SHOT ] = RectInt(212, 202, 243, 231); frames[DuckFrame::FALLING] = RectInt(245, 201, 263, 232); sounds[DuckSound::FLAP ].Load("./sfx/duckhunt/flap.wav" ); sounds[DuckSound::QUACK ].Load("./sfx/duckhunt/quack.wav" ); sounds[DuckSound::FALL ].Load("./sfx/duckhunt/fall.wav" ); sounds[DuckSound::HIT_GROUND].Load("./sfx/duckhunt/hitground.wav"); initSprite(sprite, sprites, frames[DuckFrame::NORM_1], DUCK_SCALE); setSpriteBuffer(sprite, buffer); sprite.SetPosition(Random::Random(buffer[LEFT], buffer[RIGHT]), START_HEIGHT); updateShotBox(); velocity = VectorFloat(0, 0); state = DuckState::IDLE; }
void NodeCom::initWithMap(rapidjson::Value& value) { auto visibleSize=Director::getInstance()->getVisibleSize(); node=cocos2d::Node::create(); if (value.HasMember("contentSize")) { auto size=cocos2d::SizeFromString(value["contentSize"].GetString()); if (size.width<0) size.width=visibleSize.width; if (size.height<0) size.height=visibleSize.height; node->setContentSize(size); } else { node->setContentSize(visibleSize); } if (value.HasMember("anchorPoint")) { node->setAnchorPoint(cocos2d::PointFromString(value["anchorPoint"].GetString())); } cocos2d::Point position=value.HasMember("position")?cocos2d::PointFromString(value["position"].GetString()):cocos2d::Point::ZERO; if (value.HasMember("anchor")) { node->setPosition(getRealPosition(cocos2d::Director::getInstance()->getVisibleSize(), position, cocos2d::PointFromString(value["anchor"].GetString()))); } else if (value.HasMember("position")) { node->setPosition(cocos2d::PointFromString(value["position"].GetString())); } if (value.HasMember("Node")) { int count=value["Node"].Size(); for (int i=0; i<count; i++) { rapidjson::Value& nodeValue=value["Node"][i]; if (!nodeValue.IsNull()&&nodeValue.HasMember("type")) { const char* type=nodeValue["type"].GetString(); cocos2d::Node* child=nullptr; if (strcmp("Label", type)==0) { child=initLabel(nodeValue); } else if (strcmp("Sprite", type)==0) { child=initSprite(nodeValue); } else if (strcmp("Layer", type)==0) { child=initLayer(nodeValue); } else if (strcmp("Button", type)==0) { child=initButton(nodeValue); } else if (strcmp("TableView", type)==0){ child=initTable(nodeValue); } else if (strcmp("ProgressTimer", type)==0){ child=initTimer(nodeValue); } if (child!=nullptr) { node->addChild(child); if (nodeValue.HasMember("name")) { const char* name= nodeValue["name"].GetString(); __nodeNames.insert(std::make_pair(name, child)); } if (nodeValue.HasMember("scale")) { cocos2d::Point point=cocos2d::PointFromString(nodeValue["scale"].GetString()); child->setScale(point.x, point.y); } if (nodeValue.HasMember("position")) { child->setPosition(cocos2d::PointFromString(nodeValue["position"].GetString())); } if (nodeValue.HasMember("anchorPoint")) { child->setAnchorPoint(cocos2d::PointFromString(nodeValue["anchorPoint"].GetString())); } if (nodeValue.HasMember("localZOrder")) { child->setLocalZOrder(nodeValue["localZOrder"].GetInt()); } if (nodeValue.HasMember("globalOrder")) { child->setGlobalZOrder(nodeValue["globalOrder"].GetInt()); } if (nodeValue.HasMember("visible")) { child->setVisible(nodeValue["visible"].GetBool()); } if (nodeValue.HasMember("tag")) { child->setTag(nodeValue["tag"].GetInt()); } //如果声明了anchor,则按照新的规则布局 cocos2d::Point position1=nodeValue.HasMember("position")? cocos2d::PointFromString(nodeValue["position"].GetString()):cocos2d::Point::ZERO; if (nodeValue.HasMember("anchor")) { child->setPosition(getRealPosition(node->getContentSize(), position1, cocos2d::PointFromString(nodeValue["anchor"].GetString()))); } else if (nodeValue.HasMember("position")) { child->setPosition(position1); } } } } } }
void HomeScreen::init() { initSprite(); initEffect(); }
int main() { // creates a window and GLES context if (makeContext() != 0) exit(-1); // all the shaders have at least texture unit 0 active so // activate it now and leave it active glActiveTexture(GL_TEXTURE0); flareTex = loadPNG("resources/textures/cloud.png"); width = getDisplayWidth(); height = getDisplayHeight(); glViewport(0, 0, getDisplayWidth(), getDisplayHeight()); // initialises glprint's matrix, shader and texture initGlPrint(getDisplayWidth(), getDisplayHeight()); font1=createFont("resources/textures/font.png",0,256,16,16,16); initSprite(getDisplayWidth(), getDisplayHeight()); fileid = 0; loadfile(); for (int i=0; i<max_flares; i++) { flares[i].x=rand_range(0,getDisplayWidth()); flares[i].y=rand_range(0,getDisplayHeight()); flares[i].vx=rand_range(0,10)-5; flares[i].vy=rand_range(0,10)-5; } /*for (int i=0; i<max_targets; i++) { targets[i].x=rand_range(0,getDisplayWidth()); targets[i].y=rand_range(0,getDisplayHeight()); targets[i].flares = 0; }*/ /*for (int i=0; i<max_flares; i++) { flares[i].x=rand_range(0,getDisplayWidth()); flares[i].y=rand_range(0,getDisplayHeight()); flares[i].vx=rand_range(0,10)-5; flares[i].vy=rand_range(0,10)-5; flares[i].target = (int)rand_range(0,max_targets); targets[flares[i].target].flares ++; }*/ // we don't want to draw the back of triangles // the blending is set up for glprint but disabled // while not in use glCullFace(GL_BACK); glEnable(GL_CULL_FACE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_DEPTH_TEST); glClearColor(0, 0.5, 1, 1); // count each frame int num_frames = 0; // set to true to leave main loop bool quit = false; // get a pointer to the key down array keys = getKeys(); int* mouse = getMouse(); while (!quit) { // the main loop doEvents(); // update mouse and key arrays if (keys[KEY_ESC]) quit = true; // exit if escape key pressed if (keys[KEY_SPACE]) relocate_targets(); // exit if escape key pressed if (keys[KEY_RETURN]) reassign_flares(); // exit if escape key pressed if (keys[KEY_S] && !lastkeys[KEY_S]) save(); // exit if escape key pressed if (keys[KEY_CURSL] && !lastkeys[KEY_CURSL]){ fileid--; if (fileid <0) fileid = 0; loadfile(); // exit if escape key pressed } if (keys[KEY_CURSR] && !lastkeys[KEY_CURSR]){ fileid++; loadfile(); // exit if escape key pressed } if (keys[KEY_C]){ max_targets = 1; // exit if escape key pressed reassign_flares(); } lastkeys[KEY_S] = keys[KEY_S]; lastkeys[KEY_CURSL] = keys[KEY_CURSL]; lastkeys[KEY_CURSR] = keys[KEY_CURSR]; mx = mouse[0]; my = mouse[1]; if(mouse[2] != 0){ spawn_target(mx,my); } for (int i=0; i<RE_MULTIPLY; i++){ random_events(); } think(); render(); // the render loop usleep(1600); // no need to run cpu/gpu full tilt } closeContext(); // tidy up return 0; }
void Background::init() { initSprite(); initEffect(); }