• 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!
  • Hello [name]! Thanks for joining the GMC. Before making any posts in the Tech Support forum, can we suggest you read the forum rules? These are simple guidelines that we ask you to follow so that you can get the best help possible for your issue.

Help needed: removing tiles and objects at certain place

D

Dwojityv

Guest
Hello,
I am creating an endless runner game and everything works just fine.
I am moving tiles and objects instead of player (dont ask me why, I just couldnt figure out other way to do It ^^). And thats where I am starting to feel uncomfortable, because I dont remove objects and tiles that leave my roomview.

Okay I know how to remove objects with adding some line of code to the step event what checks if the Object.x < 0 and if It is, remove It. But I would have to manually add this to every object and I believe there must be better way to do It.

About tiles - I have no idea How to remove tiles that are in certain position.

TL;DR:
I need efficient way to destroy all objects and tiles with x position smaller than -150.

Thanks in advance for your replies and sorry for my english, its my third language ^^
 

BlueBurn

Member
Well, what about this ?
Code:
// Delete tiles
var _id, _ids = tile_get_ids();
for (var i=0; i<array_length_1d(_ids); i+=1)
{
    _id = _ids[i];
    if (tile_get_x(_id) < -150) tile_delete(_id);
}

// Delete objects
with(all)
{
    if (x < -150) instance_destroy();
}
Just use it in some object that is in the room only once and to make it more efficient you should should put it in alarm.
 
D

Dwojityv

Guest
Wow thats exactly what I needed. I did not know that I can use with(all) and tile_get_ids();

Thank you very much for your quick answer. :)
 
Top