How do I create an object in an empty space?

Get help using Construct 2

Post » Tue Oct 13, 2015 9:09 am

Message: CJacobsSA can only post plain text URLS until they have 500 rep. 1 URLS modified. Why?
I'm making a breakout clone as my first real project and I've run into an issue with creating a multi-ball power-up. The multi-ball works properly and creates new balls, but because of the way Construct handles solids, the new ball that spawns is stuck in place and does not move. This is because the new ball spawns inside the old one; it has its angle/speed set when it's spawned, but Construct intentionally freezes solids that spawn on top of each other in place, so that code doesn't work (see the solid behavior in the manual - https://www.scirra.com/manual/104/solid intentionally).

I want to solve this by having the code spawn the new ball in a random, guaranteed-empty spot near the old ball instead. However, I have no idea how to go about doing this, so I would appreciate some help!
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Oct 13, 2015 9:54 am

Perhaps a stupid question, but why are the balls solid?
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Tue Oct 13, 2015 10:02 am

Don't worry, that's not a stupid question as I hadn't really given that much thought myself. Thinking about it, I marked them as solid so that I wouldn't have to define collisions for each type of brick manually; with the ball object marked as solid they bounce off of each other and all of the bricks (the different kinds of bricks are marked as solid as well) without requiring any extra code from me.

If doing that is the best way to solve my issue though, I'll do that instead.
B
18
S
9
Posts: 103
Reputation: 1,817

Post » Tue Oct 13, 2015 10:48 am

Maybe you can divide the game space by creating a virtual grid.
Let's say that the space the balls can bounce is 400X400 pixels and let's assume we want a 4x4 grid. That means a cell size of 100X100 pixels.
Create an invisible sprite with those dimensions and place it in the top-left cell in the beginning of the game.
When its time to spawn a new ball check if the dummy sprite is overlapping any object.
If yes, move it to the next cell and re-check. If not, spawn your ball in the empty cell.

I don't know how efficient that might be (or if it is working at all :D ) and sorry if it sounds like a stupid solution, but I'm a beginner myself
B
13
S
5
G
1
Posts: 116
Reputation: 1,805


Return to How do I....?

Who is online

Users browsing this forum: Laurent and 11 guests