AS3 Bitmap 和 beginBitmapFill 很有趣呐~

昨天测试网游的时候,发现同步其他人动作的时候,出了个神奇的bug. 只同步了阴影,人物的皮肤还停留在原地不动。

于是检查了下代码,发现阴影填充Bitmap,之后addChild(Bitmap) 。这应该是阴影和贴图不同步的原因。 但是嘛~之后做了个Demo似乎又没问题了。嘛~总之不管它了,换一个方法来实现。

索性就用 graphics.beginBitmapFill。然后呢 beginBitmapFill 是第一次用啊,一开始以为直接把 BitmapData丢进去就好了。结果发现显示不出来。然后就在那冥思苦想啊。然后觉得 有Begin嘛,肯定又要有End 于是加了个 endFill() 还是显示不出来。 于是就想莫非还要画个形状?

于是使用如下代码完成了整个贴图的绘制:

 
[cc lang=”actionscript3″ nowrap=”false”]
/**玩家皮肤**/
_bmd=skin;
this.graphics.beginBitmapFill(_bmd,new Matrix(1,0,0,1,-_bmd.width/2,-_bmd.height),true,false);
this.graphics.drawRect(-_bmd.width/2,-_bmd.height,_bmd.width,_bmd.height);
this.graphics.endFill();
/**绘制阴影**/
this.graphics.beginFill(0x000000,.7);
this.graphics.drawEllipse(-20,-20,40,20);
this.graphics.endFill();
[/cc]

果断成功了,有木有。因为都是直接画上去的,不是addChild上去的。所以皮肤和阴影都是一体的。

发表评论

电子邮件地址不会被公开。 必填项已用*标注