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

cocos2d3.0 Scale9Sprite

时间:2014-07-07 10:25:00      阅读:175      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   使用   

使用Scale9Sprite须要引入以下的头文件

#include "extensions/cocos-ext.h"


USING_NS_CC;
USING_NS_CC_EXT;

一、S9BatchNodeBasic

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

    
    float x = visibleSize.width / 2;
    float y = visibleSize.height / 2;
    
    auto batchNode = SpriteBatchNode::create("blocks9.png");
    
    auto blocks = Scale9Sprite::create();
    log("------created");
    
    blocks->updateWithBatchNode(batchNode, Rect(0, 0, 96, 96), false, Rect(0, 0, 96, 96));
    
    blocks->setPosition(Point(x, y));
    
    this->addChild(blocks);
    return true;
}

效果:
bubuko.com,布布扣


二、S9FrameNameSpriteSheet

bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("blocks9ss.plist");
    float x = visibleSize.width / 2;
    float y = visibleSize.height / 2;
    
    auto blocks = Scale9Sprite::createWithSpriteFrameName("blocks9.png");

    blocks->setPosition(Point(x, y));
    
    this->addChild(blocks);
    
    
    return true;
}

效果:
bubuko.com,布布扣


三、S9BatchNodeScaledNoInsets  设置精灵的大小
bool HelloWorld::init()
{
    //////////////////////////////
    // 1. super init first
    if ( !Layer::init() )
    {
        return false;
    }
    
    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("blocks9ss.plist");
    float x = visibleSize.width / 2;
    float y = visibleSize.height / 2;
    
    auto batchNode_scaled = SpriteBatchNode::create("blocks9.png");
    
    auto block_scaled = Scale9Sprite::create();
    
    block_scaled->updateWithBatchNode(batchNode_scaled, Rect(0, 0, 96, 96), false, Rect(0, 0, 96, 96));
    
    block_scaled->setPosition(Point(x, y));
    
    block_scaled->setContentSize(Size(96 * 4, 96 * 2));
    
    this->addChild(block_scaled);
    
    
    
    return true;
}

效果:
bubuko.com,布布扣


四、S9FrameNameSpriteSheetRotatedScaledNoInsets

  auto block_scaled = Scale9Sprite::createWithSpriteFrameName("blocks9.png");

    
    block_scaled->setPosition(Point(x, y));
    
    block_scaled->setContentSize(Size(96 * 4, 96 * 2));
    
    this->addChild(block_scaled);
    

效果:
bubuko.com,布布扣


五、S9FrameNameSpriteSheetRotatedScaledNoInsets
    auto block_scaled = Scale9Sprite::createWithSpriteFrameName("blocks9r.png");

    
    block_scaled->setPosition(Point(x, y));
    
    block_scaled->setContentSize(Size(96 * 4, 96 * 2));
    
    this->addChild(block_scaled);

效果:
bubuko.com,布布扣


S9FrameNameSpriteSheetInsets

    auto batchNode_scaled_with_insets = SpriteBatchNode::create("blocks9.png");
    
    auto blocks_scaled_with_insets = Scale9Sprite::create();
    
    blocks_scaled_with_insets->updateWithBatchNode(batchNode_scaled_with_insets, Rect(0, 0, 96, 96), false, Rect(32, 32, 32, 32));
    
    blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5));
    
    blocks_scaled_with_insets->setPosition(Point(x, y));
    
    this->addChild(blocks_scaled_with_insets);

bubuko.com,布布扣


S9FrameNameSpriteSheetInsetsScaled

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("blocks9ss.plist");
    float x = visibleSize.width / 2;
    float y = visibleSize.height / 2;

    
    auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9.png",Rect(32, 32, 32, 32));
    

    
    blocks_scaled_with_insets->setContentSize(Size(96 * 4.5, 96 * 2.5));
    
    blocks_scaled_with_insets->setPosition(Point(x, y));
    
    this->addChild(blocks_scaled_with_insets);

bubuko.com,布布扣




S9_TexturePacker

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("ui.plist");
    float x = visibleSize.width / 4;
    float y = visibleSize.height / 2;
    
    
    auto s = Scale9Sprite::createWithSpriteFrameName("button_normal.png");
    
    s->setPosition(Point(x, y));
    log("... setPosition");
    
    s->setContentSize(Size(14 * 16, 10 * 16));
    log("... setContentSize");
    
    this->addChild(s);


    
    auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("button_actived.png");
    

     x = visibleSize.width * 3/4;
    blocks_scaled_with_insets->setContentSize(Size(14 * 16, 10 * 16));
    
    blocks_scaled_with_insets->setPosition(Point(x , y));
    
    this->addChild(blocks_scaled_with_insets);

bubuko.com,布布扣



Scale9FrameNameSpriteSheetRotatedSetCapInsetLater

  Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("blocks9ss.plist");
    float x = visibleSize.width / 2;
    float y = visibleSize.height / 2;
    
    
    

    
    auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png");
    blocks_scaled_with_insets->setInsetLeft(32);
    blocks_scaled_with_insets->setInsetRight(32);
    blocks_scaled_with_insets->setPreferredSize(Size(32 * 5.5f, 32 * 4));
    
    blocks_scaled_with_insets->setPosition(Point(x , y));
    
    this->addChild(blocks_scaled_with_insets);

bubuko.com,布布扣





S9CascadeOpacityAndColor

    Size visibleSize = Director::getInstance()->getVisibleSize();
    Point origin = Director::getInstance()->getVisibleOrigin();

     SpriteFrameCache::getInstance()->addSpriteFramesWithFile("blocks9ss.plist");
    float x = visibleSize.width / 2;
    float y = visibleSize.height / 2;
    
    auto rgba = Layer::create();
    rgba->setCascadeColorEnabled(true);
    rgba->setCascadeOpacityEnabled(true);
    this->addChild(rgba);
    
    

    
    auto blocks_scaled_with_insets = Scale9Sprite::createWithSpriteFrameName("blocks9r.png");
    
    
    blocks_scaled_with_insets->setPosition(Point(x , y));
    
    rgba->addChild(blocks_scaled_with_insets);
    
    
    
    auto actions = Sequence::create(FadeIn::create(1),TintTo::create(1, 0, 255, 0),TintTo::create(1, 255, 255, 255),FadeOut::create(1), NULL);
    auto repeat = RepeatForever::create(actions);
    
    rgba->runAction(repeat);

bubuko.com,布布扣







cocos2d3.0 Scale9Sprite,布布扣,bubuko.com

cocos2d3.0 Scale9Sprite

标签:des   style   blog   http   color   使用   

原文地址:http://www.cnblogs.com/yxwkf/p/3820529.html

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