Legacy GM [resolved]How to turn things visibility on and off? (codes)

A

Ann

Guest
You step on a block and an object becomes visible. You step of the block and the thing becomes invisible again. How? I have an idea down below here, but I don't know if I am on the right track. Am I thinking correctly?
Ps. Explain things to me as if I am 5 years old. I am new to GameMaker and still quite stupid.

Inside whatever object I want to be invisible/visible, what do I need?

Inside the object I want to be visible/ invisible:

- create a new variable inside the create event: visible=false

- A collision event with my block that sets it to visible=true when I touch it, and visible= false when I don't touch it? How do I do that? I don't know any codes for that.

- A step event where I say that if visible =true show objects or something. I don't know any codes for that. How?
 

TheouAegis

Member
visible is a built-in variable. You don't need to create it.

In your switch, you need save the id of the block you want to toggle. In the Begin Step event of the block, set its visible to false. In the collision event of the switch with the player, set the block's visible to true.
 

Zerb Games

Member
example:

For a toggle:
Instead of keyboard_check_pressed use a basic collision:
if keyboard_check_pressed(vk_space)
{
visible=visible
}

For a collision (like you said)
if place_meeting(x,y+1,obj_wall)
{
visible=false
}
else
{
visible=true
}

I'm confused as to what you are looking for, please reiterate.
 
A

Aura

Guest
You can easily use explicit scope if there's only one instance whose visibility is to be toggled or a with construction if there are multiple instances.

For instance, you can use the Collision event between the player object and the block to object to do this:

Code:
obj_Box.visible = true;
obj_Box.alarm[0] = 2;
...or this:

Code:
with (obj_Box) {
   visible = true;
   alarm[0] = 2;
}
In the Alarm event of obj_Box (or whatever the name is) you can set visible to false.

Code:
visible = false;
That would work as the alarm would keep getting reset to 2 as long as there's a collision and as soon as the collision ends, the alarm would stop getting reset and the instance(s) would go invisible again.

As for the second query:

Code:
if (visible) {
   //Do something
}
 
A

Ann

Guest
Thanks everyone for all of your good answers!
I managed to solve the problem. I wanted to make it so that you had to be standing on a certain block or floor to be able to see something.This is how I solved it:

1. I created an obj_control where I made a create event, where I made a new variable called global.my_switch=false

2. Made obj_secretfloor.

3. Inside my obj_player step event, on the bottom, I wrote this:

if place_meeting(x,y,obj_secretfloor)
{
global.my_switch=true
}
else
{
global.my_switch=false
}

3. Inside of whatever I wanted to controll the invisibility off : In my case, I had coins that I wanted to only show on the screen if you were stepping on the secret floor.
So I created obj_coins, and inside the obj coins, I created a draw event.
Inside the draw event I wrote this code:
draw_sprite_ext(sprite_index, image_index, x, y, image_xscale, image_yscale, image_angle, image_blend, global.my_switch);

And that's pretty much it! I think xD Hope I did'nt miss anything. Hope it helps!
 
Top