它会动画,但它会将精灵表中的一块放在精灵表上,而不是x和y告诉它的位置。它很短,所以请看一下?提前谢谢。
package cyanprime{
import flash.display.*;
import flash.geom.Rectangle;
public class Player{
[Embed(source="brownplane.png")]
public var image:Class;
public var bitmapdata:BitmapData = getBitmap(new image());
public var bitmap:Bitmap = new Bitmap(bitmapdata);
public var speed:int = 5;
public var x:int = 50;
public var y:int = 50;
public var frame:int = 0;
public function getBitmap(img:DisplayObject):BitmapData{
var drawRect:Rectangle = new Rectangle((img.width/3) * frame, 0, img.width/3, img.height);
var bitmap:BitmapData = new BitmapData(img.width, img.height);
bitmap.draw(img,null,null,null,drawRect);
return bitmap;
}
public function animate():void{
bitmap.bitmapData = getBitmap(new image());
frame++;
if(frame > 2)
frame = 0;
bitmap.x = x;
bitmap.y = y;
}
}
}
答案 0 :(得分:1)
看起来你需要为draw()添加一个矩阵变换来平移正在绘制的矩形的位置。像这样:
var trans:Matrix = new Matrix();
trans.tx = drawRect.x;
bitmap.draw(img,trans,null,null,drawRect);
如果这不起作用,请尝试-drawRect.x
,我无法完全记住如何应用该转换。