I Wanna Community
Fangames => Game Design => Programming Questions => Topic started by: Derpyhoovesiwbtg on August 13, 2013, 12:22:33 PM
-
I have no idea how to use them, i cant find a tutorial anywhere.
-
Well what engine are you using?
-
Oops, i've meant actually how to use buttons. F-my self. But still, how you use buttons?
-
You're gonna have to be more specific than that. What buttons? and what are you trying to do?
-
Hittable buttons you can hit with your gun.
-
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:
-
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?
-
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.
-
Thanks Sephalos, everything worked. Please lock this thread :)
-
Locked