How do I drag a newly created object instantly

0 favourites
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • 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:

    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

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

  • 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

  • The second time you're picking up the first one you spawned.. not the newly created one.

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

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

  • Ok so i've read this:

    [quote:2wz31p0s]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:

    [quote:2wz31p0s]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

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

  • 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

  • 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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • You can try making at start of layout the first ball to have the "Drag & Drop" behavior disabled, and when the second object has created, pick him by UID and set the bahavior "Drag & Drop" enabled for the object with this UID.

    This is a possibility, and will be nice if you can do this with Construct 2.

  • Oh, sorry. Your problem in this is already solved to make the next ball draggable. Way to bring it to the front so it has the effect of popping out of the original sprite? My poor suggestion is using the action "(OBJECT) set to top of layer".

  • 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

    Is there a reason that won't work for you?

    edit: how about this. Sorry I'm pretty rusty.

    https://www.dropbox.com/s/nxc1fadm55ugp4t/drag_from_sprite_top.capx?dl=0

  • [quote:22876nhg]Oh, sorry. Your problem in this is already solved to make the next ball draggable. Way to bring it to the front so it has the effect of popping out of the original sprite? My poor suggestion is using the action "(OBJECT) set to top of layer".

    That's ok I appreciate anyone weighing in on this.

    [quote:22876nhg]Is there a reason that won't work for you?

    Your example there works perfectly, strangely however when I recreate it, it drags the first sprite underneath but then all the rest on top, I have added more 'draggable' sprites into the same family and it seems to work the same for all 3 (so far) so it's like one last little peace of the puzzle and it'll be perfect

    (only changes I made was naming the family 'Draggables' instead of 'other sprite' and making the family instance variable 'Dragid' instead of 'id')

    I'll keep tweaking it, but if anyone sees any reason why the first is going under and the rest over, let me know

  • Ok so I thought I'd post my findings in case anyone looks through this thread in the future,

    This is what I came up with (based of codahs suggestion!) just tweaked for my purposes of bringing out a new instance on top and moving to a new layer all in one click / drag out

    Thanks to everyone for your suggestions

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