light and stuff
- I-smel
-
I-smel
- Member since: Mar. 2, 2006
- Offline.
-
- Forum Stats
- Member
- Level 01
- Game Developer
Hey I'm makin a stealth game.
It'd be good if I had the whole room dark, but there were circles of visibility around the player and the enemies. Like gradients that blend into each other, or something..
Is this even possible?
- Innermike
-
Innermike
- Member since: Sep. 11, 2009
- Offline.
-
- Forum Stats
- Member
- Level 14
- Blank Slate
At 11/18/10 03:17 PM, I-smel wrote: Hey I'm makin a stealth game.
It'd be good if I had the whole room dark, but there were circles of visibility around the player and the enemies. Like gradients that blend into each other, or something..
Is this even possible?
Well it seems like you've done it right there, unless you're talking about something else, in which case could you go into more detail?
nobody
- I-smel
-
I-smel
- Member since: Mar. 2, 2006
- Offline.
-
- Forum Stats
- Member
- Level 01
- Game Developer
Well that's just a mock-up to show what I want it to look like.
I want that to happen IN-GAME so that the two circles of visibility can both flow around normally.
- AntiAliasProductionz
-
AntiAliasProductionz
- Member since: Apr. 20, 2008
- Offline.
-
- Forum Stats
- Member
- Level 08
- Blank Slate
At 11/18/10 03:17 PM, I-smel wrote: Hey I'm makin a stealth game.
It'd be good if I had the whole room dark, but there were circles of visibility around the player and the enemies. Like gradients that blend into each other, or something..
Is this even possible?
as3 or as2?
In as3 you could just add the child to the player movieclip
player_mc.addChild(gradient_mc); - CyanSandwich
-
CyanSandwich
- Member since: Aug. 14, 2009
- Offline.
-
- Forum Stats
- Member
- Level 41
- Programmer
If it's just what's in the picture you want + following them around..
light._x = player._x //and so on
Or did you want the room to be pitch black and have actual visibility gradients?
I wouldn't really know what to do there :l
- I-smel
-
I-smel
- Member since: Mar. 2, 2006
- Offline.
-
- Forum Stats
- Member
- Level 01
- Game Developer
I got close here:
http://www.newgrounds.com/dump/item/9de2 cd5f035fdace628c3eca0e925291
but it's far too code-heavy to be actually usable :/
- knugen
-
knugen
- Member since: Feb. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 42
- Programmer
It uses BitmapData which I would guess is the best method. Perhaps there are better implementations, but it should work just fine unless your game requires an extreme amount of optimization.
Let me know if this is what you're looking for and I'll PM you the source :)
(AS3 btw, but I believe BitmapData was introduced in Flash 8 so it might very well be possible to convert if you're using AS2)
- I-smel
-
I-smel
- Member since: Mar. 2, 2006
- Offline.
-
- Forum Stats
- Member
- Level 01
- Game Developer
Argh I shoulda known it was BitmapData. Whenever I don't know how to do some kinda special effect it's allways AS3 bitmapdata.
I'm usin Flash 8, I don't think I'll be able to do it.
- Doomsday-One
-
Doomsday-One
- Member since: Oct. 28, 2005
- Offline.
-
- Forum Stats
- Member
- Level 10
- Programmer
At 11/18/10 06:05 PM, I-smel wrote: Argh I shoulda known it was BitmapData. Whenever I don't know how to do some kinda special effect it's allways AS3 bitmapdata.
I'm usin Flash 8, I don't think I'll be able to do it.
Na, you should be able to. I did something similar in Flash 8 some time ago, so you should be fine.
Using cacheAsBitmap() would also allow you to achieve the effect, I would imagine.
Doomsday-One, working on stuff better than preloaders. Marginally.
- knugen
-
knugen
- Member since: Feb. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 42
- Programmer
Wow it has been a long time since I did AS2, and I can't say I missed it :) It was pretty straight-forward to convert the code though:
AS3
import flash.display.BitmapData;
import flash.filters.BlurFilter;
var bmp:Bitmap = new Bitmap();
addChild(bmp);
addEventListener(Event.ENTER_FRAME, onEF);
function onEF(e:Event):void
{
d4.x = mouseX; d4.y = mouseY;
var bmpd:BitmapData = new BitmapData(550, 400, true, 0xFF000000);
var objects:Array = [d1, d2, d3, d4];
for (var i:int = 0; i < objects.length; i++)
{
var obj:DisplayObject = objects[i] as DisplayObject;
var matrix:Matrix = new Matrix();
matrix.tx = obj.x;
matrix.ty = obj.y;
bmpd.draw(gradient, matrix, null, BlendMode.ERASE);
}
bmpd.applyFilter(bmpd, new Rectangle(0, 0, 550, 400), new Point(), new BlurFilter());
bmp.bitmapData = bmpd;
}
AS2
import flash.display.BitmapData;
import flash.filters.BlurFilter;
import flash.geom.Matrix;
createEmptyMovieClip("bmp", getNextHighestDepth());
onEnterFrame = function()
{
d4._x = _xmouse; d4._y = _ymouse;
var bmpd:BitmapData = new BitmapData(550, 400, true, 0xFF000000);
var objects:Array = [d1, d2, d3, d4];
for (var i:Number = 0; i < objects.length; i++)
{
var obj:MovieClip = objects[i];
var matrix:Matrix = new Matrix();
matrix.translate(obj._x, obj._y);
bmpd.draw(gradient, matrix, null, "erase");
}
bmpd.applyFilter(bmpd, bmpd.rectangle, new Point(0, 0), new BlurFilter(4, 4, 2));
bmp.attachBitmap(bmpd, 1);
}
d1, d2, d3 and d4 are the dots you see in the example. Regular MovieClips. gradient is a MovieClip as well, and it contains a circle with an alpha radial gradient (100% where you want full transparency and 1% where you want none, so 100% in the middle):
- knugen
-
knugen
- Member since: Feb. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 42
- Programmer
At 11/18/10 06:45 PM, Doomsday-One wrote: Using cacheAsBitmap() would also allow you to achieve the effect, I would imagine.
Huh?
- I-smel
-
I-smel
- Member since: Mar. 2, 2006
- Offline.
-
- Forum Stats
- Member
- Level 01
- Game Developer
WOW thanks. Now this game can look way less ametuer.
I knew setting the blend mode to Erase would have somethin to do with this but I could never get it to work.
- Doomsday-One
-
Doomsday-One
- Member since: Oct. 28, 2005
- Offline.
-
- Forum Stats
- Member
- Level 10
- Programmer
At 11/18/10 07:13 PM, knugen wrote:At 11/18/10 06:45 PM, Doomsday-One wrote: Using cacheAsBitmap() would also allow you to achieve the effect, I would imagine.Huh?
Please don't say "Huh?", it makes me think that I've made a huge mistake. Now I'm paranoid!
Anyway, cacheAsBitmap() allows a user to create masks which take _alpha values into account, allowing a similar effect to be created.
Doomsday-One, working on stuff better than preloaders. Marginally.
- knugen
-
knugen
- Member since: Feb. 7, 2005
- Offline.
-
- Forum Stats
- Member
- Level 42
- Programmer
At 11/18/10 08:40 PM, Doomsday-One wrote: Please don't say "Huh?", it makes me think that I've made a huge mistake. Now I'm paranoid!
Anyway, cacheAsBitmap() allows a user to create masks which take _alpha values into account, allowing a similar effect to be created.
Ah alpha masks, that explains it :) I was confused because cacheAsBitmap alone cannot have any impact on visuals.
I think that the BitmapData method is better performance wise, but alpha masks might be easier to implement. Just guessing though :)

