Please login or register.

Login with username, password and session length
Advanced search  

News:

This forum provides RSS feed. To query recent posts use this url. More...


Author Topic: Interactive theora entities - tutorial  (Read 2260 times)

0 Members and 1 Guest are viewing this topic.

metamorphium

  • Global Moderator
  • Addicted to WME forum
  • *
  • Karma: 12
  • Offline Offline
  • Gender: Male
  • Posts: 1511
  • Vampires!
    • View Profile
    • CBE  software s.r.o.
Interactive theora entities - tutorial
« 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. :)
Logged
J.U.L.I.A. Enhanced Edition, Vampires!, J.U.L.I.A., J.U.L.I.A. Untold, Ghost in the Sheet
 

Page created in 0.211 seconds with 22 queries.