Level Editor with Grid

This forum is currently in read-only mode.
From the Asset Store
Snap to visible grid - perfect solution for any game genre
  • Hello! Another Help Thread by me for you!

    <img src="http://i44.tinypic.com/2irqjrk.png">

    I planned to make a level editor. It has a grid with 32x32 big blocks. I wanted to make this with an array.

    When the player pastes a Wall at "x 1 y 1", it should get a value of "1". Then, when the player puts the player start point at "x 2 y 2", it should get a value of "2".

    Now, is it possible, that there is an event, that just says, every coordinate with value 1, creates a wall object and every coordinate with value 2, creates a player object?

    Or is it only possible by doing 200 events for every point that looks if the value is this, then do that?

  • Start of layout

    for each in array

    -value at current x,y is equal to 1

    -->system create object wall at current x,y * 32

    -value at current x,y is equal to 2

    -->system create object player at current x,y * 32

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thank you, this works like a charm!

    [Edit]Grr, somehow, I can't make the array save the value to the place of the wall. I tried to do with x to 640 and y to 480. But this can make the file to 4MB big.

    I want to use for example:

    Wall is at x=32 and y=416

    Array should save this as x=1 y=1

    I could do this with events for every place in the grid, but than I would have 234 Events.

    Any ways to make this smaller.

  • Maybe I didn't clearly explain my problem.

    I tried the solution by newt and it works perfectly fine. However, the array technique I wanted to use was for Levels to download. I planned to allow people to upload their own levels.

    Now, the thing is, I first made the array size like this:

    x - 640

    y - 480

    z - 1

    The problem is, the file get's extremly big. It's 4MB big!

    So I thought to make this like the picture in the first post. Using only this:

    x - 18

    y - 12

    z - 1

    This makes the file tiny and more acceptable to download the file. The thing is, the only way I know is, to make event to test what place the object is:

    Wall is in position x=32, y=419

    -> Add value 1 at Array (x=1, y=1)

    To do this, I would have to make a lot of events. That's why I want to ask, is there any other way to make as less events as possible, not to cluter the event sheet?

  • First you have to decide wether your levels should be pixel-based or grid-based. Either way you don't have to set up an array of huge sizes.

    1) Pixel-based

    Easiest way is to use S. (http://www.scirra.com/forum/viewtopic.php?f=2&t=4791&hilit=lucid+s&start=47) If you don't want to use S, you can do the following:

    Let the user place the objects. When it comes to saving, you count the objects on a global scope and so creating an id (object A 20x = 0-19, object B 12x = 20-31, etc) and then "misuse" a hash table. For every object you create 3 keys named

    -"whateveryoulike" & str(globalcounter) (content would be the id for the object type, like wall or player start point)

    -"whateveryoulike" & str(globalcounter) & "x" (content would be the horizontal position)

    -"whateveryoulike" & str(globalcounter) & "y" (content would be the vertical position)

    When loading, you use HashTable.KeyCount / 3 to get the number of objects. Then in a for loop you access the values via "whateveryoulike" & str(LoopIndex) and create the objects according to their type and position.

    2) Grid-based

    This version has fixed positions on the layout, depending on the cell size the grid represents. So you have to make sure, the objects are correctly placed at the fixed positions. The rest is easy. When the user wants to save, loop through your grid size to see what object is at that position and add the value to the array. Assuming the grid is 16x16, representing cell sizes of 32x32, and the objects hotspot is upper left, this would be:

    +For loopx from 1 to 16

    For loopy from 1 to 16

    ++objectwall.x equal to (LoopIndex("loopx") - 1) * 32

    objectwall.y equal to (LoopIndex("loopy") - 1) * 32

    -Array: Set index (LoopIndex("loopx"), LoopIndex("loopy")) to 'yourobjectidforwall'

    ++objectplayer.x equal to (LoopIndex("loopx") - 1) * 32

    objectplayer.y equal to (LoopIndex("loopy") - 1) * 32

    -Array: Set index (LoopIndex("loopx"), LoopIndex("loopy")) to 'yourobjectidforplayer'

    ++etc for all your object types

    When loading you do as newt wrote.

    If your objects hotspots are not upper left just add the distance from upper left to the hotspots position like this:

    objectwall.x equal to (LoopIndex("loopx") - 1) * 32 + 'distanceX' (for example 16, if hotspot is centered)

  • Thank you for the solution. I will use S. Just have to read the tutorials, so I can understand this.

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