第一个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);  
发表评论
请自觉遵守互联网相关的政策法规,严禁发布色情、暴力、反动的言论。
用户名: 验证码:点击我更换图片
最新评论 更多>>

推荐热点

  • cocos2d-x学习笔记(19)--label 、label atlas
  • cocos2d-x学习笔记(23)--地图的使用3--CCTMXLayer
  • Cocos2d-x学习(一):HelloWorld
  • cocos2dx在xcode下开发,编译到android上(2)
  • cocos2d 设置屏幕默认方向
  • cocos2d-x学习笔记(22)--地图的使用2(TMX) --Z-Order、AnchorPoi
  • Cocos2d-x 2.0 之 Actions “三板斧” 之一
  • cocos2d-x学习笔记(18)--游戏打包(windows平台)
  • cocos2d-x学习笔记(16)--spritesheet(精灵表单)
网站首页 - 友情链接 - 网站地图 - TAG标签 - RSS订阅 - 内容搜索
Copyright © 2008-2015 计算机技术学习交流网. 版权所有

豫ICP备11007008号-1