GameMaker How to completely hide the object?

U

User

Guest
In most development environments (and languages), hiding an object means that the most events can not be executed. In RAD Studio (delphi/c++) or Visual Studio (C#) events like OnClick or OnMouseEnter can not be executed when object is invisible (property visible=false). This is logical.

But in GMS2 i do
Code:
my_object.visible=0;
and i can not see my object.
But if i move mouse on this invisible object i hear sound. Sound plays when Mouse Enter events executed.
This is strange.
Why this happens?
How to completely hide the object?
 
S

Silver_Mantis

Guest
Just use exit;
Read about it here.

An Example would be something like:

Code:
if (my_object.visible == 1)
{
    //Run your code for the object
}
else
{
    exit;
}
 

Bingdom

Googledom
When setting visible to false, you're just telling the instance to stop using the draw event

The Manual said:
An instance can be flagged as visible or not by setting this variable to true (visible) or false (invisible). This works by telling GameMaker: Studio to skip the draw event for this instance, so care must be taken when using this as it means that no code placed in the draw event will be run while the instance is not visible.
 
U

User

Guest
It strange...

When i use instance_deactivate_object(my_obj) i can not fix last object state.

For example - i have an animated image (menu).
My object consists of 11 pictures (animated object).

My code

MouseEnter
Code:
mouse_state="enter";
image_index=0;
image_speed=1;
Step
Code:
if mouse_state=="enter"
{
if (image_index>4) image_speed=0;
}
So we do mouse over and now see image 5.


Tap
Code:
image_speed=0;
image_index=0;
instance_deactivate_object(my_obj);
We clicked.
We can not see our object. No sound etc - great.

And when i
Code:
instance_activate_object(my_obj);
I see my object. But i see image 5 and after second image 0.

But i write in Tap image_speed=0; image_index=0;. I say gms2 stop animation, show image 0 then instance_deactivate_object.
Why I see image 5 and after second (blink) image 0?
 
H

Homunculus

Guest
Can't really say why, but have you tried adding image_index=0; right after instance_activate ?
 
U

User

Guest
Can't really say why, but have you tried adding image_index=0; right after instance_activate ?
Yes. Same rusult.

Before instance_deactivate_object i do

Tap
Code:
//Now we see image 5
image_speed=0; //Let stop any animation
image_index=0; //Let see image 0
//deactivate_object(my_obj);
After instance_activate_object i do
Code:
//activate_object(my_obj);
image_speed=0;
image_index=0;
So i do it twice. Even twice it dont work.
And i see image 5 then blink and image 0.
Why I see image 5?
 
H

Homunculus

Guest
Well first of all, where exactly are you calling instance_activate_object ? Doing something like

Code:
instance_activate_object(my_obj);
image_speed=0;
image_index=0;
will not work, since you are setting image_speed and image_index to the instance calling the activation, not to my_obj... Use with() to set those variables correctly
 
U

User

Guest
Well first of all, where exactly are you calling instance_activate_object ?
If we clicked on my_test_object we will hide them. If we clicked on my_test_button we will show my_test_object.

Object my_test_object
Tap
Code:
image_speed=0; //stop any object animation
image_index=0; //set image index = 0
hide_my_test_object(); //laught script
Script hide_my_test_object
Code:
instance_deactivate_object(my_test_object);
Object my_test_button
Tap
Code:
show_my_test_object(); //laught script
Script show_my_test_object
Code:
instance_activate_object(my_test_object);
Result
We move mouse on my_test_object. Animation start. When my_test_object.image_index=5 animation stop. So we see image 5.
We clicked on my_test_object. Animation must be stopped. And image index must be 0. But we can not see it now because next will be laught script, where we run instance_deactivate_object function. All works fine, my_test_object is hidden now.
Let click on my_test_button. We do it and see my_test_object.image_index=5. We see fifth image! And split second later image 0.
But we set image_index=0 and image_index=0 before deactivate_object...
 
H

Homunculus

Guest
As said, I don't know why this happens, but you should try to set image_speed = 0 and image_index = 0 AFTER
instance_activate_object(my_test_object); and see if it solves the problem.

Code:
instance_activate_object(my_test_object);
with(my_test_object) {
    image_speed = 0;
    image_index = 0;
}
On a side note, instance_activate_object(my_test_object); deactivates ALL instances of my_test_object. Is this really the behaviour you want?
 
Top