Fangames > Programming Questions

How do you actually use buttons?

<< < (2/2)

Sephalos:
Well alright, let's start with something basic then.

Make a object called 'oButton'
The sprite should have 2 frames, on and off.

--------------------
Create Event:
image_speed = 0;
io = 0;
--------------------
Collision with Bullet event:
if io = 0 { image_index = 1; io = 1; }
else if io = 1 { image_index = 0; io = 0; }
with(other){ instance_destroy(); }
--------------------

There you have it, one shootable button.  :TriHard:

Derpyhoovesiwbtg:
It works but, when i hit it multiple times, it fades from blue to red, blue to red, and so on.

But how i actually use it with stuff like spikes?

Sephalos:
Alright, I'm going to assume you want spikes to come up and down when you press the button.
You're going to need a couple objects for this.

oButtonSpikeUp1
--------------------
Create Event:
image_speed = 0;
io = 0;
ys = y;
--------------------
Step Event:
if io = 0 { if y > ys { y -= 2; } }
if io = 1 { if y < ys+32 { y += 2; } }
--------------------

oButtonSpikeDown1
--------------------
Create Event:
image_speed = 0;
io = 0;
ys = y;
--------------------
Step Event:
if io = 0 { if y < ys { y += 2; } }
if io = 1 { if y > ys-32 { y -= 2; } }
--------------------

oButtonSpikeUp2
--------------------
Create Event:
image_speed = 0;
io = 0;
ys = y;
--------------------
Step Event:
if io = 0 { if y < ys { y += 2; } }
if io = 1 { if y > ys-32 { y -= 2; } }
--------------------

oButtonSpikeDown2
--------------------
Create Event:
image_speed = 0;
io = 0;
ys = y;
--------------------
Step Event:
if io = 0 { if y > ys { y -= 2; } }
if io = 1 { if y < ys+32 { y += 2; } }
--------------------

oButton
--------------------
Create Event:
image_speed = 0;
io = 0;
--------------------
Collision with Bullet event:
if io = 0 {
image_index = 1;
io = 1;
with(oButtonSpikeUp1){ io = 1; }
with(oButtonSpikeDown1){ io = 1; }
with(oButtonSpikeUp2){ io = 1; }
with(oButtonSpikeDown2){ io = 1; }
} else if io = 1 {
 image_index = 0;
 io = 0;
with(oButtonSpikeUp1){ io = 0; }
with(oButtonSpikeDown1){ io = 0; }
with(oButtonSpikeUp2){ io = 0; }
with(oButtonSpikeDown2){ io = 0; }
}
with(other){ instance_destroy(); }
--------------------


Hope this helps, let me know if something goes horribly wrong.

Derpyhoovesiwbtg:
Thanks Sephalos, everything worked. Please lock this thread :)

Denferok:
Locked

Navigation

[0] Message Index

[*] Previous page

Go to full version