[Solved] How do I create click and place UI to game?

Get help using Construct 2

Post » Fri Apr 15, 2016 10:38 pm

im trying to click with mouse on a button then an object is created on the mouse and follows the mouse until clicked again where it is then placed down... the way im doing it now works terribly so has anyone got a better way of doing it...

heres how im doing it now;

Variable PlaceObj = 0
Mouse - On left button clicked on (button) - set PlaceObj to 1
- Create obj (object) at mouse.x, mouse.y

system - PlaceObj = 1 - Set position to round(mouse.x/16) * 16, round(mouse.y/16) * 16
- Every tick

mouse - on any click - set PlaceObj to 0
- set position to self.x, self.y

Issue with this is, it only lets me place one of each object.

P.S Sorry i dont know how to import image, tried making it as clear as i can.
Last edited by clarke2509 on Sun Apr 24, 2016 8:23 pm, edited 2 times in total.
B
7
S
1
Posts: 54
Reputation: 527

Post » Sat Apr 16, 2016 3:26 am

Try saving the UID of object created to a variable when it is created. Then add a Pick by unique ID condition to position that specific instance of the object under your mouse or place it.
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sat Apr 16, 2016 9:01 am

oosyrag wrote:Try saving the UID of object created to a variable when it is created. Then add a Pick by unique ID condition to position that specific instance of the object under your mouse or place it.


Can you explain to me how i do this please, I'm not familiar with the UID and cannot find a relative UID tutorial.
B
7
S
1
Posts: 54
Reputation: 527

Post » Sun Apr 17, 2016 1:18 pm

Anyone know how to do this, surely there is a more simple way of creating a click and drop UI... for example tower defence/RTS style UI
B
7
S
1
Posts: 54
Reputation: 527

Post » Sun Apr 17, 2016 3:25 pm

I'm not sure completely what is meant by "it only lets me place one of each object". Do you mean that pressing the button, dragging and putting down an object only works once ever? Or that you'd like to press the button, drag, and then keep clicking to put down as many as you want?
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Tue Apr 19, 2016 8:18 pm

mikehive wrote:I'm not sure completely what is meant by "it only lets me place one of each object". Do you mean that pressing the button, dragging and putting down an object only works once ever? Or that you'd like to press the button, drag, and then keep clicking to put down as many as you want?


I mean so i press the UI button, the object follow my cursor, i then press the button again to release the object, then if i press that same object in the UI again, the one i previously placed, disappears, it seems like a simple fix but i am unfamiliar with the UID system.
B
7
S
1
Posts: 54
Reputation: 527

Post » Wed Apr 20, 2016 6:59 am

Ahhh okay. Try putting this part of your events:
system - PlaceObj = 1 - Set position to round(mouse.x/16) * 16, round(mouse.y/16) * 16
- Every tick

mouse - on any click - set PlaceObj to 0
- set position to self.x, self.y


As sub-events under the first one, not as seperate events in their own right. This will ensure Construct knows you mean the object it just created, not all of that object.
Image



Coming soon on Steam!
B
16
S
9
G
3
Posts: 204
Reputation: 3,466

Post » Fri Apr 22, 2016 6:40 am

I've been away, see if this helps:

https://www.dropbox.com/s/ik6hdyma5qjui ... .capx?dl=0
Mistakes were made.
B
51
S
25
G
107
Posts: 1,581
Reputation: 60,458

Post » Sun Apr 24, 2016 8:24 pm

Thank you both for your help, the file was very helpful and i have it working now.
B
7
S
1
Posts: 54
Reputation: 527


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 10 guests