码迷,mamicode.com
首页 > 其他好文 > 详细

cocos2d学习笔记

时间:2016-08-30 00:02:58      阅读:178      评论:0      收藏:0      [点我收藏+]

标签:

    //粒子系统,使用系统自己的粒子系统的书写方法
    if(!CCLayer::init()) return false;
    CCTexture2D* fire=CCTextureCache::sharedTextureCache()->addImage("fire.png");
    CCParticleSystem* firePartical = CCParticleFire::create();
    firePartical->setTexture(fire);
    this->addChild(firePartical);
    firePartical->setPosition(ccp(100,100));
    
    //自定义粒子系统的使用方法,需要plist文件,plist通过对应的编辑器获取
    if(!CCLayer::init()) return false;
    ParticleSystemQuad* system = ParticleSystemQuad::create("BoilingFoam.plist");
    system->setTextureWithRect(Director::getInstance()->getTextureCache()->addImage("fire.png"), Rect(0, 0, 64, 64));
    this->addChild(system);
    system->setPosition(300,300);
    system->retain();
    
    //精灵使用方法,下面为设置100个精灵随机加载到420*420的位置
    for (int i = 0; i < 100; i++)
    {
        CCSprite* pSprite = CCSprite::create("tp_4.png");
        CC_BREAK_IF(!pSprite);
        pSprite->setPosition(ccp(CCRANDOM_0_1()*420,CCRANDOM_0_1()*420));
        this->addChild(pSprite);
    }
    
    //精灵纹理集使用方法
    CCSpriteBatchNode* ccSprite = CCSpriteBatchNode::create("tp_4.png");
    if (!ccSprite) return false;
    this->addChild(ccSprite);
    for (int i = 0; i < 100; i++)
    {
        CCSprite* ccsprite2 = CCSprite::createWithTexture(ccSprite->getTexture());
        ccsprite2->setPosition(ccp(CCRANDOM_0_1() * 600, CCRANDOM_0_1() * 600));
        ccSprite->addChild(ccsprite2);
    }
    
    //显示helloworld
     //   
 //   Size visibleSize = Director::getInstance()->getVisibleSize();
 //   Vec2 origin = Director::getInstance()->getVisibleOrigin();
    //
 //   /////////////////////////////
 //   // 2. add a menu item with "X" image, which is clicked to quit the program
 //   //    you may modify it.

 //   // add a "close" icon to exit the progress. it‘s an autorelease object
 //   auto closeItem = MenuItemImage::create(
 //                                          "CloseNormal.png",
 //                                          "CloseSelected.png",
 //                                          CC_CALLBACK_1(HelloWorld::menuCloseCallback, this));
 //   
    //closeItem->setPosition(Vec2(origin.x + visibleSize.width - closeItem->getContentSize().width/2 ,
 //                               origin.y + closeItem->getContentSize().height/2));
 //   // create menu, it‘s an autorelease object
 //   auto menu = Menu::create(closeItem, NULL);
 //   menu->setPosition(Vec2::ZERO);
 //   this->addChild(menu, 1);

 //   /////////////////////////////
 //   // 3. add your codes below...

 //   // add a label shows "Hello World"
 //   // create and initialize a label

 //   auto label = Label::createWithTTF("my app ", "fonts/Marker Felt.ttf", 24);
 //   
 //   // position the label on the center of the screen
 //   label->setPosition(Vec2(origin.x + visibleSize.width/2,
 //                           origin.y + visibleSize.height - label->getContentSize().height));

 //   // add the label as a child to this layer
 //   this->addChild(label, 1);

 //   // add "HelloWorld" splash screen"
 //   auto sprite = Sprite::create("HelloWorld.png");

 //   // position the sprite on the center of the screen
 //   sprite->setPosition(Vec2(visibleSize.width/2 + origin.x, visibleSize.height/2 + origin.y));

 //   // add the sprite as a child to this layer
 //   this->addChild(sprite, 0);
 //   
 //   return true;

 

cocos2d学习笔记

标签:

原文地址:http://www.cnblogs.com/weifengxiyu/p/5820149.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!