首页 > 程序开发 > 移动开发 > 其他 >

第一个cocos2d-x程序

2013-11-29

目的:在界面上显示3个精灵。做法:创建一个cocos2dx项目之后重写 init( ) 方法。代码段如下:[objc on "init" you need to initialize your instance bool HelloWorld::init() {

目的:在界面上显示3个精灵。
做法:创建一个cocos2dx项目之后重写 init( ) 方法。代码段如下:
[objc
// on "init" you need to initialize your instance
bool HelloWorld::init()
{
//////////////////////////////
// 1. super init first
if ( !CCLayer::init() )
{
return false;
}
// CCSprite *bg = CCSprite::create("Icon.png");
// bg->setAnchorPoint(CCPointZero);
// bg->setPosition(CCPointZero);
// this->addChild(bg);
//
// CCSprite *Player = CCSprite::create("Player.png");
// Player->setAnchorPoint(CCPointZero);
// Player->setPosition(ccp(50,150));
// this->addChild(Player);
//
// CCSprite *Projectile = CCSprite::create("Projectile.png");
// Projectile->setAnchorPoint(CCPointZero);
// Projectile->setPosition(ccp(200, 150));
// this->addChild(Projectile);
//
// CCSprite *Target = CCSprite::create("Target.png");
// Target->setAnchorPoint(CCPointZero);
// Target->setPosition(ccp(350,150));
// this->addChild(Target);
images_dictionary = CCDictionary::createWithContentsOfFile("hand02.plist");
images_array = (CCArray *)images_dictionary->objectForKey("imagesArray");
for (int i = 0; i < images_array->count(); i++) {
CCString *string = (CCString *)images_array->objectAtIndex(i);
CCSprite *sprite = CCSprite::create(string->getCString());
sprite->setAnchorPoint(CCPointZero);
sprite->setPosition(ccp(200 + 100*i, 300));
this->addChild(sprite);
}
return true;
}
相关文章
最新文章
热点推荐