Question about drag n drop !!

Get help using Construct 2

Post » Mon Oct 24, 2011 11:56 am

Hi, i'm playing around with this wonderful piece of software and i LOVE it.
One question !!!

Is there an easier way to make a drag and drop than the way i have done:
Made a global numeric variable and set it to 0.
Set sprite position to mousex and mousey if global var is 1
If sprite clicked set global var to 1
if mouse up set global var to 0


Cheers !!

Basseman2011-10-24 15:24:20
B
12
S
2
G
5
Posts: 31
Reputation: 3,494

Post » Mon Oct 24, 2011 3:11 pm

That's basically how I do that, but instead of using a global variable, I use an instance variable BOOLEAN typed.
so basically
on left click on sprite : selected to True
[NOT] left mouse down : selected to False
if selected : follow the mouse

Also I add an offset calculation to avoid the sprite to snap on the mouse position. For that I use 2 instance variable xOffset and yOffset

on left click on sprite :
    Sprite selected = True
    Sprite xOffset = self.X - Mouse.X
    Sprite yOffset = self.Y - Mouse.Y

if [NOT] left mouse down : selected to False

if selected :
    set X to Mouse.X+self.xOffset
    set Y to Mouse.Y+self.yOffset

Oh and my way works with multiple instances, yours don't.


Cheers too o/

Oh and... The title of your topic has nothing to do with what you askedYann2011-10-24 15:15:40
B
60
S
22
G
14
Posts: 1,479
Reputation: 16,346

Post » Mon Oct 24, 2011 3:23 pm

Thank you for your reply.. I will try it your way.
And about the topic.. Darn..
I edited the post but forgot to edit the topic...

Cheers !!!
B
12
S
2
G
5
Posts: 31
Reputation: 3,494


Return to How do I....?

Who is online

Users browsing this forum: Governador, tarek2, Thelegendvinny, Yahoo [Bot] and 19 guests