Select box following the mouse (rts like)

grandfso

  • Posts: 4
Hi,
I am trying to create a behaviour, that will allow me to create a select area, similar to these they use in strategy games like starcraft or warcraft. I think there's is no need to describe this further ;)
I am asking, because I have absolutely no clue how to tackle this one. I googled stencylopedia, but nothing there's even close to what I'm looking for ?

any ideas?

brantsmith

  • Posts: 151
The easiest thing I could think of off the top of my head is to create a global list. have each actor (that can be selected) to always add its x and y coords to the list. This way you have a list that has the exact position for all selectable actors. now onto the mouse selection part. record the x and y of the mouse on mousedown, and then record the mouse x and y on mouseup. you can use the draw line tools to dynamically draw a square using those 2 points. Now, after the mouse is released, check each entry in your global list to see if the x and y coords are within the selected bounds.
Coding is Awesome.
Stencyl is Better.

Tuo

  • *
  • Posts: 2469
No lists are needed, just knowing how to manipulate the blocks. Here you go:
Don't look to me but rather to the One who is the reason for what I do. :)

If you need help, send me a PM. Even if I haven't been on in the forums in ages, I still receive those messages via email notifications. You can also reply to any of my forum posts, regardless of the age (especially if I created it), and I will likely reply.

If you want to see the programming behind certain types of games, feel free to check out my "Demo-" games on StencylForge (http://community.stencyl.com/index.php/topic,16160.0.html)

brantsmith

  • Posts: 151
yah. that is definitely easier than my idea.
Coding is Awesome.
Stencyl is Better.

Hectate

  • *
  • Posts: 4643
I did this forever ago using a region created when the mouse was released,  with one corner from the release and the other from where the mouse was first pressed. Just draw a box to match and you’re good to go, mostly.
:
:
Patience is a Virtue,
But Haste is my Life.
Proud member of the League of Idiotic Stencylers; doing things in Stencyl that probably shouldn't be done.