• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Create object everywhere on a grid?

K

KDG

Guest
For example: a 10x10 grid (32px x 32px sprites), how do you create the object 100 times, 1 time for each square of the grid.
 

origamihero

Member
Sounds like something a while loop or the 'for' command is perfect for.

Code:
var xx=0; var yy=0;

while (xx<10) {

  while (yy<10) {
  instance_create(xx*32,yy*32,object);
  yy++;
  }

xx++;
}
 
Last edited:

3dgeminis

Member
Someting like this :
Code:
for(i=0;i<10;i+=1)
    {
        for(j=0;j<10;j+=1)
            {
             instance_create(x+32*i , y+32*j , obj)
            }
    }
 

Fredrik

Member
In your room, place the wanted object in the very upper left corner of your room.
Let's say that the sprite is 32x32.

In the Create_Event of obj_block:
var obj_block;
if instance_count < 100
{
instance_create(x+32,y,var);
instance_create(x,y+32,var);
instance_create(x+32,y+32,var);
}

In the Step Event of obj_block:
if place_meeting(x,y,obj_block) {instance_destroy();}

I think this will work, I didn't try it out before I wrote it just now, but I've tried it before.
 
Top