cocos2dx创建精灵的五种方法包括使用图片名获取图片

http://www.jb51.cc/article/p-uzkwinbf-bkb.html
cocos2dx创建精灵的五种方法包括使用图片获取图片

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码

<strong><span style="color:#cc0000;">   // 创建精灵的五种方法</span></strong>

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码

<strong><span style="color:#cc0000;">  
    //方法一:直接创建精灵  
        //适合于要显示的是这张图片的全部区域,  
    CCSprite * sprite = CCSprite::create("Icon.png");  
        //上面那句话也可以根据需要这样来写:  
    //CCString* fileName = CCString::createWithFormat("Icon_%d.jpg",flag);  
    //CCSprite* sprite = CCSprite::create(fileName->getCString());  
    sprite->setPosition(ccp(100,100));  
    this->addChild(sprite);</span></strong>

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码

<strong><span style="color:#cc0000;">  
    // 方法二:参数 图片名称 矩形区域  
    //适合于需要显示图片的部分区域  
    CCSprite * sprite = CCSprite::create("Icon.png",CCRectMake(0,30,30));  
    sprite->setPosition(ccp(100,100));  
    this->addChild(sprite);</span></strong>

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码

<strong><span style="color:#cc0000;">  
    //方法三: 利用帧缓存中的一帧的名称声称一个对象  
    // 适合于plist打包好的文件  
    CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile("test_icon.plist");  
    CCSprite * sprite = CCSprite::createWithSpriteFrameName("Icon.png");  
    sprite->setPosition(ccp(100,100));  
    this->addChild(sprite);</span></strong>

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码

<strong><span style="color:#cc0000;">  
    //方法四: 利用另外一帧生成一个精灵对象    
    //适合于做帧动画使用  
    CCSpriteFrame * frame = CCSpriteFrame::create("Icon.png",40,30));  
    CCSprite * sprite = CCSprite::createWithSpriteFrame(frame);  
    sprite->setPosition(ccp(310,150));  
    addChild(sprite);</span></strong>

[cpp] view plaincopyprint?在CODE上查看代码片派生到我的代码

<strong><span style="color:#cc0000;">  
    //方法五:利用纹理,  
    //适合于需要频繁使用的图片  
    CCSpriteBatchNode* spriteTexture = CCSpriteBatchNode::create("iocn.png");  
    spriteTexture->setPosition(CCPointZero);  
    addChild(spriteTexture);  
    CCSprite* sprite = CCSprite::createWithTexture(spriteTexture->getTexture());  
    sprite->setPosition(ccp(visiblesize.width/2,100));  
    spriteTexture->addChild(sprite,2);</span></strong>

相关文章

    本文实践自 RayWenderlich、Ali Hafizji 的文章《...
Cocos-code-ide使用入门学习地点:杭州滨江邮箱:appdevzw@1...
第一次開始用手游引擎挺激动!!!进入正题。下载资源1:从C...
    Cocos2d-x是一款强大的基于OpenGLES的跨平台游戏开发...
1.  来源 QuickV3sample项目中的2048样例游戏,以及最近《...
   Cocos2d-x3.x已经支持使用CMake来进行构建了,这里尝试...