Create object between 2 created blocks.

Get help using Construct 2

Post » Fri Jan 13, 2017 4:43 pm

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.
B
5
S
2
Posts: 116
Reputation: 867

Post » Fri Jan 13, 2017 11:29 pm

Image
(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.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Mon Jan 16, 2017 2:13 pm

Thanks, I'll give this a try.
B
5
S
2
Posts: 116
Reputation: 867

Post » Tue Jan 17, 2017 4:24 pm

@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
B
5
S
2
Posts: 116
Reputation: 867

Post » Tue Jan 17, 2017 10:22 pm

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:
Image
yMin & yMax:
The items will be evenly spread between those two Y-Coordinates.

__________________________

If you want to spread them evenly horizontally between two blocks:
Image
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 [i]or[/] decrease the item size if it does look awkward.
Last edited by randomly on Wed Jan 18, 2017 10:45 pm, edited 1 time in total.
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Wed Jan 18, 2017 3:37 pm

@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.
B
5
S
2
Posts: 116
Reputation: 867

Post » Wed Jan 18, 2017 10:49 pm

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.

________________

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?

_______________________

Sorry about the constant questions

This is what this forum is for. :)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Thu Jan 19, 2017 5:37 pm

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

Image

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 :)
B
5
S
2
Posts: 116
Reputation: 867

Post » Thu Jan 19, 2017 7:28 pm

Image

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.)
"We can't solve problems by using the same kind of thinking we used when we created them."
- Albert Einstein
B
27
S
11
G
8
Posts: 528
Reputation: 7,091

Post » Sat Jan 21, 2017 4:37 pm

@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
B
5
S
2
Posts: 116
Reputation: 867

Next

Return to How do I....?

Who is online

Users browsing this forum: No registered users and 7 guests