bool VenusScene::init() { ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); loadMap("maps/PantallaMercurio/Venus.tmx", "Objetos", "Rocas2", "Rocas1", "bg1", "bg2", "FondoPrincipal", "Meta"); setEventHandlers(); createCharacter("maps/personajepequeno.png"); //createCharacterAnimation(); tileMap->addChild(playerOne->PlayerSprite, 2); crearParticulaFuego(Point(2200,120)); this->addChild(tileMap, -1, 1); setPointOfView(Point(playerOne->PlayerSprite->getPosition())); printf("x mapPosition %f", tileMap->getPosition().x); printf("x mapPosition %f", tileMap->getPosition().y); auto listener = EventListenerKeyboard::create(); cocos2d::Sprite* ptr = playerOne->PlayerSprite; while (metaCheck(Point(ptr->getPositionX(), ptr->getPositionY()-3)) == "Normal") { ptr->setPosition(Point(ptr->getPositionX() + 0.5, ptr->getPositionY() - 0.5)); ptr->setPosition(Point(ptr->getPositionX(), playerOne->PlayerSprite->getPositionY() - 1.5)); setPointOfView(Point(ptr->getPosition())); } listener->onKeyPressed = CC_CALLBACK_2(VenusScene::keyPressed, this); listener->onKeyReleased = CC_CALLBACK_2(VenusScene::keyReleased, this); this->schedule(schedule_selector(VenusScene::onKeyHold)); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //Carga de las estrellas de puntaje loadStars(); //Etiqueta en pantalla del marcador marcadores(); cargarPropulsores(); cargarNave(); //Método para verificar las distintas colisiones, en este caso, de estrellas para actualizar el puntaje schedule(schedule_selector(VenusScene::updateColision)); return true; }
void ofxTweakbars::init() { visible = true; is_initialized = true; if (!TwInit(TW_OPENGL, NULL)) { throw TwGetLastError(); } TwWindowSize(ofGetWidth(), ofGetHeight()); setEventHandlers(); }
void Optics2::loadGrid() { cleanGrid(); gridX = 9; gridY = 7; cannon = Cannon::createWithSpriteFrame(SpriteFrame::create("optics/cannon.png",Rect(0,0,100,100)),GameObject::LEFT,false); cannon->setEventHandlers(); cannonX = 1; cannonY = 2; grid[1][2]=cannon; grid[3][3]=Goal::createWithSpriteFrame(SpriteFrame::create("optics/goal.png",Rect(0,0,100,100))); auto mirror1 = OneSideMirror::createWithSpriteFrame(SpriteFrame::create("optics/onesidemirror.png",Rect(0,0,100,100)),GameObject::NW,true); mirror1->setEventHandlers(); grid[2][2] = mirror1; mirror1 = OneSideMirror::createWithSpriteFrame(SpriteFrame::create("optics/onesidemirror.png",Rect(0,0,100,100)),GameObject::NW,false); mirror1->setEventHandlers(); grid[5][4] = mirror1; mirror1 = OneSideMirror::createWithSpriteFrame(SpriteFrame::create("optics/onesidemirror.png",Rect(0,0,100,100)),GameObject::NW,true); mirror1->setEventHandlers(); grid[3][5] = mirror1; mirror1 = OneSideMirror::createWithSpriteFrame(SpriteFrame::create("optics/onesidemirror.png",Rect(0,0,100,100)),GameObject::NW,false); mirror1->setEventHandlers(); grid[3][2] = mirror1; auto mirror2 = TwoSideMirror::createWithSpriteFrame(SpriteFrame::create("optics/twosidemirror.png",Rect(0,0,100,100)),GameObject::NW,true); mirror2->setEventHandlers(); grid[2][4]= mirror2; mirror2 = TwoSideMirror::createWithSpriteFrame(SpriteFrame::create("optics/twosidemirror.png",Rect(0,0,100,100)),GameObject::NW,false); mirror2->setEventHandlers(); grid[2][5]= mirror2; mirror2 = TwoSideMirror::createWithSpriteFrame(SpriteFrame::create("optics/twosidemirror.png",Rect(0,0,100,100)),GameObject::NW,true); mirror2->setEventHandlers(); grid[4][4]= mirror2; auto wall = Wall::createWithSpriteFrame(SpriteFrame::create("optics/wall.png",Rect(0,0,100,100))); grid[4][3]= wall; wall = Wall::createWithSpriteFrame(SpriteFrame::create("optics/wall.png",Rect(0,0,100,100))); grid[4][2]= wall; fillBoundingCells(); fillEmptyCells(); }
// on "init" you need to initialize your instance bool ChainReactionScene::init() { // Init parent first if ( !Layer::init() ) return false; Size visibleSize = Director::getInstance()->getVisibleSize(); Point origin = Director::getInstance()->getVisibleOrigin(); // Add a menu item with "X" image, which is clicked to quit the program auto closeItem = MenuItemImage::create("CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(ChainReactionScene::menuCloseCallback, this)); closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2, origin.y + closeItem->getContentSize().height/2)); auto menu = Menu::create(closeItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu, 1); // Create and place the original balls on the scenery loadBalls(); for ( size_t i = 0; i < 13; ++i ) addRandomBall(); // Create and place the label to show the remaining time _remainingTimeLabel = ColorfulLabel::create("CatchMe", "Fonts/NextGames.ttf", 24); _remainingTimeLabel->setPosition(Point(origin.x + visibleSize.width/2, origin.y + visibleSize.height - _remainingTimeLabel->getContentSize().height)); this->addChild(_remainingTimeLabel, 1); // Create and place the label to show the score of current player _currenPlayerScore = Scores::create("0000", "Fonts/NextGames.ttf", 24); _currenPlayerScore->setPosition(Point(origin.x + visibleSize.width - _currenPlayerScore->getContentSize().width, origin.y + visibleSize.height - _currenPlayerScore->getContentSize().height)); addChild(_currenPlayerScore, 1); // Call update methods the schedule( schedule_selector(ChainReactionScene::update) ); schedule( schedule_selector(ChainReactionScene::updateRemainingTime), 1.0f); setEventHandlers(); return true; }
// 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. // add a "close" icon to exit the progress. it's an autorelease object auto closeItem = MenuItemImage::create( "CloseNormal.png", "CloseSelected.png", CC_CALLBACK_1(HelloWorld::menuCloseCallback, this)); closeItem->setPosition(Point(origin.x + visibleSize.width - closeItem->getContentSize().width/2 , origin.y + closeItem->getContentSize().height/2)); // create menu, it's an autorelease object auto menu = Menu::create(closeItem, NULL); menu->setPosition(Point::ZERO); this->addChild(menu, 1); ///////////////////////////// // 3. add your codes below... // add a label shows "Hello World" // create and initialize a label labelGameTitle = ColorfulLabel::create("CatchMe", "Fonts/NextGames.ttf", 72); // position the label on the center of the screen labelGameTitle->setPosition(Point(origin.x + visibleSize.width/2, origin.y + visibleSize.height - labelGameTitle->getContentSize().height)); // add the label as a child to this layer this->addChild(labelGameTitle, 1); #if 0 // add "HelloWorld" splash screen" auto sprite = Sprite::create("HelloWorld.png"); // position the sprite on the center of the screen sprite->setPosition(Point(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y)); // add the sprite as a child to this layer this->addChild(sprite, 0); #endif schedule( schedule_selector(HelloWorld::update) ); animateGameTitle(); setEventHandlers(); showHighScores(); return true; }