void LevelTwo::createRemovablePlats() { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 0; i < 4; i++) { if (i == 0) { TowerBase * removablePlats = TowerBase::create(Vec2(200, 338), m_gameState, 5); m_removablePlats.push_back(removablePlats); spritebatch->addChild(removablePlats, -5); } else if (i == 1) { TowerBase * removablePlats = TowerBase::create(Vec2(245, 338), m_gameState, 5); m_removablePlats.push_back(removablePlats); spritebatch->addChild(removablePlats, -5); } else if (i == 2) { TowerBase * removablePlats = TowerBase::create(Vec2(200, -100), m_gameState, 6); m_removablePlats.push_back(removablePlats); spritebatch->addChild(removablePlats, -5); } else if (i == 3) { TowerBase * removablePlats = TowerBase::create(Vec2(245, -100), m_gameState, 6); m_removablePlats.push_back(removablePlats); spritebatch->addChild(removablePlats, -5); } } this->addChild(spritebatch, 1, END_SPRITE_BATCH); }
void HelloWorld::createMapAndGetTile() { auto mapnotchange = TMXTiledMap::create("orthogonal-test4.tmx"); addChild(mapnotchange, 0, 1); mapnotchange->setPosition(50,240); auto map = TMXTiledMap::create("orthogonal-test4.tmx"); addChild(map, 0, 2); map->setPosition(570,240); SpriteBatchNode* child = nullptr; auto& children = map->getChildren(); for(const auto &node : children) { child = static_cast<SpriteBatchNode*>(node); child->getTexture()->setAntiAliasTexParameters(); } map->setAnchorPoint(Point(0, 0)); auto layer = map->getLayer("Layer 0"); auto s = layer->getLayerSize(); Sprite* sprite; sprite = layer->getTileAt(Point(0,0)); sprite->setScale(2); sprite = layer->getTileAt(Point(s.width-1,0)); sprite->setScale(2); sprite = layer->getTileAt(Point(0,s.height-1)); sprite->setScale(2); sprite = layer->getTileAt(Point(s.width-1,s.height-1)); sprite->setScale(2); }
//------------------------------------------------------------------ // // TMXOrthoTest4 // //------------------------------------------------------------------ TMXOrthoTest4::TMXOrthoTest4() { auto map = TMXTiledMap::create("TileMaps/orthogonal-test4.tmx"); addChild(map, 0, kTagTileMap); Size CC_UNUSED s1 = map->getContentSize(); CCLOG("ContentSize: %f, %f", s1.width,s1.height); SpriteBatchNode* child = nullptr; auto& children = map->getChildren(); for(const auto &node : children) { child = static_cast<SpriteBatchNode*>(node); child->getTexture()->setAntiAliasTexParameters(); } map->setAnchorPoint(Vec2(0, 0)); auto layer = map->getLayer("Layer 0"); auto s = layer->getLayerSize(); Sprite* sprite; sprite = layer->getTileAt(Vec2(0,0)); sprite->setScale(2); sprite = layer->getTileAt(Vec2(s.width-1,0)); sprite->setScale(2); sprite = layer->getTileAt(Vec2(0,s.height-1)); sprite->setScale(2); sprite = layer->getTileAt(Vec2(s.width-1,s.height-1)); sprite->setScale(2); schedule( schedule_selector(TMXOrthoTest4::removeSprite), 2 ); }
// on "init" you need to initialize your instance bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !LayerColor::initWithColor(Color4B(255,255,255,255)) ) { return false; } Texture2D *texture = TextureCache::sharedTextureCache()->addImage("Icon.png"); SpriteBatchNode* batch = SpriteBatchNode::createWithTexture(texture, 800); this->addChild(batch); for (int i = 0; i < 800; ++i) { int index = (i % 50) * 8; int rowIndex = (i / 50) * 8; Sprite *temp = Sprite::createWithTexture(texture); temp->setPosition(Vec2(index, rowIndex)); batch->addChild(temp); } return true; }
//------------------------------------------------------------------ // // TMXOrthoTest // //------------------------------------------------------------------ TMXOrthoTest::TMXOrthoTest() { // // Test orthogonal with 3d camera and anti-alias textures // // it should not flicker. No artifacts should appear // //auto color = LayerColor::create( Color4B(64,64,64,255) ); //addChild(color, -1); auto map = TMXTiledMap::create("TileMaps/orthogonal-test2.tmx"); addChild(map, 0, kTagTileMap); Size CC_UNUSED s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); auto pChildrenArray = map->getChildren(); SpriteBatchNode* child = NULL; Object* pObject = NULL; CCARRAY_FOREACH(pChildrenArray, pObject) { child = static_cast<SpriteBatchNode*>(pObject); if(!child) break; child->getTexture()->setAntiAliasTexParameters(); }
//INITS void GameScreen::InitAnimation() { SpriteBatchNode* spritebatch = SpriteBatchNode::create("Assets/Animation/Idle.png"); SpriteFrameCache* cache = SpriteFrameCache::getInstance(); cache->addSpriteFramesWithFile("Assets/Animation/Idle.plist"); _santaPaused = Sprite::createWithSpriteFrameName("Assets/Santa/idle_0001.png"); spritebatch->addChild(_santaPaused); addChild(spritebatch); _santaPaused->setPosition(Vec2(-_winSizeW*0.5f, _winSizeH*0.7f)); Vector<SpriteFrame*> animFrames; char str[100] = { 0 }; for (int i = 1; i <= 12; i++) { sprintf(str, "Assets/Santa/idle_%04d.png", i); SpriteFrame* frame = cache->getSpriteFrameByName(str); animFrames.pushBack(frame); } Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.1f); _santaPaused->runAction(RepeatForever::create(Animate::create(animation))); }
SpriteBatchNode* SpriteBatchNode::create(const std::string& fileImage, ssize_t capacity/* = DEFAULT_CAPACITY*/) { SpriteBatchNode *batchNode = new (std::nothrow) SpriteBatchNode(); batchNode->initWithFile(fileImage, capacity); batchNode->autorelease(); return batchNode; }
SpriteBatchNode* SpriteBatchNode::create(const char *fileImage, int capacity/* = kDefaultSpriteBatchCapacity*/) { SpriteBatchNode *batchNode = new SpriteBatchNode(); batchNode->initWithFile(fileImage, capacity); batchNode->autorelease(); return batchNode; }
void LevelTwo::createEndGame() { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 0; i < ptr->m_numEndGame; i++) { endGame * endGame = endGame::create(Vec2(ptr->m_endGameX[i], ptr->m_endGameY[i]), 1); m_end.push_back(endGame); spritebatch->addChild(endGame, -5); } this->addChild(spritebatch, 1, END_SPRITE_BATCH); }
void Tutorial::createTrucks()//creates the trucks { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 0; i < 10; i++)//loops thru the trucks for tutorial { Truck * base = Truck::create(Vec2(ptr->m_truckPosX[i], ptr->m_truckPosY[i]), m_gameState); m_trucks.push_back(base); spritebatch->addChild(base, 1); } this->addChild(spritebatch, 1, COINS_SPRITE_BATCH); }
void Tutorial::createAmbulances()//creates the ambulances { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 22; i < ptr->m_numberOfAmbulance; i++)//loops thru the ambulances for tutorial { Ambulance * base = Ambulance::create(Vec2(ptr->m_ambulancePosX[i], ptr->m_ambulancePosY[i]), m_gameState); m_ambulances.push_back(base); spritebatch->addChild(base, 1); } this->addChild(spritebatch, 1, COINS_SPRITE_BATCH); }
void Tutorial::createCoins()//creates the coins { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 92; i < 104; i++)//loops thru the coins for tutorial { Coin * base = Coin::create(Vec2(ptr->m_coinPosX[i], ptr->m_coinPosY[i]), m_gameState); m_coins.push_back(base); spritebatch->addChild(base, 1); } this->addChild(spritebatch, 4, COINS_SPRITE_BATCH); }
void Tutorial::createTowerBases()//creates the taxis { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 24; i < ptr->m_numberOfTowerBases; i++)//loops thru the taxi for tutorial { TowerBase * base = TowerBase::create(Vec2(ptr->m_towerBaseX[i], ptr->m_towerBaseY[i]), m_gameState); m_towerBases.push_back(base); spritebatch->addChild(base, 1); } this->addChild(spritebatch, 1, TOWERS_SPRITE_BATCH); }
void LevelTwo::createHiddenPlatforms() { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 0; i < ptr->m_numberOfHiddenPlatforms; i++) { TowerBase * HiddenPlat = TowerBase::create(Vec2(380, 470), m_gameState, 4); m_hiddenPlats.push_back(HiddenPlat); spritebatch->addChild(HiddenPlat, -5); } this->addChild(spritebatch, 1, HIDDEN_SPRITE_BATCH); }
void LevelTwo::createPlatforms() { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 0; i < ptr->m_numberOfLevelTwoPlats; i++) { TowerBase * base = TowerBase::create(Vec2(ptr->m_levelTwoPlatformsX[i], ptr->m_levelTwoPlatformsY[i]), m_gameState, 3); m_levelTwoPlat.push_back(base); spritebatch->addChild(base, -5); } this->addChild(spritebatch, 1, LEVELTWO_SPRITE_BATCH); }
NS_CC_BEGIN /* * creation with Texture2D */ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, int capacity/* = kDefaultSpriteBatchCapacity*/) { SpriteBatchNode *batchNode = new SpriteBatchNode(); batchNode->initWithTexture(tex, capacity); batchNode->autorelease(); return batchNode; }
NS_CC_BEGIN /* * creation with Texture2D */ SpriteBatchNode* SpriteBatchNode::createWithTexture(Texture2D* tex, ssize_t capacity/* = DEFAULT_CAPACITY*/) { SpriteBatchNode *batchNode = new (std::nothrow) SpriteBatchNode(); batchNode->initWithTexture(tex, capacity); batchNode->autorelease(); return batchNode; }
void HelloWorld::addBird(cocos2d::Point p) { SpriteBatchNode *parent = SpriteBatchNode::create("bird_hero.png"); m_pSpriteTexture = parent->getTexture();//获取纹理贴图 //将精灵批处理节点添加到层 this->addChild(parent,0,kTagParentNode); // Sprite *sprite = Sprite::createWithTexture(m_pSpriteTexture,Rect(32*idx, 32*idy, 32, 32)); bird = Sprite::createWithTexture(m_pSpriteTexture); parent->addChild(bird); Size birdSize = m_pSpriteTexture->getContentSize(); b2BodyDef bodyDef; bodyDef.type = b2_dynamicBody; bodyDef.position.Set(p.x/PTM_RATIO, p.y/PTM_RATIO); bodyDef.userData = bird; b2Body *body = world->CreateBody(&bodyDef); //定义盒子形状 b2PolygonShape dynamicBox; dynamicBox.SetAsBox(birdSize.width/2/PTM_RATIO, birdSize.height/2/PTM_RATIO); b2FixtureDef fixtureDef; // fixtureDef.filter.groupIndex = 0; // fixtureDef.filter.maskBits = 0x0002;//掩码 // fixtureDef.filter.categoryBits = 0x0003;//设置分类码 fixtureDef.shape = &dynamicBox; fixtureDef.density = 1.f;//密度 fixtureDef.friction = 0.3f; fixtureDef.restitution = 0.f;//弹性系数 body->CreateFixture(&fixtureDef);//用刚体创建夹具 //事件监听 auto listener1 = EventListenerTouchOneByOne::create(); listener1->setSwallowTouches(true); listener1->onTouchBegan =[=](Touch *touch,Event *event) { //设置线性速度 body->SetLinearVelocity(b2Vec2(0, 7)); return true; }; _eventDispatcher->addEventListenerWithSceneGraphPriority(listener1, this); }
void LevelTwo::createButton() { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 0; i < ptr->m_numButton; i++) { Button * button = Button::create(Vec2(ptr->m_ButtonsX[i], ptr->m_ButtonsY[i]), 2); m_button.push_back(button); spritebatch->addChild(button, -5); } for (int i = 0; i < ptr->m_numButton; i++) { Button * button = Button::create(Vec2(ptr->m_ButtonsX[i], ptr->m_ButtonsY[i]), 3); m_button.push_back(button); spritebatch->addChild(button, -5); } this->addChild(spritebatch, 1, END_SPRITE_BATCH); }
//------------------------------------------------------------------ // // TMXOrthoTest2 // //------------------------------------------------------------------ TMXOrthoTest2::TMXOrthoTest2() { auto map = TMXTiledMap::create("TileMaps/orthogonal-test1.tmx"); addChild(map, 0, kTagTileMap); Size CC_UNUSED s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); auto& children = map->getChildren(); SpriteBatchNode* child = NULL; for(const auto &obj : children) { child = static_cast<SpriteBatchNode*>(obj); child->getTexture()->setAntiAliasTexParameters(); } map->runAction( ScaleBy::create(2, 0.5f) ) ; }
Box2DTestLayer::Box2DTestLayer() : _spriteTexture(NULL) , world(NULL) { #if CC_ENABLE_BOX2D_INTEGRATION setTouchEnabled( true ); setAccelerometerEnabled( true ); // init physics this->initPhysics(); // create reset button this->createResetButton(); //Set up sprite #if 1 // Use batch node. Faster SpriteBatchNode *parent = SpriteBatchNode::create("Images/blocks.png", 100); _spriteTexture = parent->getTexture(); #else // doesn't use batch node. Slower _spriteTexture = TextureCache::getInstance()->addImage("Images/blocks.png"); Node *parent = Node::create(); #endif addChild(parent, 0, kTagParentNode); addNewSpriteAtPosition(VisibleRect::center()); LabelTTF *label = LabelTTF::create("Tap screen", "Marker Felt", 32); addChild(label, 0); label->setColor(Color3B(0,0,255)); label->setPosition(Point( VisibleRect::center().x, VisibleRect::top().y-50)); scheduleUpdate(); #else LabelTTF *label = LabelTTF::create("Should define CC_ENABLE_BOX2D_INTEGRATION=1\n to run this test case", "Arial", 18); Size size = Director::getInstance()->getWinSize(); label->setPosition(Point(size.width/2, size.height/2)); addChild(label); #endif }
//------------------------------------------------------------------ // // TMXOrthoTest3 // //------------------------------------------------------------------ TMXOrthoTest3::TMXOrthoTest3() { auto map = TMXTiledMap::create("TileMaps/orthogonal-test3.tmx"); addChild(map, 0, kTagTileMap); Size CC_UNUSED s = map->getContentSize(); CCLOG("ContentSize: %f, %f", s.width,s.height); auto& children = map->getChildren(); SpriteBatchNode* child = NULL; for(const auto &node : children) { child = static_cast<SpriteBatchNode*>(node); child->getTexture()->setAntiAliasTexParameters(); } map->setScale(0.2f); map->setAnchorPoint( Vec2(0.5f, 0.5f) ); }
/* -(void) runDisappearAnimation : (BlockType )type : (CGPoint)pos : (b2World *)world : (b2Body *)body { if (type == Stone) { width = 15; height = 15; frameCount = 4; delay = 0.5f; stoneType = [NSString stringWithFormat:@"stoneAni_%d.png",GLOBAL_MAPINFO[GLOBAL_GAMEINFO.currentLevel-1]]; } else if (type == Item) { width = height = 27; frameCount = 8; delay = 0.2f; stoneType = [NSString stringWithFormat:@"Tannenzapfen.png"]; } SpriteBatchNode *parent = [SpriteBatchNode batchNodeWithFile:stoneType]; spriteTexture_ = [parent texture]; Sprite *sp1 = [Sprite spriteWithTexture:spriteTexture_ rect:CGRectMake( 0 , 0 , width, height)]; Sprite *sp2 = [Sprite spriteWithTexture:spriteTexture_ rect:CGRectMake( 15 , 0 , width, height)]; uint offsetY = 20; uint offsetX = 10; sp1.position = ccp(sp1.position.x +offsetX,sp1.position.y+offsetY); sp2.position = ccp(sp2.position.x+offsetX,sp2.position.y+offsetY); //sp3.position = ccp(sp3.position.x+offsetX,sp3.position.y+offsetY); //sp4.position = ccp(sp4.position.x+offsetX,sp4.position.y+offsetY); [self.parent addChild: sp1 z:15]; // [self addChild: sp2 z:15]; b2Body *body_StonePiece1; b2BodyDef bodyDef_StonePiece1; b2FixtureDef fixtureDef_StonePiece1; b2PolygonShape shape_StonePiece1; bodyDef_StonePiece1.type = b2_dynamicBody; bodyDef_StonePiece1.position.Set(sp1.position.x/PTM_RATIO, sp1.position.y/PTM_RATIO); bodyDef_StonePiece1.userData = sp1; body_StonePiece1 = world->CreateBody(&bodyDef_StonePiece1); shape_StonePiece1.SetAsBox(sp1.contentSize.width/PTM_RATIO*0.5, sp1.contentSize.height/PTM_RATIO*0.5); fixtureDef_StonePiece1.restitution = 0.5f; fixtureDef_StonePiece1.friction = 0.5f; fixtureDef_StonePiece1.density = 1.0f; fixtureDef_StonePiece1.shape = &shape_StonePiece1; body_StonePiece1->CreateFixture(&fixtureDef_StonePiece1); body_StonePiece1->ApplyForce(b2Vec2(1,15), body_StonePiece1->GetWorldCenter()); [self removeFromParentAndCleanup:YES]; } */ CCAnimation * BlockSprite::createAnimationFromCachedImage(BlockType type, unsigned int stage) { unsigned int smallStage = GLOBAL_MAPINFO[stage - 1]; if (type == Stone) { frameCount = 5; delay = 0.3f; width = 27 * RATE; height = 36 * RATE; if (smallStage == 1 || smallStage == 2 || smallStage == 6) stoneType = String::createWithFormat("Stone_%d_%d-hd.png", smallStage, rand() % 3 + 1); //[NSString stringWithFormat : @"Stone_%d_%d.png", smallStage, rand() % 3 + 1]; else stoneType = String::createWithFormat("Stone_%d_%d-hd.png", smallStage, 1); //[NSString stringWithFormat : @"Stone_%d_%d.png", smallStage, 1]; } else if (type == Item) { frameCount = 5; delay = 0.3f; width = height = 27 * RATE; stoneType = String::createWithFormat("Item_%d-hd.png", smallStage); //[NSString stringWithFormat : @"Item_%d.png", smallStage]; } SpriteBatchNode *parent = SpriteBatchNode::create(stoneType->getCString()); //[SpriteBatchNode batchNodeWithFile : stoneType]; spriteTexture_ = parent->getTexture(); //[parent texture]; //NSMutableArray *cachedImage = [NSMutableArray array]; Vector<SpriteFrame*> cachedImage; for (int i = 0; i < frameCount; i++) { //[cachedImage addObject : //[SpriteFrame frameWithTexture : spriteTexture_ rect : CGRectMake(i * 27 * RATE, 0, width, height)]]; cachedImage.pushBack(SpriteFrame::createWithTexture(spriteTexture_, Rect(i * 27 * RATE, 0, width, height))); } CCAnimation *animation = Animation::createWithSpriteFrames(cachedImage, delay); //[CCAnimation animationWithSpriteFrames : cachedImage delay : delay]; return animation; }
void TileMapLayer::createWithTMX(const char* tmxFile) { // create a TMX map --- WARNING : if tsx path in the tmx file is subclass of Resources, libs can't find *.tsx, *.png map = TMXTiledMap::create(tmxFile); prepareLayers(); addChild(map); // All the tiles by default will be aliased. If you want to create anti-alias tiles, you should do: // iterate over all the "layers" (atlas sprite managers) // and set them as 'antialias' Array * pChildrenArray = map->getChildren(); SpriteBatchNode* child = NULL; Object* pObject = NULL; CCARRAY_FOREACH(pChildrenArray, pObject) { child = (SpriteBatchNode*)pObject; if(!child) break; child->getTexture()->setAntiAliasTexParameters(); }
void gameLevel2::shipExplosions(Vec2 vec,bool scale) { SpriteBatchNode* spritebatch = SpriteBatchNode::create("animations/explosion.png"); SpriteFrameCache* cache = SpriteFrameCache::getInstance(); cache->addSpriteFramesWithFile("animations/explosion.plist"); auto explosion = Sprite::createWithSpriteFrameName("explosion_01.png"); explosion->setPosition(vec); if (scale) explosion->setScale(0.5); spritebatch->addChild(explosion); this->addChild(spritebatch); Vector<SpriteFrame*> animFrames(48); char str[100] = { 0 }; for (int i = 1; i < 49; i++) { sprintf(str, "explosion_%02d.png", i); SpriteFrame* frame = cache->getSpriteFrameByName(str); animFrames.pushBack(frame); } Animation* animation = Animation::createWithSpriteFrames(animFrames, 0.02); explosion->runAction(Sequence::create(Animate::create(animation),RemoveSelf::create(),NULL)); }
void LevelTwo::createTraps() { std::shared_ptr<GameData> ptr = GameData::sharedGameData(); SpriteBatchNode* spritebatch = SpriteBatchNode::create(ptr->m_textureAtlasImageFile); for (int i = 0; i < 1; i++) { TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 520, 240); m_traps.push_back(traps); spritebatch->addChild(traps, -5); } for (int i = 0; i < 1; i++) { TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 970, 240); m_traps.push_back(traps); spritebatch->addChild(traps, -5); } for (int i = 0; i < 1; i++) { TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 590, 115); m_traps.push_back(traps); spritebatch->addChild(traps, -5); } for (int i = 0; i < 1; i++) { TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 790, 115); m_traps.push_back(traps); spritebatch->addChild(traps, -5); } for (int i = 0; i < 1; i++) { TowerGun * traps = TowerGun::create(Vec2(ptr->m_trapX[i], ptr->m_trapY[i]), 2, 990, 115); m_traps.push_back(traps); spritebatch->addChild(traps, -5); } this->addChild(spritebatch, -1, TRAPS_SPRITE_BATCH); }
bool GameScene::init() { if (!Layer::init()) { return false; } gameScene = this;//用于获取游戏场景对象 winSize = Director::getInstance()->getWinSize(); floorCount = 16;//设置地面和金币的个数 forceX = 300; forceY = 30; xSpeed = 5; ySpeed = 15;//决定跳的高度 constXspeed = xSpeed; constYspeed = ySpeed; scaleFix = winSize.width/480; speedFix = 0.01; accelerate = 0.94;//加速度 sizep = Director::getInstance()->getWinSizeInPixels(); scaleFix = sizep.width/480; isJump = false; isPlaySound=GameFatherLayer::allowSound();//是否播放音效 isCollistionWithFloor =false; //创建背景地图 BackMap *sky = BackMap::createMap("back_1.png"); this->addChild(sky,0,0); BackMap *backMap = BackMap::createMap("back_5.png"); this->addChild(backMap,0,1); //创建主角精灵 player = Player::createPlayer(); SpriteBatchNode *batchNode = SpriteBatchNode::create("run.png"); batchNode->addChild(player, 2, 10); playerWidth = player->getContentSize().width; playerHeight = player->getContentSize().height; this->addChild(batchNode); player->setPosition(Point(-20, winSize.height/2 -100)); MoveBy *move = MoveBy::create(1, Point(80, 0)); player->runAction(move); Floor *temp = Floor::createFloor(); floorWidth = temp->getContentSize().width; floorHeight = temp->getContentSize().height; SimpleAudioEngine::getInstance()->preloadBackgroundMusic("background.caf"); SimpleAudioEngine::getInstance()->preloadEffect("eatcoin.caf"); if (isPlaySound) { SimpleAudioEngine::getInstance()->playBackgroundMusic("background.caf"); } //进度条 coinNeededNum = 30; coinUsed = 0; isBarFull = false; progressInterval = 100.0/(float)coinNeededNum; Sprite *barSprite = Sprite::create("powerbar.png"); progress = ProgressTimer::create(barSprite); progress->setPercentage(0.0f); progress->setMidpoint(Point(0, 0)); progress->setBarChangeRate(Point(1, 0)); progress->setScaleY(1.2); progress->setType(kCCProgressTimerTypeBar); progress->setAnchorPoint(Point(0, 0.5)); progress->setPosition(Point(20, winSize.height-18)); Sprite *proFrame = Sprite::create("powerui.png"); proFrame->setAnchorPoint(Point(0, 0.3)); progress->addChild(proFrame); this->addChild(progress); //添加返回主页按钮 MenuItemImage *menuItem = MenuItemImage::create("btnmenu.png", "btnmenu.png",CC_CALLBACK_1(GameScene::menuButton, this)); menuItem->setAnchorPoint(Point(1, 1)); Menu *menu = Menu::create(menuItem, NULL); menu->setPosition(Point(winSize.width-20, winSize.height - 20)); this->addChild(menu); this->initFloorsAndCoins(); this->scheduleUpdate(); return true; }
// on "init" you need to initialize your instance bool CShop::init() { ////////////////////////////// // 1. super init first if (!Layer::init()) { return false; } Size visibleSize = Director::getInstance()->getVisibleSize(); Vec2 origin = Director::getInstance()->getVisibleOrigin(); ///////////////////////////// // 3. add your codes below... auto m_textureCache = TextureCache::getInstance(); //添加背景 auto bg = Sprite::createWithTexture(m_textureCache->getTextureForKey("select_degree.jpg")); bg->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); this->addChild(bg); //////////道具种类///////////// //双倍分数 图标 auto scoreSprite = Sprite::createWithTexture( m_textureCache->getTextureForKey("prop_score.png")); scoreSprite->setPosition(Vec2(visibleSize.width/4,visibleSize.height*0.6)); this->addChild(scoreSprite); //双倍金币 图标 auto goldSprite = Sprite::createWithTexture( m_textureCache->getTextureForKey("prop_gold.png")); goldSprite->setPosition(Vec2(visibleSize.width / 4, visibleSize.height*0.6 - scoreSprite->getContentSize().height)); this->addChild(goldSprite); //延时 图标 auto delaySprite = Sprite::createWithTexture( m_textureCache->getTextureForKey("prop_delay.png")); delaySprite->setPosition(Vec2(visibleSize.width / 4, visibleSize.height*0.6 - scoreSprite->getContentSize().height * 2)); this->addChild(delaySprite); //提示 图标 auto hintSprite = Sprite::createWithTexture( m_textureCache->getTextureForKey("prop_hint.png")); hintSprite->setPosition(Vec2(visibleSize.width / 4, visibleSize.height*0.6 - scoreSprite->getContentSize().height * 3)); this->addChild(hintSprite); //////////玩家当前道具数量///////////// std::string num; //玩家金币数量 auto m_goldSprite = Sprite::createWithTexture( m_textureCache->getTextureForKey("rest_gold.png")); m_goldSprite->setPosition(Vec2(visibleSize.width - m_goldSprite->getContentSize().width*0.6, visibleSize.height - m_goldSprite->getContentSize().height*0.6)); m_goldSprite->runAction(Sequence::create(JumpTo::create(1.0,m_goldSprite->getPosition(),m_goldSprite->getContentSize().height,2),nullptr)); this->addChild(m_goldSprite); num = String::createWithFormat("%d", CScore::getInstance()->getGold())->_string; auto remainLabel = Label::createWithCharMap( "digital.png", 20, 20, '0'); remainLabel->setString(num); remainLabel->setScale(1.5); remainLabel->setAlignment(TextHAlignment::RIGHT); remainLabel->setAnchorPoint(Vec2(1,1)); remainLabel->setPosition(Vec2(visibleSize.width, visibleSize.height-m_goldSprite->getContentSize().height)); this->addChild(remainLabel,1,101); /* //金币积分兑换 auto totalSprite1 = Sprite::create("total_change.png"); auto totalSprite2 = Sprite::create("total_change.png"); totalSprite2->setScale(1.2); auto totalGoldItem = MenuItemSprite::create( totalSprite1, totalSprite2 ); totalGoldItem->setCallback(CC_CALLBACK_1(CShop::onChangeItemCallback, this)); totalGoldItem->setPosition(Vec2( visibleSize.width - totalGoldItem->getContentSize().width / 2, visibleSize.height - m_goldSprite->getContentSize().height-remainLabel->getContentSize().height*2)); num = String::createWithFormat("%d", AdHelp::queryPoints())->_string; totalLabel = Label::createWithCharMap( "digital.png", 20, 20, '0'); totalLabel->setString(num); totalLabel->setScale(1.5); totalLabel->setAlignment(TextHAlignment::RIGHT); totalLabel->setAnchorPoint(Vec2(1, 1)); totalLabel->setPosition(Vec2(visibleSize.width, visibleSize.height - m_goldSprite->getContentSize().height - remainLabel->getContentSize().height-totalSprite1->getContentSize().height)); this->addChild(totalLabel, 1,100); */ //返回主界面 按钮 auto spriteNor0 = Sprite::createWithTexture( m_textureCache->getTextureForKey("return.png")); auto spriteSel0 = Sprite::createWithTexture( m_textureCache->getTextureForKey("return.png")); spriteSel0->setScale(1.2); auto backItem = MenuItemSprite::create( spriteNor0, spriteSel0 ); backItem->setCallback(CC_CALLBACK_1(CShop::onReturnItemCallback, this)); backItem->setPosition(Vec2(visibleSize.width / 8, visibleSize.height * 0.8)); // auto menu0 = Menu::create(totalGoldItem, backItem, nullptr); auto menu0 = Menu::create(backItem, nullptr); menu0->setPosition(Vec2::ZERO); addChild(menu0); //双倍分数 道具数量 num = String::createWithFormat("%d", CScore::getInstance()->getMultScore())->_string; auto scoreLabel = Label::createWithCharMap( "digital.png", 20, 20, '0'); scoreLabel->setString(num); scoreLabel->setScale(1.5); scoreLabel->setPosition(Vec2(visibleSize.width *0.5, visibleSize.height*0.6)); this->addChild(scoreLabel,1,102); //双倍金币 num = String::createWithFormat("%d", CScore::getInstance()->getMultGold())->_string; auto goldLabel = Label::createWithCharMap( "digital.png", 20, 20, '0'); goldLabel->setString(num); goldLabel->setScale(1.5); goldLabel->setPosition(Vec2(visibleSize.width *0.5, visibleSize.height*0.6 - scoreSprite->getContentSize().height)); this->addChild(goldLabel,1, 103); //延时 num = String::createWithFormat("%d", CScore::getInstance()->getPropDelay())->_string; auto delayLabel = Label::createWithCharMap( "digital.png", 20, 20, '0'); delayLabel->setString(num); delayLabel->setScale(1.5); delayLabel->setPosition(Vec2(visibleSize.width *0.5, visibleSize.height*0.6 - scoreSprite->getContentSize().height * 2)); this->addChild(delayLabel, 1, 104); //提示 num = String::createWithFormat("%d", CScore::getInstance()->getPropHint())->_string; auto hintLabel = Label::createWithCharMap( "digital.png", 20, 20, '0'); hintLabel->setString(num); hintLabel->setScale(1.5); hintLabel->setPosition(Vec2(visibleSize.width *0.5, visibleSize.height*0.6 - scoreSprite->getContentSize().height * 3)); this->addChild(hintLabel, 1, 105); /* auto t = Label::createWithTTF( "test", "fonts/DFPShaoNvW5-GB.ttf", 40); t->setPosition(Vec2(visibleSize.width / 2, visibleSize.height / 2)); this->addChild(t, 1);*/ //////////购买道具按钮///////////// SpriteBatchNode* spriteBatchNode = SpriteBatchNode::create("100.png"); this->addChild(spriteBatchNode); auto spriteNor1 = Sprite::createWithTexture(spriteBatchNode->getTexture()); auto spriteSel1 = Sprite::createWithTexture(spriteBatchNode->getTexture()); spriteSel1->setScale(1.2); // spriteBatchNode->addChild(spriteNor1); // spriteBatchNode->addChild(spriteSel1); auto spriteNor2 = Sprite::createWithTexture(spriteBatchNode->getTexture()); auto spriteSel2 = Sprite::createWithTexture(spriteBatchNode->getTexture()); spriteSel2->setScale(1.2); /* spriteBatchNode->addChild(spriteNor2); spriteBatchNode->addChild(spriteSel2); */ SpriteBatchNode* spriteBatchNode1 = SpriteBatchNode::create("300.png"); this->addChild(spriteBatchNode1); auto spriteNor3 = Sprite::createWithTexture(spriteBatchNode1->getTexture()); auto spriteSel3 = Sprite::createWithTexture(spriteBatchNode1->getTexture()); spriteSel3->setScale(1.2); /* spriteBatchNode->addChild(spriteNor3); spriteBatchNode->addChild(spriteSel3); */ auto spriteNor4 = Sprite::createWithTexture(spriteBatchNode1->getTexture()); auto spriteSel4 = Sprite::createWithTexture(spriteBatchNode1->getTexture()); spriteSel4->setScale(1.2); /* spriteBatchNode->addChild(spriteNor4); spriteBatchNode->addChild(spriteSel4); */ //购买道具 分数加倍 按钮 auto scoreItem = MenuItemSprite::create( spriteNor1, spriteSel1 ); scoreItem->setCallback(CC_CALLBACK_1(CShop::onScoreItemCallback, this)); //购买道具 金币加倍 按钮 auto goldItem = MenuItemSprite::create( spriteNor2, spriteSel2 ); goldItem->setCallback(CC_CALLBACK_1(CShop::onGoldItemCallback, this)); //购买道具 延时 按钮 auto delayItem = MenuItemSprite::create( spriteNor3, spriteSel3 ); delayItem->setCallback(CC_CALLBACK_1(CShop::onDelayItemCallback, this)); //购买道具 提示 按钮 auto hintItem = MenuItemSprite::create( spriteNor4, spriteSel4 ); hintItem->setCallback(CC_CALLBACK_1(CShop::onHintItemCallback, this)); auto menu = Menu::create(scoreItem, goldItem, delayItem, hintItem, nullptr); menu->alignItemsVerticallyWithPadding(scoreItem->getContentSize().height); menu->setPosition(Vec2(visibleSize.width *3/ 4, visibleSize.height*0.43)); this->addChild(menu); return true; }
//实现PianoLayer类中的init方法,初始化布景 bool PianoLayer::init() { //调用父类的初始化 if ( !Layer::init() ) { return false; } degree = 0; musicFlag = false; pauseFlag = false; instrumentName = "piano"; instrumentNumber = 1; changeFlag = true; musicNum = 0; //获取可见区域尺寸 Size visibleSize = Director::getInstance()->getVisibleSize(); //获取可见区域原点坐标 Point origin = Director::getInstance()->getVisibleOrigin(); Sprite* volume = Sprite::create(pic_RESOURE_PATH + "volume_cn.png"); //音量 volumeSize = volume->getContentSize(); volume->setScale(1.2); volume->setPosition(Point(volumeSize.width/2 + 20, visibleSize.height - volumeSize.height/2)); this->addChild(volume, 2); exit = Sprite::create(pic_RESOURE_PATH + "exit.png"); //退出 Size exitSize = exit->getContentSize(); exit->setScale(1.2); exit->setPosition(Point(visibleSize.width - exitSize.width/2, visibleSize.height - exitSize.height/2)); this->addChild(exit, 2); slider = Slider::create(); slider->loadBarTexture(pic_RESOURE_PATH + "soundBackGround.png"); slider->loadSlidBallTextures(pic_RESOURE_PATH + "transparent.png",pic_RESOURE_PATH + "transparent.png", ""); slider->loadProgressBarTexture(pic_RESOURE_PATH + "sound.png"); slider->setAnchorPoint(Point(0, 0.5)); sliderSize = slider->getContentSize(); slider->setPercent(CocosDenshion::SimpleAudioEngine::getInstance()->getEffectsVolume()*100); slider->setPosition(Point(volumeSize.width*1.2 + 20, visibleSize.height - volumeSize.height/2)); slider->addEventListener(CC_CALLBACK_2(PianoLayer::sliderEvent, this)); this->addChild(slider, 5); instrument = Sprite::create(pic_RESOURE_PATH + "piano_cn.png"); //选择 Size selectSize = instrument->getContentSize(); instrument->setPosition( Point( visibleSize.width - exitSize.width - selectSize.width/2 -20, visibleSize.height - selectSize.height/2 )); this->addChild(instrument, 2); selection = Sprite::create(pic_RESOURE_PATH + "back.png"); //背景 selection->setPosition( Point( visibleSize.width - exitSize.width - selectSize.width/2 -20, visibleSize.height - selectSize.height/2 )); this->addChild(selection, 1); Sprite* left = Sprite::create(pic_RESOURE_PATH + "left.png"); //左键 leftSize = left->getContentSize(); left->setScale(SCALE); left->setPosition( Point( leftSize.width/2*SCALE + 10, visibleSize.height - volumeSize.height - leftSize.height*SCALE/2 - 5 )); this->addChild(left, 2); Sprite* right = Sprite::create(pic_RESOURE_PATH + "right.png"); //右键 rightSize = right->getContentSize(); right->setScale(SCALE); right->setPosition( Point( visibleSize.width - rightSize.width*SCALE/2 - 10, visibleSize.height - volumeSize.height - rightSize.height*SCALE/2 - 5 )); this->addChild(right, 2); //第二个参数为最大储存数 SpriteBatchNode* batchNode = SpriteBatchNode::create(pic_RESOURE_PATH + "white_small.jpg", 50); //小键盘 batchNode->setAnchorPoint(Point(0, 0)); batchNode->setPosition( Point( leftSize.width*SCALE + LEFT_INTERVAL, visibleSize.height - volumeSize.height - ABOVE_INTERVAL )); this->addChild(batchNode); for(int i = 0; i<PIANO_KEY; i++) //小键盘 { Sprite* whiteSmall = Sprite::createWithTexture(batchNode->getTexture(), Rect(0, 0, 34, 57)); whiteSmall->setScale(SCALE); whiteSmall->setAnchorPoint(Point(0, 0)); smallSize = whiteSmall->getContentSize(); whiteSmall->setPosition(Point(i*smallSize.width*SCALE,0)); batchNode->addChild(whiteSmall, 2); } selectBack = Sprite::create(pic_RESOURE_PATH + "selectBack.png"); backSize = selectBack->getContentSize(); selectBack->setPosition( Point( leftSize.width*SCALE + LEFT_INTERVAL + smallSize.width*SCALE*7 + backSize.width/2, visibleSize.height - volumeSize.height - 37 )); this->addChild(selectBack, 4); float width = PIANO_KEY*smallSize.width*SCALE - backSize.width; //总长 percent = (selectBack->getPosition().x - backSize.width/2 - leftSize.width*SCALE - LEFT_INTERVAL) / width; float positionX = -percent*WHITE_INTERVAL*13; // for(int i=0; i<PIANO_KEY; i++) { Sprite* white = Sprite::create(pic_RESOURE_PATH + "white.png"); white->setScale(1.12); white->setAnchorPoint(Point(0, 0)); white->setPosition(Point(positionX + i*WHITE_INTERVAL, 0)); string tempNumber = StringUtils::format("%d", i); whiteSize = white->getContentSize(); piano.insert(pair<string,Sprite*>(tempNumber, white)); } for(int i = PIANO_KEY,j=0;i<38; i++) { Sprite* black = Sprite::create(pic_RESOURE_PATH + "black.png"); black->setScale(1.12); black->setAnchorPoint(Point(0.5, 0)); blackSize = black->getContentSize(); black->setPosition(Point(positionX + (i-21+j)*WHITE_INTERVAL, (whiteSize.height - blackSize.height)*1.12)); string tempNumber = StringUtils::format("%d", i); if((i-21)%5==0||(i-21)==2||(i-21)==7||(i-21)==12) { j++; } piano_black.insert(pair<string,Sprite*>(tempNumber, black)); } map<string, Sprite*>::iterator iter; for(iter=piano.begin(); iter != piano.end();iter++) { this->addChild(iter->second, 5); } for(iter=piano_black.begin(); iter != piano_black.end(); iter++) { this->addChild(iter->second, 6); } for(int i = PIANO_KEY,j = 0; i<38; i++) { Sprite* blackSmall; float positionX; if(i==37) { blackSmall = Sprite::create(pic_RESOURE_PATH + "black_small_half.jpg"); Size size = blackSmall->getContentSize(); positionX = leftSize.width*SCALE + LEFT_INTERVAL + (i-21+j)*smallSize.width*SCALE-size.width/2; }else { blackSmall = Sprite::create(pic_RESOURE_PATH + "black_small.jpg"); positionX = leftSize.width*SCALE + LEFT_INTERVAL + (i-21+j)*smallSize.width*SCALE; } blackSmall->setScale(SCALE); blackSmall->setAnchorPoint(Point(0.5, 0)); blackSmall->setPosition(Point( positionX, visibleSize.height - volumeSize.height - ABOVE_INTERVAL + smallSize.height*SCALE/2)); if((i-21)%5==0||(i-21)==2||(i-21)==7||(i-21)==12) { j++; } this->addChild(blackSmall, 2); } //设置定时回调指定方法干活 auto director = Director::getInstance(); schedRound = director->getScheduler(); //创建退出单点触摸监听 EventListenerTouchOneByOne* listenerExit = EventListenerTouchOneByOne::create(); //开始触摸时回调onTouchBegan方法 listenerExit->onTouchBegan = CC_CALLBACK_2(PianoLayer::onTouchExitBegan, this); //添加到监听器 _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerExit, exit); //创建乐器单点触摸监听 EventListenerTouchOneByOne* listenerSelect = EventListenerTouchOneByOne::create(); listenerSelect->setSwallowTouches(true); //开始触摸时回调onTouchBegan方法 listenerSelect->onTouchBegan = CC_CALLBACK_2(PianoLayer::onTouchBegan, this); listenerSelect->onTouchEnded = CC_CALLBACK_2(PianoLayer::onTouchEnded, this); //添加到监听器 _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerSelect, instrument); //创建左箭头单点触摸监听 EventListenerTouchOneByOne* listenerLeft = EventListenerTouchOneByOne::create(); listenerLeft->setSwallowTouches(true); //开始触摸时回调onTouchBegan方法 listenerLeft->onTouchBegan = CC_CALLBACK_2(PianoLayer::onTouchLeftBegan, this); listenerLeft->onTouchEnded = CC_CALLBACK_2(PianoLayer::onTouchLeftEnded, this); //添加到监听器 _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerLeft, left); //创建右箭头单点触摸监听 EventListenerTouchOneByOne* listenerRight= EventListenerTouchOneByOne::create(); listenerRight->setSwallowTouches(true); //开始触摸时回调onTouchBegan方法 listenerRight->onTouchBegan = CC_CALLBACK_2(PianoLayer::onTouchRightBegan, this); listenerRight->onTouchEnded = CC_CALLBACK_2(PianoLayer::onTouchRightEnded, this); //添加到监听器 _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerRight, right); //创建单点触摸监听 EventListenerTouchOneByOne* listenerBack = EventListenerTouchOneByOne::create(); //设置下传触摸 listenerBack->setSwallowTouches(true); //开始触摸时回调onTouchBegan方法 listenerBack->onTouchBegan = CC_CALLBACK_2(PianoLayer::onTouchSelectBegan, this); listenerBack->onTouchMoved = CC_CALLBACK_2(PianoLayer::onTouchSelectMoved, this); //添加到监听器 _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerBack, selectBack); //---------------------------------单点触控,用于选择钢琴键----------------------------- //创建单点触摸监听 EventListenerTouchOneByOne* listener = EventListenerTouchOneByOne::create(); //开始触摸时回调onTouchBegan方法 listener->onTouchBegan = CC_CALLBACK_2(PianoLayer::onMyTouchBegan, this); _eventDispatcher->addEventListenerWithSceneGraphPriority(listener, this); //---------------------------------多点触控,用于点击钢琴键------------------------------ //创建一个多点触摸监听 auto listenerTouch = EventListenerTouchAllAtOnce::create(); //开始触摸时回调onTouchBegan方法 listenerTouch->onTouchesBegan = CC_CALLBACK_2(PianoLayer::onMyTouchesBegan, this); //触摸移动时回调onTouchMoved方法 listenerTouch->onTouchesMoved = CC_CALLBACK_2(PianoLayer::onMyTouchesMoved, this); //触摸结束时回调onTouchEnded方法 listenerTouch->onTouchesEnded = CC_CALLBACK_2(PianoLayer::onMyTouchesEnded, this); //添加到监听器 _eventDispatcher->addEventListenerWithSceneGraphPriority(listenerTouch, this); return true; }
StonePieceSprite* StonePieceSprite::initStonePieceWithType(BlockType type, b2World * world, StonePieceType piece, Point pos) { int width, height; String *stoneType; CCTexture2D *spriteTexture_; int level = (g_nBigLevel - 1) * 8 + g_nSmallLevel; if (type == Stone) { width = 15 * RATE; height = 15 * RATE; stoneType = String::createWithFormat("stoneAni_%d-hd.png", GLOBAL_MAPINFO[level - 1]); } else if (type == Item) { width = height = 15 * RATE; stoneType = String::createWithFormat("itemAni_%d-hd.png", GLOBAL_MAPINFO[level - 1]); } else if (type == Platform_Breakable) { width = 40 * RATE; height = 27 * RATE; stoneType = String::createWithFormat("FlyingPlatform_break-hd.png"); //stoneType = String::createWithFormat("itemAni_%d-hd.png", GLOBAL_MAPINFO[level - 1]); } SpriteBatchNode *parent = SpriteBatchNode::create(stoneType->getCString()); //[SpriteBatchNode batchNodeWithFile : stoneType); spriteTexture_ = parent->getTexture();//[parent texture); if (Sprite::initWithTexture(spriteTexture_, Rect(piece*width, 0, width, height))) { BodyInfo info; if (type == Platform_Breakable) { this->setTag(tag_pb); info.type = b2_staticBody; info.categoryBit = CATEGORY_SCENE; info.maskBit = ~(CATEGORY_SCENE); info.density = 0.1f; if (piece == piece1) this->setPosition(pos.x - this->getContentSize().width / 2 * G_SCALEX, pos.y - this->getContentSize().height / 2 * G_SCALEY); else this->setPosition(pos.x + this->getContentSize().width / 2 * G_SCALEX, pos.y - this->getContentSize().height / 2 * G_SCALEY); } else if (type == Platform_Down_1) { this->setPosition(pos.x, pos.y - this->getContentSize().height / 2 * G_SCALEY); info.type = b2_kinematicBody; info.categoryBit = CATEGORY_SCENE; info.maskBit = ~CATEGORY_SCENE; auto moveX1 = MoveBy::create(2.0f,Point(this->getPosition().x, this->getPosition().y - 50 * G_SCALEY)); auto moveX2 = MoveBy::create(2.0f,Point(this->getPosition().x, this->getPosition().y + 100 * G_SCALEY)); auto moveX3 = MoveBy::create(2.0f,Point(this->getPosition().x, this->getPosition().y - 100 * G_SCALEY)); auto action = RepeatForever::create( Sequence::create(moveX2, moveX3, NULL)); this->runAction( Sequence::create( moveX1, action, NULL)); } else if (type == Platform_Down_2) { this->setPosition(pos.x, pos.y - this->getContentSize().height / 2 * G_SCALEY); info.type = b2_kinematicBody; info.categoryBit = CATEGORY_SCENE; info.maskBit = ~CATEGORY_SCENE; auto moveX1 = MoveBy::create(2.0f, Point(this->getPosition().x, this->getPosition().y - 50 * G_SCALEY)); auto moveX2 = MoveBy::create(2.0f, Point(this->getPosition().x, this->getPosition().y + 100 * G_SCALEY)); auto moveX3 = MoveBy::create(2.0f, Point(this->getPosition().x, this->getPosition().y - 100 * G_SCALEY)); auto action = RepeatForever::create(Sequence::create(moveX2, moveX3, NULL)); this->runAction( Sequence::create( moveX1, action, NULL)); } else if (type == Platform) { this->setPosition(pos.x, pos.y - this->getContentSize().height / 2 * G_SCALEY); info.type = b2_kinematicBody; info.categoryBit = CATEGORY_SCENE; info.maskBit = ~CATEGORY_SCENE; auto moveX1 = MoveBy::create(2.0f, Point(this->getPosition().x, this->getPosition().y - 50 * G_SCALEY)); auto moveX2 = MoveBy::create(2.0f, Point(this->getPosition().x, this->getPosition().y + 100 * G_SCALEY)); auto moveX3 = MoveBy::create(2.0f, Point(this->getPosition().x, this->getPosition().y - 100 * G_SCALEY)); auto action = RepeatForever::create(Sequence::create(moveX2, moveX3, NULL)); this->runAction( Sequence::create( moveX1, action, NULL)); } else { info.type = b2_dynamicBody; this->setTag(tag_piece); info.friction = 0.5f; info.density = 1.0f; info.restitution = 0.5f; info.linearVelocityY = 5.0f; info.categoryBit = CATEGORY_SONTEPIECE; info.maskBit = CATEGORY_SCENE; this->setPosition(pos.x, pos.y); if (piece == piece1) { info.linearVelocityX = -1.0f; info.angularVelocity = 0.1f; } else { info.linearVelocityX = 1.0f; info.angularVelocity = -0.1f; } } info.userData = this; //[self attachBodyToWorld : info : world); this->attachBodyToWorld(info, world); } if (type != Platform_Breakable) msetScale(this, RATIO_XY); return this; }