Joe
Member
I came up with a simple way to make to make spawn points for a project. All spawn points are placed by hand in the room editor via object. There is a controller object that assigns all the x,y coordinates into an a array on room start then destroys the spawn point objects, like so below
The event for the object being spawned is like so, which will eventually give an error for the last entry not being defined.
I'm a little confused as to why using array_length seems to not work in this instance, I've been trying to avoid using maths like "-1" since it doesn't seem like the "correct" thing to do (although it might be). Any help would be greatly appreciated as always.
Code:
var count = instance_number(spawn_point);
for (var i = 0; i < count; ++i)
{
spawn = instance_find(spawn_point,i);
global.spawn_grid[i,0] = spawn.x;
global.spawn_grid[i,1] = spawn.y;
}
instance_destroy(spawn_point);
GML:
var grid_spot = irandom(array_length(global.spawn_grid))
instance_create_layer(global.spawn_grid[grid_spot,0],global.spawn_grid[grid_spot,1],"player_layer",player_id);