cocos2d3.0 Scale9Sprite

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

效果:

<span>cocos2d3.0 Scale9Sprite</span>


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

效果:

<span>cocos2d3.0 Scale9Sprite</span>


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

效果:

<span>cocos2d3.0 Scale9Sprite</span>


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

效果:

<span>cocos2d3.0 Scale9Sprite</span>


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

效果:

<span>cocos2d3.0 Scale9Sprite</span>


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


<span>cocos2d3.0 Scale9Sprite</span>



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


<span>cocos2d3.0 Scale9Sprite</span>





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


<span>cocos2d3.0 Scale9Sprite</span>




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


<span>cocos2d3.0 Scale9Sprite</span>






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


<span>cocos2d3.0 Scale9Sprite</span>








版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

发布者:全栈程序员-用户IM,转载请注明出处:https://javaforall.cn/119170.html原文链接:https://javaforall.cn

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • C语言3×3二维数组_什么是二维数组

    C语言3×3二维数组_什么是二维数组C语言目录C/C++学习资源(百度云盘链接)计算机二级资料(过级专用)C语言学习路线(从入门到实战)编写C语言程序的7个步骤和编程机制C语言基础-第一个C程序C语言基础-简单程序分析VS2019编写简单的C程序示例简单示例,VS2019调试C语言程序C语言基础-基本算法C语言基础-数据类型C语言中的输入输出函数C语言流程控制语句C语言数组——一维数组二维数组前面介绍了…

  • p2p流媒体技术(简述流媒体的特点)

    【前言】今天发现二哥在搞流媒体,顿时来了兴趣(之前在考试维护的时候经常听老师说P2P等),追问之下之前林哥搞成功过,而且写了一系列博客;于是乎便翻开博客,认真看了看,写的非常不错:从概念到安装实现(linux和windows)再到性能测试对比非常不错(详见:http://blog.csdn.net/u012407484/article/category/2732453);…

  • 前端技术栈总结_前端开发技术栈

    前端技术栈总结_前端开发技术栈vuereact

    2022年10月25日
  • kettle 教程(四):自定义 Java 代码

    kettle 教程(四):自定义 Java 代码kettle拥有很多自带的组件,能帮我们实现很多的功能。但是我们总有一些很复(qi)杂(pa)的需求,用自带的组件实现不了,或者说实现起来很复杂。那么这时我们就要用到万能的组件了(Java代码),通过自己写代码来实现任何想要的功能。自定义Java代码假设有这样一个需…

  • C#中HttpWebRequest的用法详解

    C#中HttpWebRequest的用法详解HttpWebRequest和HttpWebResponse类是用于发送和接收HTTP数据的最好选择。它们支持一系列有用的属性。这两个类位于System.Net命名空间,默认情况下这个类对于控制台程序来说是可访问的。请注意,HttpWebRequest对象不是利用new关键字通过构造函数来创建的,而是利用工厂机制(factorymechanism)通过Create()方法来创建的。另外,你可…

  • matlab_matlab反归一化

    matlab_matlab反归一化最近在做神经网络,需要对训练数据进行归一化到[0.10.9]之间。虽然matlab有现成的归一化函数(mapminmax()premnmx),但归一化到特定的区间,上述函数并不方便使用。由此萌生了自己编写归一化函数的想法。(先说推导,matlab代码见后面)

    2022年10月11日

发表回复

您的电子邮箱地址不会被公开。

关注全栈程序员社区公众号