cocos2d3.0 Scale9Sprite
使用Scale9Sprite须要引入以下的头文件
#include "extensions/cocos-ext.h" USING_NS_CC;
USING_NS_CC_EXT;
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;
}
效果:
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;
}
效果:
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;
}
效果:
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);
效果:
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的更多相关文章
- cocos2d3.0跑酷代码讲解和源码
最近在网上看到一个跑酷代码的例子,写的很不错,连接如下 http://www.waitingfy.com/archives/783 现在我把他精简了一下,去除了一些比较简单的特效,着重保留了主角的跳跃 ...
- Cocos2d3.0 制作PList文件
auto root = Dictionary::create(); auto string = String::create("string element value"); ro ...
- cocos2d-3.0 Helloworld::onTouchMoved的处理机制的推測
bool sign2 = true; bool sign2 = true; void GameLayer::onTouchMoved(Touch *touch, Event *unused){ if( ...
- [原创]cocos2dx加载网络图片&异步加载图片
[动机] 之前看到一款卡牌游戏,当你要看全屏高清卡牌的时候,游戏会单独从网络上下载,本地只存了非高清的,这样可以省点包大小,所以我萌生了实现一个读取网络图片的类. [联想] 之前浏览网页的时候经常看到 ...
- 使用cocostudio 需要在Android.mk文件的配置
直接贴上Android.mk文件吧. 对了,是cocos2d3.0的,不知道2.x是否一样. LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LO ...
- Cocos2d-x移植安卓的笔记
一.下载所需软件 Java SDK http://www.oracle.com/technetwork/java/javase/downloads/index.html Windows x64 ...
- ZAM 3D 制作简单的3D字幕 流程(二)
原地址:http://www.cnblogs.com/yk250/p/5663907.html 文中表述仅为本人理解,若有偏差和错误请指正! 接着 ZAM 3D 制作简单的3D字幕 流程(一) .本篇 ...
- ZAM 3D 制作3D动画字幕 用于Xaml导出
原地址-> http://www.cnblogs.com/yk250/p/5662788.html 介绍:对经常使用Blend做动画的人来说,ZAM 3D 也很好上手,专业制作3D素材的XAML ...
- 微信小程序省市区选择器对接数据库
前言,小程序本身是带有地区选着器的(网站:https://mp.weixin.qq.com/debug/wxadoc/dev/component/picker.html),由于自己开发的程序的数据是很 ...
随机推荐
- acm专题---拓扑排序+优先队列
struct node{ int id; int cnt; node(int _id,int _cnt):id(_id),cnt(_cnt){} bool operator<(node a) c ...
- html5多媒体Video/Audio
video: 1.常见的视频格式 视频的组成部分:画面.音频.编码格式 视频编码:H.264.theora.VP8(google开源) 2.常见的音频格式 编码:AAC.MP3 ...
- JavaScript 中typeof、instanceof 与 constructor 的区别?
typeof.instanceof 与 constructor 详解 typeof 一元运算符 返回一个表达式的数据类型的字符串,返回结果为js基本的数据类型,包括number,boolean,st ...
- 在ubuntu下安装kaldi基本步骤
注:最近在学习kaldi语音识别工具,在安装过程中遇到了许多问题,在此记录,以备后需. 在一开始,我看了这篇博客(http://blog.topspeedsnail.com/archives/1001 ...
- React.js学习之理解JSX和组件
在开启JSX的学习旅程前,我们先了解一下React的基本原理.React本质上是一个"状态机",它只关心两件事:更新DOM和响应事件,React不处理Ajax.路由和数据存储,也不 ...
- 使用FlashPaper在线转换.doc为.swf_实用技巧
https://yq.aliyun.com/ziliao/160044?spm=5176.8246799.0.0.JBbqjY 摘要: 本文讲的是使用FlashPaper在线转换.doc为.swf_实 ...
- 为什么主引导记录的内存地址是0x7C00?
转自:http://www.ruanyifeng.com/blog/2015/09/0x7c00.html 当时,搭配的操作系统是86-DOS.这个操作系统需要的内存最少是32KB.我们知道,内存地址 ...
- 我对于react-router路由原理的学习
目录 react-router依赖基础--history react-router是如何实现URL与UI同步 一 react-router依赖基础--history history是一个独立的第三方j ...
- cdoj1092-韩爷的梦 (字符串hash)【hash】
http://acm.uestc.edu.cn/#/problem/show/1092 韩爷的梦 Time Limit: 200/100MS (Java/Others) Memory Limi ...
- CodeForces 606C Sorting Railway Cars(最长连续上升子序列)
Description An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the n ...