Please login or register.

Login with username, password and session length
Advanced search  

News:

For WME related articles and tutorials visit WME Resource Center.

Author Topic: Dynamically Create Region Entity  (Read 3334 times)

0 Members and 1 Guest are viewing this topic.

serdar

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • serdar
Dynamically Create Region Entity
« on: August 01, 2010, 01:45:41 PM »

Hello,

Is it possible to dynamically create region entity?

I tried this code.
var myRegion = Scene.CreateEntity("myRegion");
myRegion.X = 1;
myRegion.Y = 1;

myRegion.Width = 100;
myRegion.Height = 300;

myRegion.AttachScript("scripts/myRegion.script");


on my attached script there i have this code.
on "LeftClick"
{
   Game.Msg("Click");
}


but leftclick is not working. also when i mouse over the area that region must be created cursor does not change. i think i miss something...

How can i achieve this?

I want to create this region dynamically because i wanted to add this region to all of my scenes...
Can you offer me an other way?
« Last Edit: August 01, 2010, 01:58:48 PM by serdar »
Logged

Mnemonic

  • WME developer
  • Administrator
  • Addicted to WME forum
  • *
  • Karma: 41
  • Offline Offline
  • Gender: Male
  • Posts: 5683
    • View Profile
    • Dead:Code Site
Re: Dynamically Create Region Entity
« Reply #1 on: August 01, 2010, 02:16:58 PM »

Hello, the proper way of constructing a dynamic region entity is this:

Code: WME Script
  1. // create a new entity
  2. var ent = Scene.CreateEntity("someEntity");
  3. ent.AttachScript("scripts/some_script.script");
  4.  
  5.  
  6. // attach a new region to the entity
  7. var region = ent.CreateRegion();
  8.  
  9.  
  10. // add some points to the region
  11. region.AddPoint(100, 100);
  12. region.AddPoint(150, 100);
  13. region.AddPoint(150, 150);
  14. region.AddPoint(100, 150);
  15.  
Logged
Yes, I do have a twitter account
Please don't send me technical questions in private messages, use the forum. ::wave

serdar

  • Lurker
  • *
  • Karma: 0
  • Offline Offline
  • Gender: Male
  • Posts: 11
    • View Profile
    • serdar
Re: Dynamically Create Region Entity
« Reply #2 on: August 01, 2010, 02:36:05 PM »

thank you very much.
 

Page created in 0.063 seconds with 25 queries.