How do I generate text on a sprite?

Get help using Construct 2

Post » Fri May 15, 2015 6:53 am

Well tried to give the URL but I guess I don't have that privilege, the topic however is this:

How do I make a select/deselect operation happen w/ sprites?
Posts: 16
Reputation: 230

Post » Fri May 15, 2015 1:53 pm

Assume you are referring to something like selecting units in a RTS game or something?

Single sprite
If that's the case the easiest way to do it I think. (Of course depending if you are using multiple selection or just one at the time) But if you just need to select between different sprites, I would use a variable called "Selected_sprite_UID" and here you store the UID of a sprite when you click it for instant.

And then you always use this variable when you need to work with a sprite so you avoid suddenly picking wrong sprites. Since it can only hold one UID at the time, it will make certain of that.

For deselecting you can for instant do like this:
Code: Select all
On mouse Right click
Set Selected_sprite_UID = -1

Since an object can never have a negative UID that will work fine.

Multiple selection
If you are aiming for multiple selection, you can add a Boolean variable to your sprites called "Selected = False"

Code: Select all
On Mouse Left click on Sprite
     Set Sprite.Selected = True

Then when you need to do something with them.
Code: Select all
Sprite.Selected = True
For each Sprite
      <Do something>

Deselecting them:
Code: Select all
On Mouse right click
Sprite.Selected = True
     Set Sprite.Selected = False

Selection box
If you need a Selection box, you can do that with a 9-Patch
Code: Select all
9-patch overlapping Sprite
     Set Sprite.Selected = True

Deselecting is done the same way as with multiple selection.

To make a working selection box there are some tutorials to make it scale with the mouse as you drag in the tutorial section if I remember correct. However its not that difficult to make.
Posts: 1,209
Reputation: 7,537


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 63 guests