Please login or register.

Login with username, password and session length
Advanced search  

News:

Latest WME version: WME 1.9.1 (January 1st, 2010) - download

Author Topic: Can I run this flashlight script within a window  (Read 3019 times)

0 Members and 1 Guest are viewing this topic.

SOLO

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 23
    • View Profile
Can I run this flashlight script within a window
« 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


Logged
Best Regards
SOLO

piere

  • Supporter
  • Frequent poster
  • *
  • Karma: 4
  • Offline Offline
  • Posts: 301
  • Sorry for any bad english in my posts. Game on !
    • View Profile
Re: Can I run this flashlight script within a window
« Reply #1 on: April 13, 2012, 08:49:57 AM »

What about if you dynamically create a window?
Logged

SOLO

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 23
    • View Profile
Re: Can I run this flashlight script within a window
« Reply #2 on: April 13, 2012, 10:47:29 AM »

Dynamically??? how would I do that? and how would that help?
Logged
Best Regards
SOLO
 

Page created in 0.017 seconds with 23 queries.