我正在尝试创建一个游戏,其中单击一个对象后,对象会发光。当我嵌入图像并将其传递到位图时,它可以正常工作,如下所示:
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。
有没有办法修复这种效果并让它与这样的类一起工作?
提前感谢!
_bx.像素是一个BitmapData,所以我认为它就这么简单。至少在我的测试设置中工作。
bigbitmap.copyPixels(_bx.pixels, new Rectangle(0, 0, 160, 288), new Point(16, 16), null, null, true);
真的不难找。
//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];