GameMaker Activate instances in a line

R

RobotoSkunk

Guest
How can I activate instances on a line? Because I've searched everywhere and I can not figure out how to do it ... I was thinking of using a "collision_line_list" but that gets bugged and the game does not start when implemented. (I used Google traslator, sorry).
 

YoSniper

Member
Try something like this:
Code:
with(object_name) {
    if collision_line(x1, y1, x2, y2, id, true, false) {
        instance_activate_object(id);
    }
}
The id attribute of the object tells the program to test each instance of object_name to see if it collides with the provided line on a case by case basis.
 
R

RobotoSkunk

Guest
Try something like this:
Code:
with(object_name) {
    if collision_line(x1, y1, x2, y2, id, true, false) {
        instance_activate_object(id);
    }
}
The id attribute of the object tells the program to test each instance of object_name to see if it collides with the provided line on a case by case basis.
I just tried it and it did not work
 

rIKmAN

Member
You need to give more information, saying "it did not work" and "it gets bugged" doesn't give anyone any useful information to try and help you.

Post your code (use code tags), explain what is happening and what you think should be happening.

The more information you give, the easier it will be for people to help you.
 
R

RobotoSkunk

Guest
You need to give more information, saying "it did not work" and "it gets bugged" doesn't give anyone any useful information to try and help you.

Post your code (use code tags), explain what is happening and what you think should be happening.

The more information you give, the easier it will be for people to help you.
Okay ... I put the code as it is written there and did nothing. I do not know how "With" works

Code:
instance_activate_object(obj_cannon);
        for(var a = 0; a < instance_number(obj_cannon); a++){
            inst[a] = instance_find(obj_cannon, a);
            with(inst[a]) {
                if collision_line(x1, y1, x2, y2, id, true, false) {
                    instance_activate_object(id);
                }
            }
        }
EDIT: the rest of the code:


Code:
if(start_opt){
    instance_deactivate_all(1);
    instance_activate_object(obj_player);
    instance_activate_object(obj_game_data);
    instance_activate_object(obj_display_controller);
    instance_activate_object(obj_touchpad);
    instance_activate_object(obj_laser_gun);
    instance_activate_object(obj_point_green);
    instance_activate_object(obj_sound_controller);
    #region Objetos
        #region Cañón
        instance_activate_object(obj_cannon);
        for(var a = 0; a < instance_number(obj_cannon); a++){
            inst[a] = instance_find(obj_cannon, a);
            xi1[a] = inst[a].x-100*inst[a].image_xscale;
            yi1[a] = inst[a].y-100*inst[a].image_yscale;
            xi2[a] = 200*inst[a].image_xscale;
            yi2[a] = 200*inst[a].image_yscale;
            instance_activate_region(xi1[a], yi1[a], xi2[a], yi2[a], 1);
        }
        #endregion
        #region Pistola
        instance_activate_object(obj_gun);
        for(var a = 0; a < instance_number(obj_gun); a++){
            inst[a] = instance_find(obj_gun, a);
            with(obj_block){
                if(collision_line(inst[a].x, inst[a].y, obj_player.x, obj_player.y, id, 1, 0)){
                    instance_activate_object(id);
                }
            }
        }
        #endregion
        #region Balas
        instance_activate_object(obj_bullet);
        for(var a = 0; a < instance_number(obj_bullet); a++){
            inst[a] = instance_find(obj_bullet, a);
            xi1[a] = inst[a].x-20*inst[a].image_xscale;
            yi1[a] = inst[a].y-20*inst[a].image_yscale;
            xi2[a] = 40*inst[a].image_xscale;
            yi2[a] = 40*inst[a].image_yscale;
            instance_activate_region(xi1[a], yi1[a], xi2[a], yi2[a], 1);
        }
        #endregion
    #endregion
    x1 = camera_get_view_x(view_camera[0])-20;
    y1 = camera_get_view_y(view_camera[0])-20;
    x2 = camera_get_view_width(view_camera[0])+20;
    y2 = camera_get_view_height(view_camera[0])+20;
    instance_activate_region(x1, y1, x2, y2, 1);
} else {
    instance_activate_all();
}
 
Last edited by a moderator:
Top