AS3雪碧表 [英] AS3 Sprite Sheets

查看:190
本文介绍了AS3雪碧表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个形象mySprite.png。该图像是32×32像素的精灵一个5x5的网格。此图片已加载到项目的库。

I have an image mySprite.png. The image is a 5x5 grid of 32x32 px sprites. This image has been loaded into the project's library.

假设我有一个类中的渲染()函数,怎么会这个类绘制自身从这个精灵表资源的一个精灵?

Assuming I have a render() function inside a class, how would this class draw itself as a single sprite from this sprite sheet resource?

推荐答案

简短的回答是,你会想用<一个href="http://livedocs.adobe.com/flash/9.0/main/wwhelp/wwhimpl/common/html/wwhelp.htm?context=LiveDocs_Parts&file=00001400.html"相对=nofollow> BitmapData.copyPixels()从源精灵表复制只有一小部分,你的显示器的精灵,实际上是在屏幕上。

The short answer is that you will want to use BitmapData.copyPixels() to copy only a small section from your source sprite sheet to your display sprite that is actually on the screen.

是这样的:

private function DrawSpriteIndex( displayBitmap:Bitmap, spriteSheet:Bitmap, spriteIndex:int ):void {
  var spriteW:int = 32;
  var spriteH:int = 32;
  var sheetW:int = 5;

  displayBitmap.bitmapData.copyPixels(spriteSheet.bitmapData, 
                                       new Rectangle( (spriteIndex % sheetW) * spriteW, Math.floor(spriteIndex / sheetW) * spriteH, 32, 32),
                                       new Point(0,0)
                                      );
}

您可能会发现这些链接有用的 - 他们帮助我,当我正在学习这样的:

You may find these links helpful -- they helped me when I was learning this:

  • http://www.8bitrocket.com/2008/07/02/tutorial-as3-the-basics-of-tile-sheet-animation-or-blitting/
  • http://www.8bitrocket.com/newsdisplay.aspx?newspage=13430
  • http://www.8bitrocket.com/newsdisplay.aspx?newspage=14591
  • http://www.8bitrocket.com/newsdisplay.aspx?newspage=15967

这篇关于AS3雪碧表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆