GMS 2 Collision objects limitations?

Discussion in 'Programming' started by Sean Catherine, Jul 11, 2019.

  1. Sean Catherine

    Sean Catherine Member

    Joined:
    Nov 10, 2017
    Posts:
    186
    Is a collision object able to process multiple collisions at once? If so, how many?
    thx
     
  2. Phil Strahl

    Phil Strahl Member

    Joined:
    Jul 3, 2016
    Posts:
    387
    In GameMaker Studio 2 you can use the instance_place_list() function that returns a ds_list of the ids all the colliding instances, not just a single id. Here's the entry in the manual.
     
    RefresherTowel likes this.
  3. RefresherTowel

    RefresherTowel Member

    Joined:
    Jul 13, 2016
    Posts:
    1,212
    If it's not in GMS2, there is a manual solution to the problem:
    Code:
    var list = ds_list_create(); // Create a temporary list for the instances at the location
    var inst = instance_place(x,y,object); // Get the first instance in the location
    while (inst != noone) { // As long as there is an instance at this location, perform the loop code
       ds_list_add(list,inst); // Add the instance to the list
       inst.x += 1000; // Move the instance
       inst = instance_place(x,y,object); // Check if there is another instance at the original location
    }
    var list_size = ds_list_size(list); // Get the how many instances where found (which is equivalent to the list size)
    for (var i=0;i<list_size;i++) {
       with (list[| i]) { // Using the ID's that we previously stored in the list
          x -= 1000;  // We move them all back to where they were
          // Do any manipulation/checks you want to happen to specific instances here
       }
    }
    ds_list_destroy(list); // After that, make sure to destroy your list so you don't have a memory leak
    
     
    marasovec and Phil Strahl like this.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice