// on "init" you need to initialize your instance
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !CCLayer::init() )
    {
        return false;
    }
    
    CCTextureCache *cache = CCTextureCache::sharedTextureCache();
    //support spx
    spx = CCSPXSprite::create("spx_test.sprite", cache->addImage("spx_test.png"), 0);
    spx->setPosition(ccp(200,200));
    addChild(spx);
    
    //support spx3
    spx3 = CCSPX3Sprite::create("spx3_test.sprite", 0, cache->addImage("spx3_test.png"),NULL);
    spx3->setPosition(ccp(200, 100));
    spx3->setLoopCount(-1);
    addChild(spx3);
    
    setTouchEnabled(true);
    scheduleUpdate();
    
    return true;
}
////////////////////////////////////////////////////////
//
// TextureTest
//
////////////////////////////////////////////////////////
void TextureTest::performTestsPNG(const char* filename)
{
    struct timeval now;
    CCTexture2D *texture;
    CCTextureCache *cache = CCTextureCache::sharedTextureCache();

    CCLog("RGBA 8888");
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
    gettimeofday(&now, NULL);
    texture = cache->addImage(filename);
    if( texture )
        CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    else
        CCLog(" ERROR\n");
    cache->removeTexture(texture);

    //CCLog("RGBA 4444");
    //CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
    //gettimeofday(&now, NULL);
    //texture = cache->addImage(filename);
    //if( texture )
    //    CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    //else
    //    CCLog(" ERROR\n");
    //cache->removeTexture(texture);

 /*   CCLog("RGBA 5551");
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB5A1);
    gettimeofday(&now, NULL);
    texture = cache->addImage(filename);
    if( texture )
        CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    else
        CCLog(" ERROR\n");
    cache->removeTexture(texture);*/

    CCLog("RGB 565");
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGB565);
    gettimeofday(&now, NULL);	
    texture = cache->addImage(filename);
    if( texture )
        CCLog("  ms:%f\n", calculateDeltaTime(&now) );
    else
        CCLog(" ERROR\n");
    cache->removeTexture(texture);

	// restore default
    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);

}
//------------------------------------------------------------------
//
// Arctic
//
//------------------------------------------------------------------
void AnimArctic::onEnter()
{
    AnimDemo::onEnter();
    
    // surface
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    // texture
    CCTextureCache* tc = CCTextureCache::sharedTextureCache();
    CCTexture2D* tex1 = tc->addImage("Files/fighterboby001.png");
    CCTexture2D* tex2 = tc->addImage("Files/fighterarmor001.png");
    CCTexture2D* tex3 = tc->addImage("Files/fighterweapon001.png");
    
    // animation 1
    m_sprite1 = CCArcticSprite::create("Files/fighter.aspr", 0, tex1, tex2, tex3, NULL);
    m_sprite1->setLoopCount(-1);
    m_sprite1->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 3 / 4));
    m_sprite1->setUnitInterval(0.1f);
    m_sprite1->setDebugDrawFrameRect(true);
    m_sprite1->setDebugDrawCollisionRect(true);
    addChild(m_sprite1);
    
    // animation 2
    m_sprite2 = CCArcticSprite::create("Files/fighter.aspr", 1, tex1, tex2, tex3, NULL);
    m_sprite2->setLoopCount(-1);
    m_sprite2->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 2 / 4));
    m_sprite2->setUnitInterval(0.1f);
    m_sprite2->setDebugDrawFrameRect(true);
    m_sprite2->setDebugDrawCollisionRect(true);
    addChild(m_sprite2);
    
    // animation 3
    m_sprite3 = CCArcticSprite::create("Files/fighter.aspr", 2, tex1, tex2, tex3, NULL);
    m_sprite3->setLoopCount(-1);
    m_sprite3->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height / 4));
    m_sprite3->setUnitInterval(0.1f);
    m_sprite3->setDebugDrawFrameRect(true);
    m_sprite3->setDebugDrawCollisionRect(true);
    addChild(m_sprite3);
    
    scheduleUpdate();
    
    setTouchEnabled(true);
    setTouchMode(kCCTouchesOneByOne);
}
Example #4
0
bool CImageWidget::setPorperty( const std::string& key,const std::string& strvalue )
{
	bool ret = true;
	do 
	{
		ret = CBaseWidget::setPorperty(key,strvalue);
		if (ret)
		{
			break;
		}

		if (key == CImageWidget::IMAGE_PIC)
		{
			CCTextureCache* pCache = CCTextureCache::sharedTextureCache();
			CCTexture2D* pPic = pCache->addImage(strvalue.c_str());
			this->setPic(pPic);
		}
		else
		{
			ret = false;
		}
	} while (0);

	return ret;
}
//------------------------------------------------------------------
//
// Clip Mapping (Aurora GT)
//
//------------------------------------------------------------------
void AnimClipMappingAuroraGT::onEnter()
{
    AnimDemo::onEnter();
    
    // surface
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    // texture
    CCTextureCache* tc = CCTextureCache::sharedTextureCache();
    CCTexture2D* tex = tc->addImage("Files/prince.png");
    
    // animation 1
    m_sprite1 = CCAuroraSprite::create("Files/prince.bsprite", 78, tex, NULL);
    m_sprite1->setLoopCount(-1);
    m_sprite1->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height / 2));
    m_sprite1->setUnitInterval(0.1f);
    m_sprite1->setDebugDrawFrameRect(true);
    m_sprite1->setDebugDrawCollisionRect(true);
    addChild(m_sprite1);
    
    // create clip mapping and add them to sprite
    CCAFCClipMapping* mapping = CCAFCClipMapping::createWithAuroraGT(1, "Files/prince_m00.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(2, "Files/prince_m01.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(3, "Files/prince_m02.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(4, "Files/prince_m03.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(5, "Files/prince_m04.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(6, "Files/prince_m05.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(7, "Files/prince_m06.mmp");
    m_sprite1->addClipMapping(mapping);
    mapping = CCAFCClipMapping::createWithAuroraGT(8, "Files/prince_m07.mmp");
    m_sprite1->addClipMapping(mapping);
    
    CCLabelTTF* label = CCLabelTTF::create("Switch Clip Mapping", "Helvetica", 16);
    CCMenuItemLabel* item = CCMenuItemLabel::create(label,
                                                    this,
                                                    menu_selector(AnimClipMappingAuroraGT::onSwitchClipMapping));
    item->setPosition(ccp(origin.x + visibleSize.width / 2,
                          origin.y + visibleSize.height / 7));
    CCMenu* menu = CCMenu::create(item, NULL);
    menu->setPosition(CCPointZero);
    addChild(menu);
    
    scheduleUpdate();
    
    setTouchEnabled(true);
    setTouchMode(kCCTouchesOneByOne);
}
//------------------------------------------------------------------
//
// Aurora GT
//
//------------------------------------------------------------------
void AnimAuroraGT::onEnter()
{
    AnimDemo::onEnter();
    
    // surface
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    // texture
    CCTextureCache* tc = CCTextureCache::sharedTextureCache();
    CCTexture2D* tex = tc->addImage("Files/prince.png");
    
    // animation 1
    m_sprite1 = CCAuroraSprite::create("Files/prince.bsprite", 78, tex, NULL);
    m_sprite1->setLoopCount(-1);
    m_sprite1->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 3 / 4));
    m_sprite1->setUnitInterval(0.1f);
    m_sprite1->setDebugDrawFrameRect(true);
    m_sprite1->setDebugDrawCollisionRect(true);
    addChild(m_sprite1);
    
    // animation 2
    m_sprite2 = CCAuroraSprite::create("Files/prince.bsprite", 99, tex, NULL);
    m_sprite2->setLoopCount(-1);
    m_sprite2->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 2 / 4));
    m_sprite2->setUnitInterval(0.1f);
    m_sprite2->setDebugDrawFrameRect(true);
    m_sprite2->setDebugDrawCollisionRect(true);
    addChild(m_sprite2);
    
    // animation 3
    m_sprite3 = CCAuroraSprite::create("Files/prince.bsprite", 66, tex, NULL);
    m_sprite3->setLoopCount(-1);
    m_sprite3->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height / 4));
    m_sprite3->setUnitInterval(0.1f);
    m_sprite3->setDebugDrawFrameRect(true);
    m_sprite3->setDebugDrawCollisionRect(true);
    addChild(m_sprite3);
    
    scheduleUpdate();
    
    setTouchEnabled(true);
    setTouchMode(kCCTouchesOneByOne);
}
//------------------------------------------------------------------
//
// SpriteX 2011
//
//------------------------------------------------------------------
void AnimSpriteX2011::onEnter()
{
    AnimDemo::onEnter();
    
    // surface
    CCSize visibleSize = CCDirector::sharedDirector()->getVisibleSize();
    CCPoint origin = CCDirector::sharedDirector()->getVisibleOrigin();
    
    // texture
    CCTextureCache* tc = CCTextureCache::sharedTextureCache();
    CCTexture2D* tex = tc->addImage("Files/spx3_test.png");
    
    // animation 1
    // SpriteX doesn't support tick mode, but you can use setForceTickMode
    // to enforce using tick mode. this animation use a large unit interval
    // so the animation plays slow
    m_sprite1 = CCSPX3Sprite::create("Files/spx3_test.sprite", 0, tex, NULL);
    m_sprite1->setLoopCount(-1);
    m_sprite1->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 7 / 8));
    m_sprite1->setForceTickMode(true);
    m_sprite1->setUnitInterval(0.5f);
    addChild(m_sprite1);
    
    // animation 2
    m_sprite2 = CCSPX3Sprite::create("Files/spx3_test.sprite", 1, tex, NULL);
    m_sprite2->setLoopCount(-1);
    m_sprite2->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 6 / 8));
    addChild(m_sprite2);
    
    // animation 3, 反着放
    m_sprite3 = CCSPX3Sprite::create("Files/spx3_test.sprite", 2, tex, NULL);
    m_sprite3->setLoopCount(-1);
    m_sprite3->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 5 / 8));
    m_sprite3->setReverse(true);
    addChild(m_sprite3);
    
    // animation 4
    m_sprite4 = CCSPX3Sprite::create("Files/spx3_test.sprite", 3, tex, NULL);
    m_sprite4->setLoopCount(-1);
    m_sprite4->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 4 / 8));
    addChild(m_sprite4);
    
    // animation 5, y轴倒转播放
    m_sprite5 = CCSPX3Sprite::create("Files/spx3_test.sprite", 4, tex, NULL);
    m_sprite5->setLoopCount(-1);
    m_sprite5->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 3 / 8));
    m_sprite5->setFlipY(true);
    addChild(m_sprite5);
    
    // animation 6
    m_sprite6 = CCSPX3Sprite::create("Files/spx3_test.sprite", 5, tex, NULL);
    m_sprite6->setLoopCount(-1);
    m_sprite6->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height * 2 / 8));
    addChild(m_sprite6);
    
    // animation 7
    m_sprite7 = CCSPX3Sprite::create("Files/spx3_test.sprite", 6, tex, NULL);
    m_sprite7->setLoopCount(-1);
    m_sprite7->setPosition(ccp(origin.x + visibleSize.width / 2,
                               origin.y + visibleSize.height / 8));
    addChild(m_sprite7);
    
    scheduleUpdate();
    
    setTouchEnabled(true);
    setTouchMode(kCCTouchesOneByOne);
}
void SubTest::initWithSubTest(int nSubTest, CCNode* p)
{
    subtestNumber = nSubTest;
    parent = p;
    batchNode = NULL;
    /*
    * Tests:
    * 1: 1 (32-bit) PNG sprite of 52 x 139
    * 2: 1 (32-bit) PNG Batch Node using 1 sprite of 52 x 139
    * 3: 1 (16-bit) PNG Batch Node using 1 sprite of 52 x 139
    * 4: 1 (4-bit) PVRTC Batch Node using 1 sprite of 52 x 139

    * 5: 14 (32-bit) PNG sprites of 85 x 121 each
    * 6: 14 (32-bit) PNG Batch Node of 85 x 121 each
    * 7: 14 (16-bit) PNG Batch Node of 85 x 121 each
    * 8: 14 (4-bit) PVRTC Batch Node of 85 x 121 each

    * 9: 64 (32-bit) sprites of 32 x 32 each
    *10: 64 (32-bit) PNG Batch Node of 32 x 32 each
    *11: 64 (16-bit) PNG Batch Node of 32 x 32 each
    *12: 64 (4-bit) PVRTC Batch Node of 32 x 32 each
    */

    // purge textures
    CCTextureCache *mgr = CCTextureCache::sharedTextureCache();
    //        [mgr removeAllTextures];
    mgr->removeTexture(mgr->addImage("Images/grossinis_sister1.png"));
    mgr->removeTexture(mgr->addImage("Images/grossini_dance_atlas.png"));
    mgr->removeTexture(mgr->addImage("Images/spritesheet1.png"));

    switch ( subtestNumber)
    {
        case 1:
        case 4:
        case 7:
            break;
            ///
        case 2:
            CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
            batchNode = CCSpriteBatchNode::create("Images/grossinis_sister1.png", 100);
            p->addChild(batchNode, 0);
            break;
        case 3:
            CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
            batchNode = CCSpriteBatchNode::create("Images/grossinis_sister1.png", 100);
            p->addChild(batchNode, 0);
            break;

            ///
        case 5:
            CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
            batchNode = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
            p->addChild(batchNode, 0);
            break;                
        case 6:
            CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
            batchNode = CCSpriteBatchNode::create("Images/grossini_dance_atlas.png", 100);
            p->addChild(batchNode, 0);
            break;

            ///
        case 8:
            CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA8888);
            batchNode = CCSpriteBatchNode::create("Images/spritesheet1.png", 100);
            p->addChild(batchNode, 0);
            break;
        case 9:
            CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_RGBA4444);
            batchNode = CCSpriteBatchNode::create("Images/spritesheet1.png", 100);
            p->addChild(batchNode, 0);
            break;

        default:
            break;
    }

    if (batchNode)
    {
        batchNode->retain();
    }

    CCTexture2D::setDefaultAlphaPixelFormat(kCCTexture2DPixelFormat_Default);
}
Example #9
0
/**
*   初始化操作
*/
bool YJTabTitle::initWithString(const char* normalImageName, const char* selectedImageName, YJTabTitleState state, 
						const char* displayText, const char *fontName, float fontSize, CCObject* target, SEL_CallFuncN selector) 
{
	if(!normalImageName)
	{
		return false ;
	}

	if(!selectedImageName)
	{
		return false ;
	}

	if(kStateNormal!=state && kStateSelected!=state)
	{
		return false ;
	}

	if(!displayText)
	{
		return false ;
	}

	if(!fontName)
	{
		return false ;
	}

	this->normalImageName = normalImageName ;
	this->selectedImageName = selectedImageName ;
	this->displayText = displayText ;
	this->fontName = fontName ;
	this->fontSize = fontSize ;

	this->state = state ;	// 设置状态
	this->setTarget(target, selector) ; // 设置回到函数

	CCTextureCache* textureCache = CCTextureCache::sharedTextureCache() ;
	std::string initImageName ;
	if( kStateNormal == state)
	{
		initImageName = normalImageName ;
	}
	else if(kStateSelected == state)
	{
		initImageName = selectedImageName ;
	}

	this->bgSprite = CCSprite::createWithTexture(textureCache->addImage(initImageName.c_str())) ;

	this->bgSprite->setAnchorPoint(ccp(0, 0)) ;
	this->bgSprite->setPosition(ccp(0, 0)) ;
	this->setContentSize(this->bgSprite->getContentSize()) ;
	this->addChild(this->bgSprite, 0) ;

	this->label = CCLabelTTF::create(this->displayText.c_str(), this->fontName.c_str(), this->fontSize) ;
	this->label->setAnchorPoint(ccp(0.5, 0.5)) ;
	this->label->setPosition(ccp(this->getContentSize().width/2, this->getContentSize().height/2)) ;
	this->addChild(this->label, 1) ;

	return true ;
}