Hi, I try to implent a rogue like dynamic light system to my game. At first I a raycasting method to get a Vector of Points that will form a shape to lighten up the scenery. With this method I want to create an image that forms my light source:
public function calculateSightfield(rays:Vector.<Point>):FXImage
{
FP.sprite.graphics.clear();
FP.sprite.graphics.beginFill(0x333333, 1);
var p:Point = new Point();
for each (p in rays)
{
if (p == Player.pos)
{
FP.sprite.graphics.moveTo(p.x, p.y);
}
else {
FP.sprite.graphics.lineTo(p.x, p.y);
}
}
FP.sprite.graphics.endFill();
var data:BitmapData = new BitmapData(dist*4, dist*4, true, 0xffffff);
data.draw(FP.sprite);
var img:FXImage = new FXImage(data);
img.color = 0x000000;
img.alpha = 1;
return img;
}
This works great in my 512x512 test level. But if I have a bigger level, f. e. 4096x2048 the light will only show up in area 512x512. So I fit the BitmapData dimensions to the map dimensions, now the light shows up, but the performance is very bad. I think the problem is the Sprite I create, it is as big as my map, filled with transparent pixels and a few that represents my light. How can I fix this?
PS: Sorry for my bad english!