开发者

as3- passing a rectangle to sprite.graphics.drawRect( )

Is there a neat minimal way of doin开发者_JS百科g this? (this produces an error):

var freeSpace = shape.freeSpace() // returns Rectangle

var s:Sprite = new Sprite();

s.graphics.drawRect(freeSpace);

Just looking for a more cleaner way other than something like .drawRect(freeSpace.x, freeSpace.y, freeSpace.w, freeSpace.h)

I know you can do it with bitmapData.fillRect(rectangle), but need sprites in this case.


You could write your own class which extends Sprite

public class SpritePlus extends Sprite

and imlpements a method which does this:

public function drawRect(rect:Rectangle):void {
  this.graphics.drawRect(rect.x, rect.y, rect.width, rect.height);
}

Now you can do this:

var freeSpace:Rectangle = shape.freeSpace();
var s:SpritePlus = new SpritePlus();
s.drawRect(freeSpace);

But in my opinion, it's alright to use the Sprite's native method.

s.graphics.drawRect(freeSpace.x, freeSpace.y, freeSpace.width, freeSpace.height);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜