AS3 精灵表

编程入门 行业动态 更新时间:2024-10-18 08:31:55
本文介绍了AS3 精灵表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我有一张图片 mySprite.png.图像是 32x32 像素精灵的 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.

假设我在一个类中有一个 render() 函数,这个类如何从这个精灵表资源中将自己绘制为单个精灵?

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

推荐答案

简短的回答是您需要使用 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:

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

更多推荐

AS3 精灵表

本文发布于:2023-11-23 16:05:26,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1622069.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:精灵

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!