怎么样分割由texturepackerpro生成的SpriteSheets图和plist文件

通过texturePacker做出的flash帧图怎么调用_百度知道
通过texturePacker做出的flash帧图怎么调用
提问者采纳
flash能要使用位图画帧每帧都要图片保存能耗费余内存能用TexturePacker图合并图(文用sprite sheet代替)减少内存使用且减少读入程序图片数量定程度能加快程序运行效率本文章介绍何SpriteSheetAs3库读入TexturePackersprite sheet播放画先介绍SpriteSheetAs3源用SpriteSheet Animation in AS3修改优化库新功能: 1.减少内存使用;2.读入sprite sheetplist格式配置文件;3.改用图片名索引位图(图)或画帧;4.支持旋转位图(图)sprite sheet;5.读入tiled图用TexturePacker我sprite sheet载TexturePacker丑鱼画帧打TexturePacker所丑鱼图片加入工程图所示:注意Data Format定要cocos2dTexture settings其选项图致texturefiledata file路径由自定吧点击public发布sprite sheet关sprite sheet所包含图片数据plist文件免费版TexturePacker,点击public,要点continue,且sprite sheet两图花免费版才 接代码发先载SpriteSheetAs3打Flash Builder新建ActionScript项目命名testSpriteSheet图:点击&步&点&添加SWC&SpriteSheetAs3bin目录SpriteSheetAs3.swc文件添加工程图:点完Clown_Normal.pngClown_Normal.plist复制testSpriteSheet/bin-debug/data/(请手创建目录)内容复制testSpriteSheet.as文件://testSpriteSheet.aspackage{ import flash.display.B import flash.display.DisplayO import flash.display.S import flash.display.StageA import flash.display.StageScaleM import flash.events.E import flash.events.IOErrorE
import com.sprite_sheet.AnimSpriteS import com.sprite_sheet.SpriteSheetF import com.sprite_sheet.TextureC import com.sprite_sheet.SpriteFrameC import utils.S import utils.loading.BigL import utils.loading.BigLoadI
[SWF (width=&750&, height=&600&)] public class testSpriteSheet extends Sprite {
private var mLoader:BigL //res loader
public function testSpriteSheet()
addEventListener(Event.ADDED_TO_STAGE, onAdded);
protected function onAdded(event:Event):void
stage.scaleMode = StageScaleMode.NO_SCALE;
stage.frameRate= 60;
//draw background
var appWidth:Number= 750;
graphics.beginFill(0x434E8E);
graphics.drawRect(0,0, appWidth, 24);
graphics.endFill();
graphics.beginFill(0xf0f0f0);
graphics.drawRect(0,24, appWidth, 600);
graphics.endFill();
var st:DisplayObject= new Stats();
addChild(st);
// load resources
mLoader= new BigLoader();
mLoader.add(&data/Clown_Normal.png&, &Clown_Normal.png&);
mLoader.add(&data/Clown_Normal.plist&, &Clown_Normal.plist&, 1, BigLoadItem.DATA);
mLoader.PLETE, onAnimLoaded);
mLoader.addEventListener(IOErrorEvent.IO_ERROR, onLoadFailed);
mLoader.start();
private static const NUM_H:int = 6;
protected function onAnimLoaded(event:Event):void
//add sprite sheet data file to SpriteFrameCache
SpriteFrameCache.Singleton().SetLoader(mLoader);
SpriteFrameCache.Singleton().AddSpriteFrames(&Clown_Normal.plist&);
//add sprite sheet file to TextureCache
TextureCache.Singleton().SetLoader(mLoader);
TextureCache.Singleton().addSpriteSheet(&Clown_Normal.png&);
for (var i:int = 0; i & 24; i++)
//create clown fish anim
var anim: AnimSpriteSheet = createClownAnim();
addChild(anim);
anim.mFps = 2 * (i + 1);
var row: int = int(i/NUM_H);
anim.x= 20 + 100*(i%NUM_H) + row*36;
anim.y= 150 + row*60;
protected function createClownAnim(): AnimSpriteSheet
//00~09 frames
var bmps: Array = new Array();
var bmp: SpriteSheetFrame =
for(var i:int = 0; i & 10; i++)
bmp = SpriteFrameCache.Singleton().CreateSpriteSheetFrame(&Clown_Normal0& + i + &.png&);
bmps.push(bmp);
//10~ 23 frames
for(i = 10; i & 24; i++)
bmp = SpriteFrameCache.Singleton().CreateSpriteSheetFrame(&Clown_Normal& + i + &.png&);
bmps.push(bmp);
var anim: AnimSpriteSheet = new AnimSpriteSheet(bmps);
anim.mFps = 30;
anim.EnableShow(true);
anim.EnablePlay(true);
protected function onLoadFailed(event:IOErrorEvent):void
// if load file failed, will print the file name to console
trace(&Cannot find file!&);
trace(event.text);
} }}运行程序功看见丑鱼游些花图(我用免费版TexturePacker)
资深电脑人
其他类似问题
等待您来回答
下载知道APP
随时随地咨询
出门在外也不愁TexturePacker 它是一款把若干资源图片拼接为一张大图的工具。
我们知道openGL载入纹理图片的时候,所用内存是会自动扩张到2的n次方的。
所以我们需要把很多小图拼接到一张大图里,
然后到代码中取其所需。
这样,浪费掉的空间就很小了。
还有就是,提前一次载入,减少I/O,提高速度。
节省内存,提高效率。
生成的XX.plist文件,XX.png图片一张。
如何获取XX.png这张图片上的小图片呢?
很简单,知道小图片的Name就行。
我们可以根据plist文件获取单个CCSprite,把他添加到CCLayer上。
方法如下:
CCSprite* HelloWorld::addSp(const char*ImageName)
&CCSpriteFrameCache *cache = CCSpriteFrameCache::sharedSpriteFrameCache();
&cache-&addSpriteFramesWithFile(&TankUIp.plist&, &TankUIp.png&);
&CCString::createWithFormat(ImageName)-&getCString();
&CCSpriteFrame*frame =& cache-&spriteFrameByName(ImageName);
&CCSprite*sp = CCSprite::createWithSpriteFrame(frame);
bool HelloWorld::init()
&&&& CCSprite*sp = addSp(&1P.png&);
&&& sp-&setPosition(ccp(200,400));
&&& this-&addChild(sp);
还可以通过plist文件保存的序列帧创建Animation
方法如下:
static void buildAnimateByPlist(CHAR* plistName, int beginFrame,int endFrame,CHAR* findpngName,CHAR* setAniName,bool B,double frameSpeed,cocos2d::CCObject * target,cocos2d::SEL_CallFuncO selector)
&&int nNameLength = strlen(plistName);
&&char * pImageName = new char[nNameLength+5];
&&strcpy(pImageName,plistName);
&&strcat(pImageName,&.png&);
&&char * pPlistName = new char[nNameLength+6];
&&strcpy(pPlistName,plistName);
&&strcat(pPlistName,&.plist&);
&&CCSpriteFrameCache *frameCache = CCSpriteFrameCache::sharedSpriteFrameCache();
&&frameCache-&addSpriteFramesWithFile(pPlistName);
&&CCArray* animFrames = CCArray::createWithCapacity(endFrame+1);
&&char str[100] = {0};
&&for(int i = beginF i & endFrame+1; i++)
&&&sprintf(str, findpngName,i);
&&&CCSpriteFrame *frame = frameCache-&spriteFrameByName(str);
&&&animFrames-&addObject(frame);
&&//设置动画名字
&&CCAnimation *animation = CCAnimation::createWithSpriteFrames(animFrames, frameSpeed);
&&//加入缓存
&&CCAnimationCache::sharedAnimationCache()-&addAnimation(animation, setAniName);
&&//CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();
&&//CCAnimation *action = animCache-&animationByName(setAniName);
&&CCTextureCache::sharedTextureCache()-&addImageAsync(pImageName,target,selector);
static CCAnimation * getAnimationByName(CHAR* setAniName,bool isRestoreOrgin = true)
&&CCAnimationCache *animCache = CCAnimationCache::sharedAnimationCache();
&&CCAnimation * animation = animCache-&animationByName(setAniName);
&&animation-&setRestoreOriginalFrame(isRestoreOrgin);
void HelloWorld::loadingProgress(cocos2d::CCObject * obj)
//在此处添加进度条Animation
&cocos2d::CCSprite * sp = cocos2d::CCSprite::create();
&sp-&initWithFile(&CloseNormal.png&);
&sp-&setPosition(ccp(100,200));
&this-&addChild(sp);
bool HelloWorld::init()
&& MyTools::buildAnimateByPlist(&Animation&,0,11,&EnemyBullet%02d.png&,&ebullet&,false,0.12,this,callfuncO_selector(HelloWorld::loadingProgress));
&&& CCAnimation * pre_ani_atk =MyTools::getAnimationByName(&ebullet&);
&&& CCAnimate*actoinwq = CCAnimate::create(pre_ani_atk);
&&&&CCSprite*m_Bullet = CCSprite::create(&hedan.png&,CCRect(0,0,30,70));&
&&& m_Bullet-&setPosition(ccp(200,200));
&&& this-&addChild(m_Bullet);
&&& m_Bullet-&runAction(actoinwq);
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:176791次
积分:2598
积分:2598
排名:第5362名
原创:34篇
转载:357篇
评论:29条
壶天的语像 .cn/wallydai zcmky的家 /zcmky/archive//1703397.html pjk1129专栏:http://blog.csdn.net/pjk1129/article/details/6593264 OpenGL ES学习网址 /portal.php?mod=list&catid=1 雨松MOMO的程序世界专栏:http://blog.csdn.net/xys/article/list/1
Techotopia:/index.php/Preparing_an_iOS_5_iPhone_App_to_use_iCloud_Storage 易飞扬:http://www.yifeiyang.net/ 禚 的iphone开发专栏:http://blog.csdn.net/diyagoanyhacker/article/category/846338 Marshal's Blog:/page/2 XML解析:/725/how-to-read-and-write-xml-documents-with-gdataxml
http :/dream-2011/powerful-asihttprequest-library-c.html
(1)(2)(2)(1)(2)(7)(2)(31)(15)(16)(7)(7)(7)(2)(2)(6)(4)(8)(4)(1)(4)(4)(1)(10)(4)(1)(3)(8)(8)(7)(1)(2)(21)(78)(112)主题 : cocostudio怎么使用texturepacker导出的plist,pngx游戏开发用来自动打包图片资源,生成plist和p
TexturePacker是一款用来打包程序资源的软件,特别是图片资源,可以减少程序的内存和优化效率,cocos2d-x开发游戏的使
TexturePacker是一款用来打包程序资源的软件,特别是图片资源,可以减少程序的内存和优化效率,cocos2d-x开发游戏的使用经常用到。本软件是一名叫Andreas Loew的国外朋友开发的,可以免费使用一周,之后需要付费使用。不过作者也提供给业内开发人员一个方便,只要你有自己的技术博客,就可以到官网上申请免费的license
申请免费key:
下面简单介绍如何使用该软件来打包游戏的图片资源,三步轻松搞定
1、把包含图片的目录拖入程序右边的方框Sprites区域,程序就会自动加载里面所有的图片资源,并在中间区域显示出来
2、配置最左边的TextureSettings信息,主要是选择Data file和Texture file保存的目录和文件名,分别是保存每个图片信息的plist文件和合成后的png图片,其他信息根据需要自己调整,默认可以不改动
3、点击程序上面的Publish按钮,即可生成plist和png两个文件,搞定
以上就是程序的使用步骤,很简单吧,之后就可以把plist和png两个文件放在程序的resources文件夹,用cocos2d-x里面的加载plist的方法加载任何一张png里面的小图片
例子如下:
CCSpriteFrameCache::sharedSpriteFrameCache()-&addSpriteFramesWithFile(&BG-hd.plist&);
CCSpriteBatchNode* batchNode = CCSpriteBatchNode::create(&BG-hd.png&,10);
this-&addChild(batchNode,0);
CCSprite* background = CCSprite::createWithSpriteFrameName(&skymap02.png&);
background-&setPosition(ccp(size.width/2,size.height/2));
this-&addChild(background,0);
其中BG-hd.plist和BG-hd.png就是使用TexturePacker生成的两个文件,而skymap02.png就是合成的png的里面的某张小图片的名字。
上一篇:cocos2d-x深入运行启动过程(win32)
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
核心技术类目
iOS Android
移动游戏 Windows Phone
Hadoop OpenStack
MySQL textview
可穿戴计算
XAML ASP.NET 前端开发
内核模块(1)
helloworld(1)
内核编译(1)
windows开发(1)
windows系统(2)
cocos2d-x(2)
linux 内核编译详解 (ubuntu 10.04 内核 2.6.32-36 升级内核 2.6.38.8 )(2833)
windows 7 80端口被NT kernel & System 占用 pid 4(1943)
用convert把FAT32转换NTFS失败出现文件或目录损坏且无法读取——解决办法(1004)
win7系统下安装XP双系统(710)
linux 内核模块加载 HelloWorld(398)
搭建Symbian OS S60 C++ 5th开发环境--RanJi(369)
Carbide.c++ IDE的常用快捷键和技巧 + Symbian OS的错误代码定义大全(315)
ubuntu 安装rpm包(ATI DISPLAY DRIVERS)(282)
Carbide.c++ IDE的常用快捷键和技巧 + Symbian OS的错误代码定义大全(134)
Carbide.c++ IDE的常用快捷键和技巧 + Symbian OS的错误代码定义大全(111)
(责任编辑:赵红霞)
------分隔线----------------------------
# -*- encoding: utf-8 -*-import urllibimport urllib2from urllib import urlencodei...
Top 20+ Java Developers’ BlogsThis topic has been in my mind for a very long ti...
问题描述一开始开始机器为Win7环境,使用的是域用户user.group(...
宫粉雕痕...
前言: FileUpload 服务器控件用多了,自己写html控件通过表单上传...
最近有点想写博客的冲动,不为别的,只为能为那些和我一样碰...您现在的位置:&&>>&&>>&&>>&&>>&正文
cocos2d-x开发之plist解析工具:Anti_TexturePacker(十二)
  之前拿了一些别人的图片素材,是用TexturePacker打包合成的,结果写程序的时候不知道每个合成前小png图的名字是什么,只能一个一个从plist文件中找,然后猜测对应的名字,再进行显示,如果不对,还要继续猜。。。坑爹啊,效率大大降低了,时间都耗在找图片名字上了。后来决定动手写一个解析plist的软件,就叫它Anti_TexturePacker吧。
  Anti_TexurePacker软件基于VS 2008 MFC Dialog。
  1.PNG图的显示
  这个还好,VS2008提供了GDI+,所以可以直接用它显示。关键是屏幕尺寸有限,如果打包后的PNG图很大的话,不能直接显示,又懒得做滚动条,所以直接采用缩放的方式了。缩放比例较大的话,可能会出现捕获点计算不精确,不过效果还是不错的,没有尺寸限制。
  CDC* pDC =GetDC();
  Graphics graphics( pDC-&m_hDC);
  Image image(m_PNGFileName.GetString(), FALSE);
  graphics.DrawImage(&image,ORIGIN_DRAW_X,ORIGIN_DRAW_Y,(int)(m_RealWidth*m_ScaleRatio),(int)(m_RealHeight*m_ScaleRatio));
  要注意PNG图的显示要放在OnPaint中执行,这样窗口进行重绘的时候才会保证PNG图的正常显示。
  2.plist文件的读取
  看一下plist的格式:
  这样一看,就知道了标准的plist文件中,我们需要的是第7,10,14,20,23,27…行。抓出规律,读取到CStringArray。我没有采用xml的解析库,而是直接无耻的这么做了,用起来倒是没什么问题,但是不要学啊。。。
  int i=1;
  int needName=7;
  int needConfig=10;
  int needrotate=14;
  if(!bFileExist)//如果文件存在且可读
  return FALSE;
  FileContainer.RemoveAll();
  //将PlistFile文件数据读到FileContainer
  while(PlistFile.ReadString(strline))
  if (i==needName)
  FileContainer.Add(strline);
  needName+=13;
  if (i==needConfig)
  FileContainer.Add(strline);
  needConfig+=13;
  if (i==needrotate)
  FileContainer.Add(strline);
  needrotate+=13;
  PlistFile.Close();
  然后再解析出CCStringArray中的名字和对应的坐标,尺寸,是否旋转赋值到一个结构体(包含Name,Width,Height,OriginX,OriginY,isRotate)。创建一个CList来储存这些结构体。
【责编:peter】
没有相关文章
?&[]?&[]?&[]?&[]?&[]?&[]?&[]?&[]?&[]?&[]
相关产品和培训
 友情推荐链接
 认证培训
 专题推荐
 ? ? ? ? ? ? ? ? ? ?
 今日更新
?&?&?&?&?&?&?&?&?&?&
 社区讨论
 博客论点
 频道精选
 C/C++频道相关导航

我要回帖

更多关于 backpacker 的文章

 

随机推荐