我正在尝试创建一个游戏,在您点击某个对象后,该对象会发光。当我嵌入一个图像并通过位图传递它时,它工作正常,如下所示:
package
{
import org.flixel.*;
public class HelloWorld extends FlxState
{
[Embed(source = "pics/Cancer.png")] private var cancerIMG:Class;
private var cancer:FlxSprite;
private var title_text:FlxText;
public function HelloWorld()
{
}
override public function create():void
{
/**
* Glow method test
*/
//Start Test
var bigbitmap:BitmapData = new BitmapData(320, 288, true, 0x00000000);
bigbitmap.copyPixels(Bitmap(new cancerIMG).bitmapData, new Rectangle(0, 0, 160, 288), new Point(16, 16), null, null, true);
cancer = new FlxSprite;
cancer.pixels = bigbitmap;
add(cancer);
//End Test
}
override public function update():void
{
super.update();
}
}
}
但是,每当我尝试使用相同的方法传递类精灵时,如下所示:
_bx = new box(120, 120);
var bigbitmap:BitmapData = new BitmapData(320, 288, true, 0x00000000);
bigbitmap.copyPixels(Bitmap(_bx.pixels).bitmapData, new Rectangle(0, 0, 160, 288), new Point(16, 16), null, null, true);
_bx.pixels = bigbitmap;
add(_bx);
我这样打电话:
public var _bx:box;
其中,本身就是一个FlxExtendedSprite(尽管为了测试,还是将它恢复为常规的FlxSprite)。当我尝试这个时,我得到错误:
错误#1034:类型强制失败:无法将flash.display :: BitmapData @ 3960701转换为flash.display.Bitmap。
有没有办法可以解决这个问题并让它与这样的类一起工作?
提前致谢!
答案 0 :(得分:1)
_bx.pixels是一个BitmapData,所以我觉得它就像这样简单。至少在我的测试设置中工作。
bigbitmap.copyPixels(_bx.pixels, new Rectangle(0, 0, 160, 288), new Point(16, 16), null, null, true);
答案 1 :(得分:0)
<强> Really not that hard to find.. 强>
//This goes in the package, at the top of your .as
import flash.filters.GlowFilter;
//This goes in your class
var myFilter:GlowFilter = new GlowFilter(0xffffff, 1, 1.5, 1.5, 30, 4); //(color, alpha, blurX, blurY, strength, quality);
//This goes wherever you want to apply this method
myMC.filters = [myFilter];