Ejemplo n.º 1
0
Coin * Coin::create(Vec2 position, GameStates & gameState)
{
	std::shared_ptr<GameData> ptr = GameData::sharedGameData();

	auto spritecache = SpriteFrameCache::getInstance();
	spritecache->addSpriteFramesWithFile(ptr->m_textureAtlasPlistFile);		

	Coin* pSprite = new Coin(gameState);
	if (pSprite->initWithSpriteFrameName(ptr->m_coinFile))
	{
		pSprite->autorelease();
		

		pSprite->initOptions(position);

		pSprite->addEvents();
		pSprite->setTag(30);

		auto towerBody = PhysicsBody::createBox(pSprite->getContentSize());
		towerBody->setCollisionBitmask(0x000003);
		towerBody->setContactTestBitmask(true);
		towerBody->setTag(30);
		//towerBody->setDynamic(false);

		pSprite->setPhysicsBody(towerBody);

		return pSprite;
	}

	CC_SAFE_DELETE(pSprite);
	return NULL;
}
Ejemplo n.º 2
0
// on "init" you need to initialize your instance
bool Interface::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    /////////////////////////////
    // 3. add your codes below...
    
    // add a label shows "Hello World"
    // create and initialize a label
    
    CCLabelTTF* pLabel = CCLabelTTF::create("0", "Arial", TITLE_FONT_SIZE);
    
    pLabel->setAnchorPoint(ccp(0.0f, 0.5f));
    
    // position the label on the center of the screen
    pLabel->setPosition(ccp(origin.x + visibleSize.width/2,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));
    
    pLabel->setTag(10);
    
    // add the label as a child to this layer
    this->addChild(pLabel, 1);
    
    Coin* coin = Coin::create();
    coin->setAnchorPoint(ccp(0.5f, 0.5f));
    coin->setScale(2.0f);
    coin->setPosition(ccp((origin.x + visibleSize.width/2) - coin->getContentSize().width,
                              origin.y + visibleSize.height - pLabel->getContentSize().height));
    
    // add the sprite as a child to this layer
    this->addChild(coin, 2);
    
    
    CCLabelTTF* parachuteLabel = CCLabelTTF::create("10 sec", "Arial", TITLE_FONT_SIZE);
    
    parachuteLabel->setAnchorPoint(ccp(0.0f, 0.5f));
    
#ifdef CC_TARGET_OS_MAC
    // position the label on the center of the screen
    parachuteLabel->setPosition(ccp(50.0f,
                            origin.y + visibleSize.height - pLabel->getContentSize().height));
#endif
    
#ifdef OUYA_BUILD
    // position the label on the center of the screen
    parachuteLabel->setPosition(ccp(60.0f,
                                    origin.y + visibleSize.height - pLabel->getContentSize().height));
#endif
    
    parachuteLabel->setTag(20);
    
    // add the label as a child to this layer
    this->addChild(parachuteLabel, 1);
    
    
    Parachute* parachute = Parachute::create();
    parachute->setAnchorPoint(ccp(0.5f, 0.5f));
    parachute->setScale(1.0f);
#ifdef CC_TARGET_OS_MAC
    parachute->setPosition(ccp((50.0f) - parachute->getContentSize().width / 2.0f,
                               origin.y + visibleSize.height - pLabel->getContentSize().height));
#endif
#ifdef OUYA_BUILD
    parachute->setPosition(ccp((60.0f) - parachute->getContentSize().width / 2.0f,
                          origin.y + visibleSize.height - pLabel->getContentSize().height));
#endif
    // add the sprite as a child to this layer
    this->addChild(parachute, 3);
    
    return true;
}