2011-11-17 10:10:13 +08:00
|
|
|
// enable log
|
|
|
|
#define COCOS2D_DEBUG 1
|
|
|
|
|
|
|
|
#include "TextureCacheTest.h"
|
|
|
|
|
2012-06-14 05:19:13 +08:00
|
|
|
USING_NS_CC;
|
2011-11-21 12:04:21 +08:00
|
|
|
|
2011-11-17 10:10:13 +08:00
|
|
|
TextureCacheTest::TextureCacheTest()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _numberOfSprites(20)
|
|
|
|
, _numberOfLoadedSprites(0)
|
2011-11-17 10:10:13 +08:00
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_labelLoading = CCLabelTTF::create("loading...", "Arial", 15);
|
|
|
|
_labelPercent = CCLabelTTF::create("%0", "Arial", 15);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_labelLoading->setPosition(ccp(size.width / 2, size.height / 2 - 20));
|
|
|
|
_labelPercent->setPosition(ccp(size.width / 2, size.height / 2 + 20));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
this->addChild(_labelLoading);
|
|
|
|
this->addChild(_labelPercent);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// load textrues
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/HelloWorld.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_01.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_02.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_03.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_04.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_05.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_06.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_07.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_08.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_09.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_10.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_11.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_12.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_13.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/grossini_dance_14.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background1.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background2.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/background3.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
|
|
|
CCTextureCache::sharedTextureCache()->addImageAsync("Images/blocks.png", this, callfuncO_selector(TextureCacheTest::loadingCallBack));
|
2011-11-17 10:10:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCacheTest::loadingCallBack(CCObject *obj)
|
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
++_numberOfLoadedSprites;
|
2012-04-19 14:35:52 +08:00
|
|
|
char tmp[10];
|
2013-06-15 14:03:30 +08:00
|
|
|
sprintf(tmp,"%%%d", (int)(((float)_numberOfLoadedSprites / _numberOfSprites) * 100));
|
|
|
|
_labelPercent->setString(tmp);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_numberOfLoadedSprites == _numberOfSprites)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
this->removeChild(_labelLoading, true);
|
|
|
|
this->removeChild(_labelPercent, true);
|
2012-04-19 14:35:52 +08:00
|
|
|
addSprite();
|
|
|
|
}
|
2011-11-17 10:10:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void TextureCacheTest::addSprite()
|
|
|
|
{
|
2012-04-19 14:35:52 +08:00
|
|
|
CCSize size = CCDirector::sharedDirector()->getWinSize();
|
|
|
|
|
|
|
|
// create sprites
|
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite *bg = CCSprite::create("Images/HelloWorld.png");
|
2012-10-23 17:48:50 +08:00
|
|
|
bg->setPosition(ccp(size.width / 2, size.height / 2));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite *s1 = CCSprite::create("Images/grossini.png");
|
|
|
|
CCSprite *s2 = CCSprite::create("Images/grossini_dance_01.png");
|
|
|
|
CCSprite *s3 = CCSprite::create("Images/grossini_dance_02.png");
|
|
|
|
CCSprite *s4 = CCSprite::create("Images/grossini_dance_03.png");
|
|
|
|
CCSprite *s5 = CCSprite::create("Images/grossini_dance_04.png");
|
|
|
|
CCSprite *s6 = CCSprite::create("Images/grossini_dance_05.png");
|
|
|
|
CCSprite *s7 = CCSprite::create("Images/grossini_dance_06.png");
|
|
|
|
CCSprite *s8 = CCSprite::create("Images/grossini_dance_07.png");
|
|
|
|
CCSprite *s9 = CCSprite::create("Images/grossini_dance_08.png");
|
|
|
|
CCSprite *s10 = CCSprite::create("Images/grossini_dance_09.png");
|
|
|
|
CCSprite *s11 = CCSprite::create("Images/grossini_dance_10.png");
|
|
|
|
CCSprite *s12 = CCSprite::create("Images/grossini_dance_11.png");
|
|
|
|
CCSprite *s13 = CCSprite::create("Images/grossini_dance_12.png");
|
|
|
|
CCSprite *s14 = CCSprite::create("Images/grossini_dance_13.png");
|
|
|
|
CCSprite *s15 = CCSprite::create("Images/grossini_dance_14.png");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
// just loading textures to slow down
|
2012-06-14 15:13:16 +08:00
|
|
|
CCSprite::create("Images/background1.png");
|
|
|
|
CCSprite::create("Images/background2.png");
|
|
|
|
CCSprite::create("Images/background3.png");
|
|
|
|
CCSprite::create("Images/blocks.png");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2012-10-23 17:48:50 +08:00
|
|
|
s1->setPosition(ccp(50, 50));
|
|
|
|
s2->setPosition(ccp(60, 50));
|
|
|
|
s3->setPosition(ccp(70, 50));
|
|
|
|
s4->setPosition(ccp(80, 50));
|
|
|
|
s5->setPosition(ccp(90, 50));
|
|
|
|
s6->setPosition(ccp(100, 50));
|
|
|
|
|
|
|
|
s7->setPosition(ccp(50, 180));
|
|
|
|
s8->setPosition(ccp(60, 180));
|
|
|
|
s9->setPosition(ccp(70, 180));
|
|
|
|
s10->setPosition(ccp(80, 180));
|
|
|
|
s11->setPosition(ccp(90, 180));
|
|
|
|
s12->setPosition(ccp(100, 180));
|
|
|
|
|
|
|
|
s13->setPosition(ccp(50, 270));
|
|
|
|
s14->setPosition(ccp(60, 270));
|
|
|
|
s15->setPosition(ccp(70, 270));
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
this->addChild(bg);
|
2011-11-17 10:10:13 +08:00
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(s1);
|
2011-11-17 10:10:13 +08:00
|
|
|
this->addChild(s2);
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(s3);
|
|
|
|
this->addChild(s4);
|
|
|
|
this->addChild(s5);
|
|
|
|
this->addChild(s6);
|
|
|
|
this->addChild(s7);
|
|
|
|
this->addChild(s8);
|
|
|
|
this->addChild(s9);
|
2011-11-17 10:10:13 +08:00
|
|
|
this->addChild(s10);
|
2012-04-19 14:35:52 +08:00
|
|
|
this->addChild(s11);
|
|
|
|
this->addChild(s12);
|
|
|
|
this->addChild(s13);
|
|
|
|
this->addChild(s14);
|
|
|
|
this->addChild(s15);
|
2011-11-17 10:10:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void TextureCacheTestScene::runThisTest()
|
|
|
|
{
|
|
|
|
CCLayer* pLayer = new TextureCacheTest();
|
|
|
|
addChild(pLayer);
|
|
|
|
|
|
|
|
CCDirector::sharedDirector()->replaceScene(this);
|
|
|
|
pLayer->release();
|
|
|
|
}
|