How do I drag a newly created object instantly

Get help using Construct 2

Post » Sun Jun 14, 2015 4:35 pm

Hello everyone :)
I'm working on a project that involves the following example,

I have a sprite of a BeachBall image with no behaviours, then a clone of that sprite with a drag and drop behaviour,
the idea is that I'm using the first BeachBall sprite (with no behaviours) as a button that - when pressed - creates the second BeachBall sprite (with the drag and drop) over the top of the 'button' and instantly starts dragging it.

So I made it look like this:
Image

It's almost there but currently what happens is that it creates the new sprite on top of the 'button' but doesn't let me drag it out with the same press, is there a way to tell the new sprite to start being dragged as soon as it's created?

Thanks for any assistance :geek:
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Sun Jun 14, 2015 4:56 pm

You need a global variable to store the newly created BeachBall UID.
An event will snap the BeachBall with this UID to your Touch coordination.

On created Object "BeachBall" : Set Global Variable "BeachBallUID" to BeachBall.UID

On Touching the screen
------Pick Object by UID = Globalvariable BeachBallUID : Set BeachBall position to Touch.X and Touch.Y

gl!
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,370

Post » Sun Jun 14, 2015 5:42 pm

Thanks ikke2902 I'll look into this!

I thought I'd follow up though by showing the demo of how it's working right now
http://www.jmkit.com/mgame/dragouttest/
If you notice, what happens the first time you click or drag over the ball.. The new sprite is created over the top of it (slightly bigger) but doesn't drag out.. However the next time you do the same thing, another new sprite is created but drags straight out O_O

So I'm just a little confused why it can't do that the first time with the same code
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Sun Jun 14, 2015 5:57 pm

The second time you're picking up the first one you spawned.. not the newly created one.
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,670

Post » Sun Jun 14, 2015 6:04 pm

Ah, so it's creating one underneath the new one at the same time as dragging it away.. That sounds about right :)

Well I guess if creating a variable for every object is the only way, I'll do that, it's just my project involves a lot of 'draggable' sprites so any where I can shave off code and variables I'd like too.
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Sun Jun 14, 2015 6:19 pm

JMKit wrote:Ah, so it's creating one underneath the new one at the same time as dragging it away.. That sounds about right :)

Well I guess if creating a variable for every object is the only way, I'll do that, it's just my project involves a lot of 'draggable' sprites so any where I can shave off code and variables I'd like too.


Should be doable with just one IsDraggingUID..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sun Jun 14, 2015 9:54 pm

Ok so i've read this:
You need a global variable to store the newly created BeachBall UID.
An event will snap the BeachBall with this UID to your Touch coordination.

On created Object "BeachBall" : Set Global Variable "BeachBallUID" to BeachBall.UID

On Touching the screen
------Pick Object by UID = Globalvariable BeachBallUID : Set BeachBall position to Touch.X and Touch.Y


and:
Should be doable with just one IsDraggingUID..


And I am a newb to the finer points of Construct2 - (I'm coming from a game made in flash / AS3 and learning the new ways around here to convert it as my first main project) I'm defiantly more of a visual designer which is why I'm enjoying working in this platform and being able to add behaviours with a click.

So this sounds like more slightly finer detail work than that, can someone show an example of how this would look in practice, it will help me get a handle of it and hopefully let me understand more in future. Thanks :)
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Tue Jun 16, 2015 8:10 pm

Can anyone tell me where to find 'IsDraggingUID', I've been looking and can't find any commands that look like that.
I'd like to just say, when the new ball is created, start dragging it. Sorry if that's been explained above but I just can't figure out how to actually put that in anywhere.. Thanks for any further help.
B
16
S
4
Posts: 50
Reputation: 1,035

Post » Wed Jun 17, 2015 2:09 am

Hi, bit late to this party but here's a sample I did last year, see if it helps.

https://www.dropbox.com/s/vuvvvinzqu2b066/drag_from_sprite.capx?dl=0
B
24
S
9
G
4
Posts: 1,646
Reputation: 6,596

Post » Wed Jun 17, 2015 2:26 pm

Hey, codah - not late at all thanks for your input!
So I thought that example was just what I was looking for, however if you put any kind of pattern on that green square and drag it out, you'll see it's still dragging from underneath, is there no way to bring it to the front so it has the effect of popping out of the original sprite, seems everything i try just makes it come from underneath O_o
B
16
S
4
Posts: 50
Reputation: 1,035

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 52 guests