How do I set in advance the angle and other properties of multiple instances created at once ?

0 favourites
  • 6 posts
From the Asset Store
Change the size and position of everything without calculating anything!
  • Hello everyone !

    I'm trying to automate a particular behaviour of buttons being created at runtime.

    When the player clicks on a sprite ("Sprite1"), a serie of new smaller sprites ("Sprite2") should appear all around Sprite1.

    Every Sprite2 is visually linked to Sprite1 with a solid white line.

    In the end, the Sprite 2 should look like the rays of a sun, evenly distributed all around Sprite1, regardless of their number (for example, if 4 Sprite2 are created, they would each go in a different direction at 90°, but if there are 6 Sprite2, they would each be at 360/6° all around Sprite1, etc.)

    Then, once every SPrite 2 has appeared, they will each spawn another sprite ("Sprite3") on their center - but each one of those Sprite3 is different (but has to be distributed in the right order) - I have a hunch using families will be useful for that one...

    Here is the code I wrote for the spawn animation of Sprite 2 (composed of a line and a square) ; the sprite named "subbut_mouth01" corresponds to a Sprite3) ; to summerize : when the player clicks on a button, a white line is created on the originPoint of the button ; that line is created at 0 height, and goes to a 150px height with a lerp ; once that height is achieved, a white square is also created on the top origin point of the white line, and then, once the square is at the right dimensions, the Sprite3 appears in the square)

    And here is a quick sketch of what I'm trying to achieve :

    What I'm having difficulties with is :

    - automate the creation of Sprite2 with only a simple parameter (the number of instances to create) to adjust, with that parameter being also linked to the angle at which every new sprite2 should be created

    - specify in the code which sprite3 should go with which sprite2 (I'd like that to be "automatic", as long as there are the same number of sprite2 that appear as there are sprite3 needed to display.

    Thanks in advance for tour help and tips !

  • This is very easy to do with hierarchies and templates.

    Create all your hierarchies on a separate "Assets" layout. Select multiple objects, right-click the parent sprite and choose "Hierarchy - Add selection to this instance".

    Then in properties on the parent object set it as a template and give it a template name.

    Now when you create the parent object, you can specify which template to create it from, and if you tick "Hierarchy" textbox, it will be created with all its children objects.

    In your case you can use an invisible sprite as parent.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • If you have a different set of layers on your layout from the asset layout where you set up your templates you can't recreate them exactly. The hierarchy doesn't load the children into layers it doesn't have in the asset layout.

    just a caution here.

    yours

    winkr7

  • Thank you both, I'll try that !

    I was trying to set up all this without setting up in a "test" layout, which is kind of a way I already know about ; I was more looking for a totally code-dependant way of creating all this dynamically.

    Nonetheless, it's still a good advice to achieve my goal !

  • Var n=4

    On sprite clicked

    Repeat n times

    — create line at sprite.x, sprite.y

    — line: set width to 0

    — line: set angle to 360/n+45

    Every tick

    — line: set width to min(100, self.width+200*dt)

    Line: width=100

    Trigger once

    For each line

    — create sprite2 at line.x,line.y

    — sprite2: move 100 pixels at angle line.angle

    — create sprite3 at sprite2.x, sprite2.y

    — sprite3: set frame to loopindex

  • Thank you all !

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