使用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. 用PHP去实现数据库查询结果缓存

    有些时候我们希望减少对数据库的查询来提高程序的性能,因为这些数据不是经常变更的,而是会在很长一段时间内都不会变化,因此,我们每连接一次数据库,都会把相应的结果用文件的形式保存起来.比如对于一个商城来说 ...

  2. AWS 使用总结

    A.升配置的流程: 1.新开一台配置较高的机器; 2.将新机器和老机器的磁盘都取消关联,注意需要记录下老机器的磁盘分区设备名,如:/dev/sda1: 3.将老机器的磁盘挂载到新机器上,磁盘分区设备名 ...

  3. Linux 进程间通信(一)(经典IPC:管道、FIFO)

    管道 管道是Unix系统IPC的最古老方式,有两种局限性: (1)   历史上它们是半双工的(即数据只能在一个方向上流动),虽然现在某些系统提供了全双工管道,但是为了可移植性,不要抱有绝对的全双工假设 ...

  4. css控制单行文本溢出

    1.溢出属性(容器的) overflow:visible/hidden(隐藏)/scroll/auto(自动)/inherit; visible:默认值,内容不会被修剪,会成现在元素框之外: hidd ...

  5. bzoj 4518

    4518 思路: 斜率优化: 代码: #include <cstdio> #include <cstring> #include <iostream> #inclu ...

  6. DB First 中对Repository 层封装的几点小记

    在数据库表创建完成的情况下,使用DB First 进行开发,封装底层会遇到一些小问题,在此记录一下,供以后参考. 主要解决的问题有: 1.EF上下文管理 2.BaseRepository的封装 3.E ...

  7. C# asp.net 实现导出Excel

    原文地址:传送门 这段时间用到了导出Excel的功能,这个功能还是比较常用的,我常用的有两个方法,现在整理一下,方便以后查看. 1.实现DataTable数据导出到本地,需要自己传进去导出的路径. / ...

  8. loadrunner场景执行出现:Failed to Initialize. Reason: TimeOut

      问题1: Failed to Initialize. Reason: TimeOut LoadRunner的异常原因(Failed to Initialize. Reason: TimeOut) ...

  9. spring_150807_hibernate_transaction_annotation

    实体类: package com.spring.model; import javax.persistence.Entity; import javax.persistence.Id; import ...

  10. Java 如何获取系统时间

    Java 如何获取系统时间 import java.text.SimpleDateFormat; import java.util.Date; public class Test { public s ...