摘要:C++中的vector使用范例一、概述vector是C++标准模板库中的部分内容,它是一个多功能的,能够操作多种数据结构和算法的模板类和函数库。vector是一个容器,它能够存放各种类型的对象,简单地说,vector是一个能够存放任意类型的动态数组,可以动态改变大小。例如:// c语言风格int myHouse[100] ;// 采用vectorvector<int> vecMyHouse(100);当如上定义后,vecMyHouse就可以存放100个int型的数据了。1. 它可以像普通数组一样访问eg: vecMyHouse[50] = 1024;2. 你可以顺序地向容器中填充数
阅读全文
摘要:方法一:srand(time(NULL));array->removeAllObjects();this->removeAllChildren();init();方法二: CCDirector::sharedDirector()->replaceScene(HelloWorld::scene());从本场景切换到本场景,但是不能在init()函数中。。
阅读全文
摘要:include "HelloWorldScene.h" #include "SimpleAudioEngine.h" using namespace cocos2d; using namespace CocosDenshion; //根据不同平台使用预编译索引不同音频文件 #if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID) #define EFFECT_FILE "effect2.ogg" #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MARMALADE)
阅读全文
摘要:重新设置一个随机种子。。。 如果没有srand((unsigned)time(NULL));运行以下程序,每次输出结果会都是一样的。。。。。 void test_rand(void) { unsigned long n; srand((unsigned)time(NULL)); for(int i = 0; i < 100; i++) { n = rand(); printf("%10d\n", n); } }
阅读全文
摘要:举例代码如下: //游戏子弹与怪物的碰撞检测,当发生碰撞时从游戏中去除相碰撞的子弹与怪物 //getEemyArray()为定义在PlayScene类中得到怪物数组的函数, 下面语句体在子弹类中Bullet 继承 CCSprite for(int i = 0; i < PlayScene::sharedPlay()->getEnemyArray()->count(); i ++) { Enemy* enemy = (Enemy*) PlayScene::sharedPlay()->getEnemyArray()->objectAtIndex(i); ...
阅读全文
摘要:获取当前某类的静态实例方法:如下代码,举例类名为: PlayScene在 .h 文件中声明:class PlayScene : public CCLayer{public: //获取当前PlayScene的静态实例(分享) static PlayScene* sharedPlay(); static CCScene* createPlayScene(); virtual bool init(); CREATE_FUNC(PlayScene);};在 .cpp 文件中定义:#include "PlayScene.h"static PlayScene* ps;Pla...
阅读全文
摘要:/首先到cocos2d-x项目下的ios文件夹下,找到AppController.mm文件,在函数 didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 中添加如下函数: [__glView setMultipleTouchEnabled:YES]; bool HelloWorld::init() { if ( !CCLayer::init() ) { return false; } //开启多触点监听务必调用此函数 setTo...
阅读全文
摘要:CCSprite* sp = CCSprite::create("crop1.png"); sp->setPosition(ccp(170, 200)); addChild(sp); CCAnimation* animation = CCAnimation::create(); animation->addSpriteFrameWithFileName("crop1.png"); animation->addSpriteFrameWithFileName("crop2.png"); animation->add
阅读全文
摘要:bool HelloWorld::init() { ////////////////////////////// // 1. super init first if ( !CCLayer::init() ) { return false; } CCSprite* sp1 = CCSprite::create("Icon.png"); sp1->setPosition(ccp(200, 160)); addChild(sp1, 0, 1); CCSprite*...
阅读全文
摘要://扇形 逆时针 // CCTransitionScene* transition = CCTransitionProgressRadialCCW::create(1.5f, MyScene::createMyScene()); // CCDirector::sharedDirector()->replaceScene(transition); //扇形 顺时针 // CCTransitionScene* transiton = CCTransitionProgressRadialCW::create(1.2f, MyScene::createM...
阅读全文
摘要:CCSprite* sp = CCSprite::create("Default.png"); sp->setPosition(ccp(240, 160)); addChild(sp); //常见的22种特效 //3D晃动的特效 // CCActionInterval* shaky3D = CCShaky3D::create(5, CCSize(10, 10), 15, false); // sp->runAction(shaky3D); //3D瓷砖晃动特效 // CCActionInter...
阅读全文
摘要://清晰移动类型的作用 CCParticleSystem* particleSystem1 = CCParticleSun::create(); particleSystem1->setTexture(CCTextureCache::sharedTextureCache()->addImage("fire.png")); //自动释放 particleSystem1->setAutoRemoveOnFinish(true); //设置移动类型:自由模式 particleSystem1->setPositionType(kCCPositi...
阅读全文
摘要:虚拟摇杆类起名为:HRocker 下面是 HRocker.h 文件:[cpp] view plaincopy#include <iostream> #include "cocos2d.h" using namespace cocos2d; //枚举型:用于标识摇杆与摇杆的背景 typedef enum{ tag_rocker, tag_rockerBG, }tagForHRocker; class HRocker : public CCLayer { public: //创建摇杆,摇杆图片,摇杆背景图片,起始坐标 ...
阅读全文
摘要:/粒子特效 //爆炸效果 CCParticleSystem* particleSystem = CCParticleExplosion::create(); particleSystem->setTexture(CCTextureCache::sharedTextureCache()->addImage("stars.png")); addChild(particleSystem); //火焰效果 CCParticleSystem* particleSystem = CCParticleFire::create...
阅读全文
摘要:CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("last.plist","last.png"); CCTexture2D *texture=CCTextureCache::sharedTextureCache()->textureForKey("last.png"); CCSpriteBatchNode *node=CCSpriteBatchNode::createWithTexture(texture); addChild(no
阅读全文
摘要:准备工作在使用C++操作SQLite之前,需要获得sqlite3.h,sqlite3.lib,sqlite3.dll,大家可以在这里下载。并将这3个文件导入VC++工程中。其中sqlite3.dll文件放到Debug文件夹里。SQLite API介绍int sqlite3_open(char *path,sqlite3 **db)这个函数打开数据库,第一个参数为sqlite文件的地址,第二个参数是sqlite3的指针的指针,也就是二级指针。返回值为SQLITE_OK则成功打开数据库。 sqlite3_close(sqlite3 *db)这个函数关闭数据库,参数是sqlite3的指针。 sqli
阅读全文
摘要:CCSprite *s= CCSprite::create("xiao.png"); s->getTexture()->setAntiAliasTexParameters(); s->setPosition(ccp(240, 160)); addChild(s); CCActionInterval *ac = CCScaleTo::create(2, 5); s->runAction(ac);
阅读全文
摘要:HelloWorld::HelloWorld(){ smoke=CCParticleSmoke::create(); sun=CCParticleSun::create(); }HelloWorld::~HelloWorld(){ smoke->setAutoRemoveOnFinish(true); sun->setAutoRemoveOnFinish(true);} CCScene* HelloWorld::scene(){ // 'scene' is an autorelease object CCScene *scene = CCScene::cre...
阅读全文
摘要:CCParticleSnow *snow=CCParticleSnow::create(); snow->setPosition(ccp(400,670)); snow->setTextureWithRect(CCTextureCache::sharedTextureCache()->addImage("snow.png"),CCRectMake(0,0,32,32)); addChild(snow);
阅读全文
摘要:CCParticleSystemQuad *m_emitter = new CCParticleSystemQuad(); m_emitter->initWithTotalParticles(900);//900个粒子对象 //设置图片 m_emitter->setTexture(CCTextureCache::sharedTextureCache()->addImage("snow1.png")); //设置发射粒子的持续时间-1表示一直发射,0没有意义,其他值表示持续时间 m_emitter->setDuration(-1); //设置中心方向,
阅读全文