Skip to content

Instantly share code, notes, and snippets.

@tks2shimizu
Created January 13, 2013 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tks2shimizu/4524293 to your computer and use it in GitHub Desktop.
Save tks2shimizu/4524293 to your computer and use it in GitHub Desktop.
1000匹のネコ (1)CCSprite
#include "HelloWorldScene.h"
#include "SimpleAudioEngine.h"
using namespace cocos2d;
using namespace CocosDenshion;
CCScene* HelloWorld::scene()
{
CCScene *scene = CCScene::create();
HelloWorld *layer = HelloWorld::create();
scene->addChild(layer);
return scene;
}
bool HelloWorld::init()
{
if ( !CCLayer::init() )
{
return false;
}
srand((unsigned)time(NULL));
usingSprite();
return true;
}
void HelloWorld::usingSprite()
{
CCSize winSize = CCDirector::sharedDirector()->getWinSize();
start = clock();
for (int i = 0; i < 1000; i++) {
int random = rand();
// ふつうの表示
CCString* fileName = CCString::createWithFormat("cat00.png", i);
CCSprite* cat = CCSprite::create(fileName->getCString());
cat->setPosition(ccp(random % (int)winSize.width,
random % (int)winSize.height));
this->addChild(cat);
}
CCLog("%f", (double)(clock() - start) / CLOCKS_PER_SEC);
}
//#ifndef __HELLOWORLD_SCENE_H__
//#define __HELLOWORLD_SCENE_H__
#include "cocos2d.h"
class HelloWorld : public cocos2d::CCLayer
{
private:
clock_t start;
void usingSprite();
public:
virtual bool init();
static cocos2d::CCScene* scene();
CREATE_FUNC(HelloWorld);
};
//#endif // __HELLOWORLD_SCENE_H__
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment