0 Favourites

Create object between 2 created blocks.

  • I've got blocks being created and they scroll accoss the screen. They're created at the top and bottom of the screen and they're at random times between 0.5 & 2 seceonds.

    Basically, i want to create another seperate object in between those created blocks. I can create the additional object but i'm having trouble trying to get them to spawn only in between the blocks.

    How do i do this?

    Also, i wanted it so that the object is created if the blocks are within a certain distance. So for example, if there is a gap of 0.5sec between the two created blocks, then the objects doesn't spawn, but if it's something like 1sec or higher, then they can spawn between them.

    I hope i made it clear, it's a bit difficult to describe.

    https://www.dropbox.com/s/9mngq42zrhp8k0g/Example.capx?dl=0

    This is a quick example capx i made, in this capx, i'm looking for the blue box to spawn in between the created blocks.

    I'd appriciate any help on this. Thanks.

  • (Added "destroy after leaving layout" so you don't have infinite block and item instances)

    Change "rndm < 1" to whatever value you like for the time in between the blocks

    I'd also exchange the "Bullet" behavior with something like "Every dt seconds" -> "Block: Set X: Self.X - 1".

    That will make the movement look a lot smoother.

  • Thanks, I'll give this a try.

  • randomly

    Thanks for the help, this is on the lines of what i'm looking for.

    One other thing, right now there is one object being created between the blocks, which is fine. If i wanted to create a few more objects in between the gaps, how do about about that?

    I've tried the following to do this but it didn't work.

    (Event) rndm>1

    (Sub Event) Every 0.5sec - create object

  • You didn't specify how you want your items to spawn.

    This is what you would do if you want to spawn multiple items spread vertically:

    yMin & yMax:

    The items will be evenly spread between those two Y-Coordinates.

    __________________________

    If you want to spread them evenly horizontally between two blocks:

    Remember though that it will look awkward if the space between the blocks are too small for the amount of items you want to fit in.

    So make sure to set the "rndm < 1" condition to a high enough value or decrease the SpawnCount or[/] decrease the item size if it does look awkward.

  • randomly

    Thanks for the reply, appriciate the help. The two pictures are the same, unless its just me, i can't see anything different between them.

    One more thing (Sorry!), my aim is to switch between horizontal scroll and vertical scroll. I assume that your method would be very similar to translate to adapt to vertical scrolling.

    For this, i did the same as you showed in your first post, but set Y as "Obstacle.Y-((Object*Obstacle.Bullet.Speed)/2)" instead of X. This works exactly as your example, which is great.

    I used the second part of your method by setting X as "yMin+((yMax-yMin)/(spawnCount+1)*(loopindex+1))" and again, it does work but the blocks are set horizontally.

    How do i set this veritcally? I know you showed how to do it in your second post, but thats with horizontall scroll.

    I can provide a capx for verticall scroll if needed, it's more or less the same as the one i've already provided.

    Sorry about the constant questions, and apologies about not being more specific.

  • [quote:j39svcgn]The two pictures are the same, unless its just me, i can't see anything different between them.

    Sorry about that, screwed something up there, obviously.

    Edited the post, images should be fixed now.

    ________________

    [quote:j39svcgn]How do i set this vertically?

    Please tell me first how you want your items to be spread.

    How are the blocks looking when scrolling vertically?

    Do you want to have the items spawning horizontally or vertically between the blocks?

    _______________________

    [quote:j39svcgn]Sorry about the constant questions

    This is what this forum is for. :)

  • randomly

    Basically, the game will switch between horizontal and vertical. Your example for horizontal scrolling has really helped, i can work off that to adjust how i want it.

    With vertical scroll, i want the blocks to spawn vertically.

    This is what i'm looking for, where the blocks are spread apart but have different X value. The X value would be random between the layout width.

    Thanks for your help so far

  • This should work.

    (Was too lazy to create a vertical scroll complete capx, so ignore the "set Bullet.AngleOfMotion". The "Create object" action though should work fine.)

  • Construct 3

    Buy Construct 3

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

    Buy Now Construct 3 users don't see these ads
  • randomly

    Thanks, that example is helpful.

    How do i set the X value of the blocks to be random? Right now, the blocks are set in a diagonal pattern. I'm looking for the blocks to be a random pattern.

    I've tried by setting the block X value at - "random(20,340)*(loopindex+1)"

    This does sort of work, i'm not sure if its the best way. Is there a better way of doing that?

    I've created a vertical scrolling capx with the example you've provided as well.

    https://www.dropbox.com/s/whzdsgoxcvtzyz1/V-Scroll.capx?dl=0

  • [quote:3jmmud05]I've tried by setting the block X value at - "random(20,340)*(loopindex+1)"

    This does sort of work, i'm not sure if its the best way. Is there a better way of doing that?

    Again, that depends on how you want it to look in the end.

    If you just want it to spawn at a random x position, you can simply set X to "random(0,WindowWidth)".

    If you want to spawn the object in the current pattern, but offset by a random amount, add a " + random(-25,25)".

    This will offset the X coordinate by something between -25 and 25.

  • The offset X coordinate seems to work a lot better, i can work with this.

    Thanks so much for your help, appriciate it.

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