Jump to content


Cycle through all objects in a collision area

  • Please log in to reply
1 reply to this topic

#1 zbox


    GMC Member

  • GMC Member
  • 2618 posts
  • Version:Unknown

Posted 11 December 2012 - 03:49 AM

Hello all,
I'm not sure if this has been posted here before; but the other day I needed a script to easily cycle through all the objects that existed in a collision_rectangle area. I couldn't find one so I made one for myself and for you guys to have a look at :)

So without further ado, here's the link. It contains a gm81 example of how to use it. Everyone loves screenshots so here is one as well :D
Linky: https://www.box.com/...kd9lsrm9fbhnlwh
Posted Image

How do I use this lovely script?
I'm glad you asked, to use this script, (there is one script for each collision function i.e. circle,rectangle,line), simply choose the one you need, they use the same arguments as the original function, and to iterate through each object place it in a while loop. When the script is done with all the objects in the specified area, it will return false and stop the loop. The object's id is stored in a variable called global._id. Put more simply:
while (all_collision_rectangle(mouse_x-30,mouse_y-30,mouse_x+30,mouse_y+30,all,true,true)){
    global._id.image_blend = c_red; //for example.
If I didn't explain it too well there, check out the editable example. I've done indenting and stuffs like a real programmer so hopefully its pretty readable :P.
  • 4

#2 ze1


    GMC Member

  • GMC Member
  • 153 posts
  • Version:GM:Studio

Posted 09 May 2013 - 11:57 PM

Sorry for necroposting, but I figured the guy deserves appreciation, so... Nice script! This will be pretty useful! =)

  • 4