How do I create an object in an empty space?

0 favourites
  • 4 posts
From the Asset Store
Fully commented source code/event sheet & sprites to create a space shooter game
  • 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 - 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!

  • Perhaps a stupid question, but why are the balls solid?

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

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • 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 ) and sorry if it sounds like a stupid solution, but I'm a beginner myself

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