How to Spawn/move Rooms that include multiple objects (like in Rider or Subway Surfers)?

0 favourites
  • 5 posts
From the Asset Store
Add calm and a lounge vibe to your games with these 8 tracks
  • Hey,

    I want to make an endless runner (think of Subway Surfers) where pre-defined rooms spawn ahead of the player (these can be either created or moved to the position).

    These rooms should consist of multiple objects, like spikes or bombs.

    Now: I want to move those rooms, but the issue is that I can't just pin the objects to the rooms because there are also instances of such objects in the other rooms.

    This is why families wouldn't work either, because they select every instance.

    If I want to move an entire room to a different position, there would need to be something like a "prefab" so I can create or move a room with all the instances at the correct position.

    An Idea was to create a family in which all objects are and then say: if family overlaps with room_background (invisible sprite) = pin to object. However, this did not work well.

  • Check out this demo:

    howtoconstructdemos.com/generate-random-levels-from-pre-built-scenes

    There is a free version and a video tutorial.

    The full version of this demo has an example of an endless runner where rooms/scenes are moved ahead of the player.

    There is also a new feature in C3 which was only added a couple weeks ago - templates. You can create rooms on a separate (unused) layout, connect all objects to the room with hierarchy, and give a template name to each room. Then you'll be able to spawn rooms by their names, with all objects in them.

  • Okay so this seems helpful (thanks a lot!) but it is a very lengthy tutorial so I figured for everyone who's curious here is the short form:

    CurX here is the right boarder (BBox.right) of the last placed scene. CurY here is the Y position of the last placed scene, in this example it always stays the same but if you want to add verticality to the game you might want to change this.

    For adding a room (in this case called "scene") above the current room, you need to take BBox.top for the Y position (curY) and if wou want to add a room below the current one you need to use BBox.bottom + NewScene.height instead.(this wasn't mentioned in the video but I believe this should work)

    Now, you got a family with all the scene objects (so basically every object in your game's world), in this case it is called "Entities".

    Now with this funky formula you set the position for each entity to the position where the new scene is going to be but add the own position of the object relative to the scene position (so self.x & self.y) as an offset.

    For this formula it is essential (wasn't mentioned in the video though) that the origins of the background scene objects are in the lower left-hand corner.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • dop2000

    You can create rooms on a seperate (unused) layout, connect all objects to the room with hierachy [...]

    Does this mean I can just connect them with hierachy in the layout view?

    Because I got like a hundred objects and I dont want to make an action "if object1 overlaps room1 -> room1 add child" for every object.

    Or would "if room1 overlaps "FamilyWithALlObjects" -> room 1 add child "FamilyWithAllObjects" work? Or would it just pick all family members in the whole scene?

    thanks for your help!

  • Does this mean I can just connect them with hierachy in the layout view?

    Yes, in layout editor - you select one room/scene with all its objects, then right click on the room and add all objects as children.

    You can create hierarchies with code, but only if all objects exist on the current layout. Templates allow to spawn complex objects pre-built on other layouts.

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