第一个cocos2d-x程序
来源:未知 责任编辑:责任编辑 发表时间:2013-12-18 11:33 点击:次
目的:在界面上显示3个精灵。
p>
p>做法:创建一个cocos2dx项目之后重写 init( ) 方法。代码段如下:
p>
p>[objc
p>// on "init" you need to initialize your instance
p>
p>bool HelloWorld::init()
p>
p>{
p>
p> //////////////////////////////
p>
p> // 1. super init first
p>
p> if ( !CCLayer::init() )
p>
p> {
p>
p> return false;
p>
p> }
p>
p>
p>
p>// CCSprite *bg = CCSprite::create("Icon.png");
p>
p>// bg->setAnchorPoint(CCPointZero);
p>
p>// bg->setPosition(CCPointZero);
p>
p>// this->addChild(bg);
p>
p>//
p>
p>// CCSprite *Player = CCSprite::create("Player.png");
p>
p>// Player->setAnchorPoint(CCPointZero);
p>
p>// Player->setPosition(ccp(50,150));
p>
p>// this->addChild(Player);
p>
p>//
p>
p>// CCSprite *Projectile = CCSprite::create("Projectile.png");
p>
p>// Projectile->setAnchorPoint(CCPointZero);
p>
p>// Projectile->setPosition(ccp(200, 150));
p>
p>// this->addChild(Projectile);
p>
p>//
p>
p>// CCSprite *Target = CCSprite::create("Target.png");
p>
p>// Target->setAnchorPoint(CCPointZero);
p>
p>// Target->setPosition(ccp(350,150));
p>
p>// this->addChild(Target);
p>
p>
p>
p> images_dictionary = CCDictionary::createWithContentsOfFile("hand02.plist");
p>
p> images_array = (CCArray *)images_dictionary->objectForKey("imagesArray");
p>
p>
p>
p> for (int i = 0; i < images_array->count(); i++) {
p>
p> CCString *string = (CCString *)images_array->objectAtIndex(i);
p>
p> CCSprite *sprite = CCSprite::create(string->getCString());
p>
p> sprite->setAnchorPoint(CCPointZero);
相关新闻>>
最新推荐更多>>>
- 发表评论
-
- 最新评论 更多>>