精灵的设置锚点到中年 [英] Setting anchor point of sprite to middle
问题描述
我生成精灵编程是这样的:
this.food =新的Sprite();
this.food.graphics.beginFill(0XFFFFFF);
this.food.graphics.drawRect(0,0,10,10);
this.food.filters =新的GlowFilter(0xFF6699,0.80,5,5,2,2,假的,假的);
this.food.graphics.endFill();
this.food.x = this.x;
this.food.y = this.y;
this.stage.addChild(this.food);
和后来我做这样的:
公共功能的更新():无效
{
//旋转食品
this.food.rotation + = 1;
}
我基本上要的食物精灵慢慢旋转围绕其中心,而不是它的x和y的值是精灵的左上角。
我怎样才能让锚精灵的中心?
使用的前两个参数<一href="http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/Graphics.html#drawRect%28%29"相对=nofollow> 的drawRect()
以抵消显卡:
的drawRect(-5,-5,10,10);
参数
X:数
- 一个数字,指示的水平位置相对 父显示对象注册点(像素)。
Y:数
- 一个数字,指示垂直位置相对的 父显示对象注册点(像素)。
宽度:数
- 矩形的宽度(以像素为单位)
。高度:数
- 矩形的高度(像素)
我们的想法是要减去一半宽度
和高度
从 X <的/ code>和
是
来中心。
I am generating sprites programatically like this:
this.food = new Sprite();
this.food.graphics.beginFill(0xFFFFFF);
this.food.graphics.drawRect(0, 0, 10, 10);
this.food.filters = [new GlowFilter(0xFF6699, .80, 5, 5, 2, 2, false, false)];
this.food.graphics.endFill();
this.food.x = this.x;
this.food.y = this.y;
this.stage.addChild(this.food);
And later on I'm doing this:
public function update():void
{
// Spin the food
this.food.rotation += 1;
}
I basically want the food sprite to spin slowly about its center, not its x and y value which is the top left corner of the sprite.
How can I make the anchor the center of the sprite?
Use the first two parameters of drawRect()
to offset the graphics:
drawRect(-5, -5, 10, 10);
Parameters
x:Number
— A number indicating the horizontal position relative to the registration point of the parent display object (in pixels).
y:Number
— A number indicating the vertical position relative to the registration point of the parent display object (in pixels).
width:Number
— The width of the rectangle (in pixels).
height:Number
— The height of the rectangle (in pixels).
The idea is to subtract half of the width
and height
from the x
and y
to centre.
这篇关于精灵的设置锚点到中年的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!