It animates but it put's the piece of the sprite sheet where it is on the sprite sheet and not where the x and y tell it to. It's very short, so please take a look? Thank you in advance.
它会动画,但它会将精灵表中的一块放在精灵表上,而不是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;
}
}
}
1 个解决方案
#1
Looks like you need to add a matrix transform to draw() to translate the position of the rectangle being drawn. Something like this:
看起来你需要添加一个矩阵变换到draw()来转换正在绘制的矩形的位置。像这样的东西:
var trans:Matrix = new Matrix();
trans.tx = drawRect.x;
bitmap.draw(img,trans,null,null,drawRect);
If that doesn't work, try -drawRect.x
, I can't exactly remember how that transform is applied.
如果这不起作用,请尝试-drawRect.x,我不能完全记住如何应用该转换。
#1
Looks like you need to add a matrix transform to draw() to translate the position of the rectangle being drawn. Something like this:
看起来你需要添加一个矩阵变换到draw()来转换正在绘制的矩形的位置。像这样的东西:
var trans:Matrix = new Matrix();
trans.tx = drawRect.x;
bitmap.draw(img,trans,null,null,drawRect);
If that doesn't work, try -drawRect.x
, I can't exactly remember how that transform is applied.
如果这不起作用,请尝试-drawRect.x,我不能完全记住如何应用该转换。