# [Solved] Area selection by sprite

### » Mon Sep 12, 2011 9:39 am

Hello.

I have a 32x32 sprite square attached to my mouse (with: ((floor ((MouseX) / 32) * 32) +16), ((floor ((MouseY) / 32) * 32) +16))) and I want when I click and as long as the button is pressed and I move the mouse, my sprite "spawn" other sprites, to form a rectangle whose diagonal is the distance between the first sprite and mouse.
When I release the button the rectangular area composed of sprites is created.

Basically, I want a selection box in multiples of 32 and I do not know how to do that.
I hope to be understandable.

Can you help?

Thank you in advance and I apologize for my English.Anxious2011-09-13 22:24:15
B
4
S
1
G
2
Posts: 9
Reputation: 1,393

### » Mon Sep 12, 2011 10:11 am

Based on what I think you meant:

Basically when you start holding down mouse, make 2 variables of where mouseX and Y is. When you stop holding down mouse button make 2 variables of where mouseX and Y is.

You now have enough coordinates to make a box. When mouse button is released make a loop for each side of the box, the length of the loop is based on the distance between each point of the box (then divide by 32 cause of your sprite size). Then create the sprite at the index of the loop.

CAP example
_alspal2011-09-12 10:19:18
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,857

### » Mon Sep 12, 2011 10:50 am

Thank you for your response Aspal.

Your solution is attractive but it gives strange results to the left and up. To the right and down, no worries.

Otherwise it's the idea, but I'm looking for sprites that also fills the interior of the area and we see the sprites while you move the mouse.

I don't know if it's possible to do this by adapting your solution.
B
4
S
1
G
2
Posts: 9
Reputation: 1,393

### » Mon Sep 12, 2011 11:42 am

B
168
S
81
G
22
Posts: 1,815
Reputation: 24,857

### » Mon Sep 12, 2011 12:05 pm

Yes, the principle is exactly that.

But unfortunately I think I can't use the "tilebackgroud" because I need it to be sprites.

Let me explain:
I have a lumberjack.
I want to select an area and create a sprite in each square of 32x32 included in the zone.
Once the area is created, my lumberjack will automatically be planting a tree on each sprite.
B
4
S
1
G
2
Posts: 9
Reputation: 1,393

### » Mon Sep 12, 2011 12:14 pm

I don't see the conflict? The one I showed you creates the 32x32 sprites. The 'tiled background' is just for display.
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,857

### » Mon Sep 12, 2011 12:48 pm

Yes you are right.
It works well.

There's just a lag between the creation of Tiledbackground and the sprites.
This can be seen with the selection of sprite attached a mouse that I added.
I try to fix that for the Tiledbackground coincides perfectly with the sprites.

Do you have a solution for this?

SpriteBox3.capAnxious2011-09-12 13:07:51
B
4
S
1
G
2
Posts: 9
Reputation: 1,393

### » Mon Sep 12, 2011 4:24 pm

Well, after trying some way I just can not fix this little detail.

It frustrates me even more that the solution has ASPAL exactly what I want (and I thank you greatly, Aspal) but no way to adjust the display of TiledBackground to create the sprites.

It really does not interfere with the operation because the sprites are created in the right place but it is not accurate especially when a line is drawn: the Tiled does not appear.

Does anyone have a solution to fix this?
B
4
S
1
G
2
Posts: 9
Reputation: 1,393

### » Tue Sep 13, 2011 12:56 am

I think I changed it to what you mean.

spritebox4.cap

Seems to work fine for me.
B
168
S
81
G
22
Posts: 1,815
Reputation: 24,857

### » Tue Sep 13, 2011 4:09 am

Might check out the rts basics template that comes with Construct.
B
178
S
50
G
206
Posts: 8,688
Reputation: 127,719

Next