使用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的更多相关文章

  1. cocos2d3.0跑酷代码讲解和源码

    最近在网上看到一个跑酷代码的例子,写的很不错,连接如下 http://www.waitingfy.com/archives/783 现在我把他精简了一下,去除了一些比较简单的特效,着重保留了主角的跳跃 ...

  2. Cocos2d3.0 制作PList文件

    auto root = Dictionary::create(); auto string = String::create("string element value"); ro ...

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

    bool sign2 = true; bool sign2 = true; void GameLayer::onTouchMoved(Touch *touch, Event *unused){ if( ...

  4. [原创]cocos2dx加载网络图片&异步加载图片

    [动机] 之前看到一款卡牌游戏,当你要看全屏高清卡牌的时候,游戏会单独从网络上下载,本地只存了非高清的,这样可以省点包大小,所以我萌生了实现一个读取网络图片的类. [联想] 之前浏览网页的时候经常看到 ...

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

    直接贴上Android.mk文件吧. 对了,是cocos2d3.0的,不知道2.x是否一样. LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LO ...

  6. Cocos2d-x移植安卓的笔记

    一.下载所需软件 Java SDK   http://www.oracle.com/technetwork/java/javase/downloads/index.html  Windows x64 ...

  7. ZAM 3D 制作简单的3D字幕 流程(二)

    原地址:http://www.cnblogs.com/yk250/p/5663907.html 文中表述仅为本人理解,若有偏差和错误请指正! 接着 ZAM 3D 制作简单的3D字幕 流程(一) .本篇 ...

  8. ZAM 3D 制作3D动画字幕 用于Xaml导出

    原地址-> http://www.cnblogs.com/yk250/p/5662788.html 介绍:对经常使用Blend做动画的人来说,ZAM 3D 也很好上手,专业制作3D素材的XAML ...

  9. 微信小程序省市区选择器对接数据库

    前言,小程序本身是带有地区选着器的(网站:https://mp.weixin.qq.com/debug/wxadoc/dev/component/picker.html),由于自己开发的程序的数据是很 ...

随机推荐

  1. input只读属性 设置和移除 选择数字

    设置只读属性 $('#stage').attr("readonly", "readonly"); 移除 只读属性  $("input").r ...

  2. MVC – 8.Razor 布局

    8.1.@RenderBody() 8.2.多个"占位符":@RenderSection() 8.3.js合并 @Scripts.Render("~/bundles/js ...

  3. MVC – 7.Razor 语法

    7.1 Razor视图引擎语法 Razor通过理解标记的结构来实现代码和标记之间的顺畅切换. @核心转换字符,用来 标记-代码 的转换字符串. 语境A: @{ string rootName=&quo ...

  4. WMI技术介绍和应用——WMI概述

    https://blog.csdn.net/breaksoftware/article/details/8424317

  5. Web开发入门知识小总结

    原来是写给 http://www.zhihu.com/question/22689579 的答案,也算是学了一学期web课程后的一点小总结,搬运到博客里存一下吧~ ================== ...

  6. 一个配置文件收集多个日志-if根据type类型判断

    1.同时收集/var/log/messages日志和secure日志 #vim /etc/logstash/conf.d/system.conf input { file { path => & ...

  7. poj2253 Frogger(Floyd)

    题目链接 http://poj.org/problem?id=2253 题意 给出青蛙A,B和若干石头的坐标,现在青蛙A要跳到青蛙B所在的石头上,求出所有路径中最远那一跳的最小值. 思路 Floyd算 ...

  8. 【JAVAWEB学习笔记】26_Linux基础:简介安装、常用命令和JDK、Mysql、Tomcat的安装

    Linux基础 学习目标 1.了解Linux的简介与安装 2.掌握Linux常用的命令 3.掌握Linux系统上JDK.Mysql.Tomcat的安装 一.Linux的简介 1.Linux的概述 Li ...

  9. 请画出Servlet 2.2以上Web Application的基本目录结构

    Java web工程下的webapp或WebContent就是工程的发布文件夹,发布时会把该文件夹发布到tomcat的webapps里. 一个web应用必须要有的目录文件如下: webapp/WebC ...

  10. Codeforces 622 F. The Sum of the k-th Powers

    \(>Codeforces \space 622\ F. The\ Sum\ of\ the\ k-th\ Powers<\) 题目大意 : 给出 \(n, k\),求 \(\sum_{i ...