Wintermute Engine Forum
Wintermute Engine => Technical forum => Topic started by: SOLO on April 12, 2012, 12:04:59 PM
-
Hi Wintermutes,
I have this flashlight script that runs great for a scene but I need it to work over a window.
Is this possible?
Here is the flashlight script -
#include "scripts\base.inc"
////////////////////////////////////////////////////////////////////////////////
// a scene region the darkness is going to be stuck to
// create a dummy region and move it to the bottom of the scene nodes in SceneEdit
var ForegroundRegionName = "foreground";
// two images to build the darkness/flashlight overlay
var DarkImage = "flashlight\dark.png";
var LightImage = "flashlight\light2.png";
// dimensions of the above images
var TileWidth = 200;
var TileHeight = 200;
// transparency of the "darkness"
// set to 255 for solid black
var Alpha = 180;
////////////////////////////////////////////////////////////////////////////////
// setup
var MainLayer = Scene.MainLayer;
var NumTilesWidth = MainLayer.Width / TileWidth + 2;
var NumTilesHeight = MainLayer.Height / TileHeight + 2;
Initialize();
var LastPosX = -100;
var LastPosY = -100;
////////////////////////////////////////////////////////////////////////////////
// main loop
while(true)
{
// postion of the light
Update(Scene.MouseX, Scene.MouseY);
//Update(actor.X, actor.Y - actor.Height);
Sleep(100);
}
////////////////////////////////////////////////////////////////////////////////
function Update(PosX, PosY)
{
if(PosX==LastPosX && PosY==LastPosY) return;
LastPosX = PosX;
LastPosY = PosY;
var LightX = ToInt(PosX / TileWidth + 1);
var LightY = ToInt(PosY / TileHeight + 1);
var Ent;
var OffsetX = PosX - Math.Floor(PosX / TileWidth) * TileWidth + TileWidth / 2;
var OffsetY = PosY - Math.Floor(PosY / TileHeight) * TileHeight + TileHeight / 2;
for(var j = 0; j<=NumTilesHeight; j=j+1)
{
for(var i = 0; i<=NumTilesWidth; i=i+1)
{
Ent = Scene.GetNode(i + "-" + j);
var NewSprite;
if(i==LightX && j==LightY) NewSprite = LightImage;
else NewSprite = DarkImage;
if(Ent.GetSprite()!=NewSprite) Ent.SetSprite(NewSprite);
Ent.X = (i - 2) * TileWidth + OffsetX;
Ent.Y = (j - 2) * TileHeight + OffsetY;
}
}
}
////////////////////////////////////////////////////////////////////////////////
function Initialize()
{
for(var j = 0; j<=NumTilesHeight; j=j+1)
{
for(var i = 0; i<=NumTilesWidth; i=i+1)
{
var Ent = Scene.CreateEntity(i + "-" + j);
Ent.X = (i - 1) * TileWidth;
Ent.Y = (j - 1) * TileHeight;
Ent.Scalable = false;
Ent.Colorable = false;
Ent.Interactive = false;
Ent.SetSprite(DarkImage);
Ent.AlphaColor = MakeRGBA(255, 255, 255, Alpha);
Ent.StickToRegion(ForegroundRegionName);
}
}
}
Can someone help please?
Many thanks
Regards
Solo
-
What about if you dynamically create a window?
-
Dynamically??? how would I do that? and how would that help?