cocos2d学习笔记

    //粒子系统,使用系统自己的粒子系统的书写方法
    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;
时间: 2024-08-06 03:24:17

cocos2d学习笔记的相关文章

Cocos2D学习笔记(1)- 常用的类

1.坐标系 >屏幕坐标系(UIKit):原点在左上角! >OpenGl坐标系:原点在屏幕的左下角! 2.游戏设计:Director--Scene--Layer--Sprite. >CCDirector:导演类,相当于是游戏策划,负责整个游戏的布局和运行规则的制定. >CCScene:场景类,每个场景可以是一个界面或一个关卡. >CCLayer:图层类,为了方便游戏界面的渲染管理. >CCSprite:精灵类, 小结:一个导演类(CCDirector)可以指挥多个场景类(

COCOS2D 学习笔记

cc.Node.scheduleUpdate:function () * schedules the "update" method. * It will use the order number 0. This method will be called every frame. * Scheduled methods with a lower order value will be called before the ones that have a higher order va

Cocos2d学习笔记2——cocos命令行指令使用

搭建好cocos2dx环境后,可以使用cocos指令来新建cocos2dx项目.编译运行cocos2dx项目等. 先来看看cocos2dx-3.x版本的目录. 在该目录下,按住shift键的同时右击鼠标,即按住shift+鼠标右键,点击在此处打开命令窗口. 在打开的命令窗口中,输入cocos -help指令,可以查看cocos的所有相关指令,如编译指令compile,创建项目指令new等. 输入cocos compile -help可以查看编译指令用到的所有参数及参数具体含义. 其他cocos指

IOS cocos2d学习笔记

更新到 xcode6之后,发现没有原来的  empty  application了  习惯又要被改变了. 下面是解决的方法: 1.新建一个single view application2.打开 Info.plist,删除里面的  Launch screen interface file....以及 Main storyboard file base name...3.删除Main.storyboard以及LaunchScreen.xib4.在AppDelegate.m修改如下(其中MainVie

cocos2d-js引擎学习笔记

Scale9Sprite 在用Scale9Sprite.create的时候出现Uncaught TypeError: Cannot call method 'create' of undefined这个错误, 后来发现在默认情况下,project.json里的modules只自带cocos2d模块,通过检查frameworks/cocos2d-html5/moduleConfig.json,可以看到cocos2d模块里并没有CCScale9Sprite.js这个类. 它在GUI里,所以可以在mo

cocos2dx游戏开发学习笔记2-从helloworld开始

一.新建工程 具体安装和新建工程的方法在cocos2dx目录下的README.md文件中已经有详细说明,这里只做简单介绍. 1.上官网下载cocos2dx-3.0的源码,http://www.cocos2d-x.org/ 2.安装python2.7 3.运行setup.py安装 4.执行cocos new helloworld -p helloworld -l cpp,生成新工程 二.新建工程中包含的东西 -Classes AppDelegate.cpp      -----游戏真正开始执行的地

《Cocos2d-x游戏开发实战精解》学习笔记3--在Cocos2d-x中播放声音

<Cocos2d-x游戏开发实战精解>学习笔记1--在Cocos2d中显示图像 <Cocos2d-x游戏开发实战精解>学习笔记2--在Cocos2d-x中显示一行文字 之前的内容主要都是介绍如何在屏幕上显示图像,事实上除了图像之外,音乐的播放也可以被理解为一种显示的方式,本节将学习在Cocos2d-x中播放声音的方法. (1)在HelloWorld.h中对HelloWorld类进行如下定义: class HelloWorld : public Cocos2d::Layer { pu

cocos2dx游戏开发&mdash;&mdash;微信打飞机学习笔记(三)&mdash;&mdash;WelcomeScene的搭建

一.场景与层的关系: cocos2dx的框架可以说主要由导演,场景,层,精灵来构成: 1.其中导演,意如其名,就是操控整个游戏的一个单例,管理着整个游戏. 2.场景就像电影的一幕剧情,所以说,懂得如何划分好游戏的场景,是开始动手做游戏的第一步. 3.一个场景会有很多层,用来处理场景不同的功能. 4.而精灵则是最小的单位,比如子弹,飞机,敌机都是一个个的精灵所组成的.   二.WelcomeScene的搭建: 1.场景和层的二种搭建方法: (1)一种就是跟HelloWorld示例一样的方法,以一个

Cocos2d-x 3.2 学习笔记(五)Sprite Node

游戏中最重要的元素Sprite精灵,关于精灵的创建,精灵的控制等等. 涉及到的类Class: AnimationFrame 动画帧. Animation 动画对象:一个用来在精灵对象上表现动画的动画对象. AnimationCache 动画缓存单例类. 如何你想要保存动画,你需要使用这个缓存. Sprite 精灵;定义为二维图像. SpriteBatchNode 与批量节点类似,如果包含子节点会在一次OpenGL调用内绘制完成. SpriteFrame 一个精灵帧. SpriteFrameCac