Wintermute Engine Forum

Wintermute Engine => Scripts, plugins, utilities, goodies => Topic started by: metamorphium on January 10, 2010, 09:22:20 PM

Title: Interactive theora entities - tutorial
Post by: metamorphium on January 10, 2010, 09:22:20 PM
Hi muties,

this one will be short but for those of you who are using theora entities in your scripts and thought they are not interactive, I provide the following trick, how to mend this.

Logic behind the following code is, that WME now supports creating own regions even if there's none. So we'll creating bounding region ourselves manually.

We'll presume your theora is square 128x128 points, other shapes are just a matter of using more region points.
First in Scene Edit create an empty entity and call it test, then in scene_init.script type something like this:

Code: WME Script
  1. var ent = Scene.GetNode("test");
  2. ent.PlayTheora("your ogv file goes here",true,"your mask goes here"); // so our theora is playing now!
  3.  
  4. ent.CreateRegion(); //we create a new region so our entity will become interactive
  5.        
  6. var region = ent.Region;
  7.        
  8. region.AddPoint(ent.X, ent.Y);
  9. region.AddPoint(ent.X, ent.Y + 128);
  10. region.AddPoint(ent.X + 128, ent.Y + 128);
  11. region.AddPoint(ent.X + 128, ent.Y);
  12. ent.Interactive = true;
  13.  

Piece of cake, no? Now you can easily click your theora entity.

But wait what if you want to move it around on the screen? Simply update the region nodes based on current theora position!

Code: WME Script
  1. var ent = Scene.GetNode("test");
  2. var region = ent.Region;
  3. region.SetPoint(0,ent.X, ent.Y);
  4. region.SetPoint(1,ent.X, ent.Y + 128);
  5. region.SetPoint(2,ent.X + 128, ent.Y + 128);
  6. region.SetPoint(3,ent.X + 128, ent.Y);
  7.  

That's all folks. Hope you find it as useful as I did for my game. :)