在 Flash 中构建基于图块的地图
var square:Sprite = new Sprite();
var tileWidth:int = 32;
var tileHeight:int = 32;
var row:int = 0;
for (var i:int=0;i<5;i++) {
if (i > 0)
{
row = 32 * i;
}
square.graphics.beginFill(0x000000);
square.graphics.drawRect(row,0,32,32);
square.graphics.endFill();
addChild(square);
}
到目前为止,这是我的代码,square.graphics 是正确的方法吗?如何绘制作为图片的图块?我是否需要将图形保存在某种数组中以进行碰撞等检查?
var square:Sprite = new Sprite();
var tileWidth:int = 32;
var tileHeight:int = 32;
var row:int = 0;
for (var i:int=0;i<5;i++) {
if (i > 0)
{
row = 32 * i;
}
square.graphics.beginFill(0x000000);
square.graphics.drawRect(row,0,32,32);
square.graphics.endFill();
addChild(square);
}
This is my code so far, is square.graphics the way to go? How do I draw a tile that is a picture? Do I need to hold the graphics in some sort of array to do checking like collision?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您希望从中获得任何性能,则需要考虑位块传送等内容,或者在本例中将像素数据从源图像复制到单个显示对象。所以你用所有的瓷砖制作了一个疯狂的图像。然后,blit 引擎将表示该图块的图像的特定框复制到较大显示对象中的特定位置。
Google - as3 blitting - 或查看 http://freelanceflashgames.com/news/2010/02/08/bold-pixel-engine-an-as3-framework-for-games/
If you are going to desire any performance out of this, you need to look at things like blitting - or copying pixel data from a source image to single display object in this case. So you make a crazy image with all your tiles on it. Then your blit engine copies specific boxes of the image representing that tile to a specific place in the larger display object.
Google - as3 blitting - or check out http://freelanceflashgames.com/news/2010/02/08/bold-pixel-engine-an-as3-framework-for-games/