How do I spawn a new instance with new attributes?

0 favourites
  • 10 posts
From the Asset Store
Create your game with this complete pack of images and animations!
  • Essentially what I am trying to do is to present a menu of static items and allow the player to click and drag a new instance of a menu item out of the menu area. I want this new instance to have drop and drag behaviors, gravity, etc. and I cannot figure out a means of applying new behaviors, etc. to a newly spawned instance.

    To be clear, the items in the menu area do not move and only the newly spawned instance of the menu item should have any functions. In other words, if there is a bowling ball in the menu area, clicking/holding that bowling ball causes a new bowling ball to spawn in the exact spot and then follow the cursor along until released while the original bowling ball remains static and can be clicked/held again and again to duplicate the same functionality.

    Thanks!

  • You would just create a new bowling ball with drag and drop behaviour when you click on the bowling ball menu icon. So the menu version is an icon, this can be a different object. When this icon is clicked you create a bowling ball at cursor xy.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks but I still don't see how to actually pull it off. In other words, I can't figure out how to apply behaviors (such as Drag and Drop) to an instance that does not yet exist on the stage.

  • If you have a bowling ball somewhere on the layout with drag/drop behaviour, then every bowling ball you create will have the behaviour.

  • So, the "trick" is not to create an instance of the menu bowling ball but to have a completely different symbol hidden or offstage (or whatever) that has the desired properties?

  • Not a different object, but the same object. You need to do this anyway or Construct won't let you create the object. You will get an error saying instance of object does not exist. Construct will take attributes from the first instance of an object and apply it to future instances. You can hide this somewhere off-screen or destroy it at the start of the game/ on layout load.

  • I'm sure that I'll figure it out eventually but your advice isn't clear to me. If the object to be clicked is the same as the object being spawned then I am right back to my initial question: how can I apply behaviors and parameters to one instance of an object that does not globally apply to all instances of that object UNLESS I create two different symbols/objects that only look the same? The object being clicked should not have drag and drop attributes or be functional in any way other than operating as a clickable object/icon.

  • Yeah my advice was to make the clicked object a different object, because I couldn't see why it needs to do be a drag/drop bowling ball if it is simply an icon you click in a menu? You can alter values when something is spawned, using the On Created condition, where you can say something like On Created > Enable drag/drop behaviour, where the clickable version has the drag/drop behaviour disabled by default.

    To answer your question in a more general sense, Construct is all about picking. When you use 'on created' it picks the created instance and applies only to this. If you say change such a variable on bowling ball without picking a specific one with a condition then it will apply this to all bowling ball instances. It's really up to you to define in some way which of the bowling ball instances will change.

  • Okay... well, I've made a tiny bit of progress but I continue to run head-first into the absence of in-depth documentation for this program. I'm now able to touch > hold_over the static version of the object to spawn an alternate version that has the properties that I want BUT the touch > hold action is not being applied to the newly created (and draggable) symbol (which makes functional sense) - the end result being that I'm failing to pull off what should be a pretty simple thing (the syntax evades me).

    Now I'm thinking that maybe I should have the draggable version there all along but make it invisible. Then doing a touch > hold on the invisible one (which would be laid directly over the static icon version) would spawn a new invisible symbol below the current one (in the event that the user wanted to drag out more than one), turn the clicked one visible and allow it to be dragged. Does that make sense?

  • Yeah you could do something like that. On click or drag start, create a new instance that stays there for next time, essentially becoming the new clickable icon.

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