cocos2d3.0 Scale9Sprite

使用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;
}

效果:

二、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;
}

效果:

三、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;
}

效果:

四、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);
    

效果:

五、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);

效果:

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);

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);

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);

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);

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);

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

时间: 2024-11-10 15:57:57

cocos2d3.0 Scale9Sprite的相关文章

Cocos2d3.0 制作PList文件

auto root = Dictionary::create(); auto string = String::create("string element value"); root->setObject(string, "string element key"); auto array = Array::create(); auto dictInArray = Dictionary::create(); dictInArray->setObject(

Cocos2d3.0 CheckBox

.h Text* _displayValueLabel; void selectedEvent(Ref* pSender,CheckBoxEventType type); .cpp  init()函数 _touchGroup = Layer::create(); addChild(_touchGroup); Size winSize = Director::getInstance()->getWinSize(); _displayValueLabel = Text::create("NO

用cocos2d3.0写一个srpg游戏-移动部分的实现

确定SRPG一个人物的移动范围, 我用的是比较傻的穷举法, 其实就是把人物可移动长度的每一个点都判断一下是否可以移动, 然后根据地形对人物影响的障碍等级, 每走一步,就少一个障碍等级的行走能力. 具体看代码 void SearchPathForSLG::init(TMXTiledMap* map, Point heroIndex,int runLength,bool movePath[][255]){ Point mapSize=Point(map->getMapSize().width,map

Cocos2d3.0 画折线图

实现用2dx画折线图,为以后用2dx开发应用做准备 下面记录下使用方法 auto lineView = DJLineChart::create(); std::vector<float> vec; vec.push_back(130); vec.push_back(520); vec.push_back(60); vec.push_back(0); vec.push_back(140); vec.push_back(100); vec.push_back(30); vec.push_back(

cocos2d-3.0 Helloworld::onTouchMoved的处理机制的推測

bool sign2 = true; bool sign2 = true; void GameLayer::onTouchMoved(Touch *touch, Event *unused){ if(sign){ sign = false; ** if(sign2){ CCLOG("RUNNING!"); sign2 = false; sign = true; }else{ sign2 = true; } ** } } 假设上述代码顺序执行,则会出现无限循环的RUNNING的LOG:

[原创]cocos2dx加载网络图片&amp;异步加载图片

[动机] 之前看到一款卡牌游戏,当你要看全屏高清卡牌的时候,游戏会单独从网络上下载,本地只存了非高清的,这样可以省点包大小,所以我萌生了实现一个读取网络图片的类. [联想] 之前浏览网页的时候经常看到一张图片渐进(由模糊变清晰)的显示,如果在游戏中,诸如像显示高清卡牌的时候,使用有这种方式去显示一张图片,这样的体验应该会稍微好些 [相关知识] png interlaced:png图片在导出的时候是可以选择 interlaced (Adam7)的,这样的存储的png在网页上显示会渐进显示, 这种i

使用cocostudio 需要在Android.mk文件的配置

直接贴上Android.mk文件吧. 对了,是cocos2d3.0的,不知道2.x是否一样. LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := cocos2dcpp_shared LOCAL_MODULE_FILENAME := libcocos2dcpp LOCAL_SRC_FILES := hellocpp/main.cpp ../../Classes/AppDelegate.cpp ../../Classe

鬃嘴释怀说太多就成真不了。

子阻撞砖奏尊仔籽着 释怀说太多就成真不了. http://passport.baidu.com/?business&un=vip&un=%E5%A4%A9%E6%B0%B4%E4%B8%8A%E9%97%A8%E8%BF%99%E5%B0%8F%E5%A7%90#0 http://passport.baidu.com/?business&un=vip&un=%E7%99%BD%E9%93%B6%E4%B8%8A%E9%97%A8%E8%BF%99%E5%B0%8F%E5%A

澜星粘鼐贩逊耐盼系甭妊倏纪傲傲sdfghjk

http://passport.baidu.com/?business&un=R&un=%E5%A4%A7%E5%AE%81%E6%A1%91%E6%8B%BF%E9%80%9A%E5%B0%8F%E5%A7%90#0 http://passport.baidu.com/?business&un=R&un=%E4%B9%A1%E5%AE%81%E6%A1%91%E6%8B%BF%E9%80%9A%E5%B0%8F%E5%A7%90#0 http://passport.bai