GM:S 1.4 Drawing many instances at a time.

Discussion in 'Programming' started by Thexel PIN, May 29, 2017.

  1. Thexel PIN

    Thexel PIN Member

    Joined:
    Feb 10, 2017
    Posts:
    97
    So this is my code:
    Code:
    if instance_exists(obj_enemybullet) {
    if obj_enemybullet.sprite_index != -1 {
    draw_sprite_ext(obj_enemybullet.sprite_index,obj_enemybullet.image_index,obj_enemybullet.x,obj_enemybullet.y+altitude,obj_enemybullet.image_xscale,obj_enemybullet.image_yscale,obj_enemybullet.image_angle,c_black,obj_enemybullet.image_alpha*0.5);
    }}
    You can see I'm drawing "obj_enemybullet". It works fine, but there are many instances of it and I need it to draw them all. How can I do that?
     
  2. rIKmAN

    rIKmAN Member

    Joined:
    Sep 6, 2016
    Posts:
    4,885
    You can use with to iterate through all instances of an object.
     
  3. Thexel PIN

    Thexel PIN Member

    Joined:
    Feb 10, 2017
    Posts:
    97
    And here's the thing:
    1. Can you draw through a with?
    2. If I do that, the objects will draw themselves in the same depth. I need a different object with bigger depth to draw them.
     
  4. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,343
    with obj_enemybullet {
    y += other.altitude;
    image_alpha /= 2;
    draw_self();
    y -= other.altitude;
    image_alpha *= 2;
    }
     
  5. FrostyCat

    FrostyCat Member

    Joined:
    Jun 26, 2016
    Posts:
    4,793
    1. with is just a looping construct. If it is put in a place where drawing functions make sense (i.e. a Drawing event), then you can draw with it.
    2. with does not change the drawing depth to that of the instances being accessed, quit believing that myth. Put the with in the object with the higher depth and it will draw at that higher depth.
     

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