折腾cocos2d

创建工程 link
./create_project.py -project MyGame -package com.MyCompany.AwesomeGame -language cpp
Options:
  • -l cpp for a cocos2d-x C++ project
  • -l lua for a cocos2d-x + Lua bindings project
  • -l javascript for a cocos2d-x + JavaScript bindings project
shift+F1 win32平台下模拟Android后退键 http://www.cocos2d-x.org/wiki/Howtosimulateandroidbehaviorsonwindows_desktop
CCLog函数提供给Android平台调试使用
http://www.cocos2d-x.org/wiki/Howtouse_CCLOG
http://www.cocos2d-x.org/wiki/Howtodebugcocos2d-xgames
http://www.cocos2d-x.org/forums/6/topics/3499?r=37155
USING_NS_CC 声明cocos2d命名空间
// 为C++的名称空间宏,using namespace cocos2d的缩写
USING_NS_CC;
单点触控:Targeted Touch Delegate
使用单点触控时遇到不响应
在onEnter函数中
CCDirector::sharedDirector()->getTouchDispatcher()->addTargetedDelegate(this,0,true);
在onExit函数中
CCDirector::sharedDirector()->getTouchDispatcher()->removeDelegate(this);
http://stackoverflow.com/questions/17350669/cocos2d-x-and-handling-touch-events
http://www.cocos2d-x.org/forums/6/topics/17177
    // 1.生成动画需要数据类
    CCTexture2D* texture = CCTextureCache::sharedTextureCache()->addImage("action_people.png");
    CCSpriteFrame* frame0 = CCSpriteFrame::createWithTexture(texture , CCRectMake(32*0 , 48*0 , 32 , 48));
    CCSpriteFrame* frame1 = CCSpriteFrame::createWithTexture(texture , CCRectMake(32*1 , 48*0 , 32 , 48));
    CCSpriteFrame* frame2 = CCSpriteFrame::createWithTexture(texture , CCRectMake(32*2 , 48*0 , 32 , 48));
    CCSpriteFrame* frame3 = CCSpriteFrame::createWithTexture(texture , CCRectMake(32*3 , 48*0 , 32 , 48));

    CCArray* animFrames = CCArray::create();
    animFrames->addObject(frame0);
    animFrames->addObject(frame1);
    animFrames->addObject(frame2);
    animFrames->addObject(frame3);

    CCAnimation* animation =CCAnimation::createWithSpriteFrames(animFrames, 0.2f );
    animFrames->release();

    // 2.初始化并设置Sprite
    CCSprite* sprite = CCSprite::createWithSpriteFrame(frame0);
    sprite->setPosition( ccp( sprite->getContentSize().width+50 , winSize.height/2 ) );
    addChild(sprite);

    // 2.使用animation生成一个动画动作animation
    CCAnimate* animate = CCAnimate::create(animation);
    sprite->runAction(CCRepeatForever::create(animate));
简单过程是,使用CCTexture2D加载图片 ,用CCTexture2D生成对应的CCSpriteFrame(对应的就是帧),将CCSpriteFrame添加到CCAnimation生成动画数据,用CCAnimation生成CCAnimate(就是最终的动画动作),最后用CCSprite执行这个动作。
cocos2d中LUA脚本的处理类
CCLuaEngine LUA脚本引擎
CCScriptEngineManager LUA脚本引擎管理

Related Articles

0 评论 :

发表评论

Quote Of The Day