GML Parent object drawing

P

PatatjeFriet

Guest
Hello,

So i am making a game were i want to have states something like hearts of iron 4 and europa universalis 4. So i drew 2 different objects with different sprites and made a parrent object for them. What they are supposed to do is glow (i just made the image a bit yellower) when i press them. In the parent object i put a draw event to draw the 2 objects, but now when i put them in the room the draw event works only for 1. They are both in the room and you can see them, but only 1 when i click them glows. And the weird thing is if i delete 1 in the room and then place it again and i start the game it will only work for that one. So for example i put obj 1 first in the room and then obj 2. Obj 2 will glow when i press but obj 1 not. Now when i put obj2 first and then obj 1 obj 1 is going to glow. Can someone explain to me why it is not working?

Code:
Code:
Create event:

pro1 = 0;
pro2 = 0;

Left pressed event:

//province 1
if position_meeting(mouse_x,mouse_y,obj_1) {
    if pro1 = 0 {
        pro1 = 1;
        pro2 = 0;
    }
    else {
        pro1 = 0;
    }
}
//provincie 2
if position_meeting(mouse_x,mouse_y,obj_2) {
    if pro2 = 0 {
        pro2 = 1;
        pro1 = 0;
    }
    else {
        pro2 = 0;
    }
}

Draw event:

//provincie 1
//standart
with (obj_1) {
    draw_sprite(spr_1,0,self.x,self.y);
}
//selected
if pro1 = 1 {
    with(obj_1) {
        draw_sprite(spr_1,1,self.x,self.y);
    }
}
else if pro1 = 0 {
    with(obj_1) {
        draw_sprite(spr_1,0,self.x,self.y);
    }
}
//provincie 2
//standart
with (obj_2) {
    draw_sprite(spr_2,0,self.x,self.y);
}
//selected
if pro2 = 1 {
    with(obj_2) {
        draw_sprite(spr_2,1,self.x,self.y);
    }
}
else if pro2 = 0 {
    with(obj_2) {
        draw_sprite(spr_2,0,self.x,self.y);
    }
}
Regards,
Patatjefriet
 
Last edited by a moderator:
I think you overcomplicated things.
Basically, you just need a parent object with the following events:

CREATE EVENT:
selected = false
image_speed = 0;
image_index = selected;


STEP EVENT
if (point_in_rectangle(mouse_x, mouse_y, bbox_left, bbox_top, bbox_right, bbox_bottom) && mouse_check_button_pressed(mb_left)) {
// First, deselect all the objects
with (parObject) {
selected = false;
}
// Select the object below the cursor
selected = !selected;
}


// DRAW EVENT
draw_sprite(sprite_index, selected, x, y);


Then you just need to create an object for each state and put the previous object as its parent.
NOTE: Each state sprite must have two images: one for the deselected frame (index 0) and one for the selected one(index 1);

I didn't test it, but it should work fine.
Let me know if it does work.
 
P

PatatjeFriet

Guest
Hello,

Thanks for responding, but I am making it in gamemaker 8.1 and it seems the point in rectangle doesnt work in that. Also i am still learning gamemaker and am just looking in to parent objects so I thought what i did would work, but i dont totaly understand what you did.

regards,
Patatjefriet
 
Last edited by a moderator:
Top