[Solved] Area selection by sprite

This forum is currently in read-only mode.
From the Asset Store
Selection frame like in RTS games, works both on mobile and desktop devices.
  • Hello.

    I need your help.

    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.

  • 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.

    <img src="http://dl.dropbox.com/u/1024727/caps/selectbox.JPG" border="0">

    CAP example

    _

  • 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.

  • 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.

  • I don't see the conflict? The one I showed you creates the 32x32 sprites. The 'tiled background' is just for display.

  • Yes you are right.

    I answered too quickly without your eventsheet observe.

    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.cap

  • 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?

  • I think I changed it to what you mean.

    spritebox4.cap

    Seems to work fine for me.

  • Might check out the rts basics template that comes with Construct.

  • well you dont need to "spawn" a bunch of stuff, you can set the width/height to the x,y size of the box.

    in essence you just need to store the initial position of your click when you click using (((floor ((MouseX/Y) / 32) * 32) +16))like you have already (and seem to understand) in a variable like INITIAL CLICK X, INITIAL CLICK Y, for x y respectively, then from there on if mouse button is down set the width of the box to ((floor ((MouseX) / 32) * 32) +32)-'INITIAL CLICK X') and height to ((floor ((MouseY) / 32) * 32) +32)-'INITIAL CLICK Y'). you might need to adjust the +32 part depending on how your sprite is positioned, but you seem like you'll be able to figure that out.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • Very good job, Alspal, is exactly the result I expected.

    As I could not solve this problem, I have everything taken from zero while trying to serve me a sprite instead of "TiledBackgroud" based on the mechanisms that you made me understand in your solution.

    And joy, I got it to work perfectly.

    SpriteBox.cap

    So this morning I just post my solution (French time) and I also see that you solved the problem.

    Looking your .cap, I realize that our solutions are very close even though in the end, yours is simpler, more elegant and above half as long .<img src="smileys/smiley4.gif" border="0" align="middle">

    I think my solution and that of Aspal put into practice what you said, QuaziGNRLnose, and finally the difference is only the use of a sprite for my part, and "TiledBackground" for Alspal.

    I looked a bit the template RTS, Newt, but it was not really what I was looking for.

    Anyway, a big thank you, especially Alspal. <img src="smileys/smiley32.gif" border="0" align="middle">

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)