I Wanna Community

Fangames => Game Design => Programming Questions => Topic started by: Derpyhoovesiwbtg on August 13, 2013, 12:22:33 PM

Title: How do you actually use buttons?
Post by: Derpyhoovesiwbtg on August 13, 2013, 12:22:33 PM
I have no idea how to use them, i cant find a tutorial anywhere.
Title: Re: How do you actually use triggers?
Post by: Sephalos on August 13, 2013, 02:25:21 PM
Well what engine are you using?
Title: Re: How do you actually use buttons?
Post by: Derpyhoovesiwbtg on August 13, 2013, 03:05:22 PM
Oops, i've meant actually how to use buttons. F-my self. But still, how you use buttons?
Title: Re: How do you actually use buttons?
Post by: Sephalos on August 13, 2013, 03:20:35 PM
You're gonna have to be more specific than that. What buttons? and what are you trying to do?
Title: Re: How do you actually use buttons?
Post by: Derpyhoovesiwbtg on August 13, 2013, 04:27:41 PM
Hittable buttons you can hit with your gun.
Title: Re: How do you actually use buttons?
Post by: Sephalos on August 13, 2013, 05:12:51 PM
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:
Title: Re: How do you actually use buttons?
Post by: Derpyhoovesiwbtg on August 14, 2013, 04:01:05 AM
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?
Title: Re: How do you actually use buttons?
Post by: Sephalos on August 14, 2013, 02:39:37 PM
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.
Title: Re: How do you actually use buttons?
Post by: Derpyhoovesiwbtg on August 15, 2013, 04:39:08 AM
Thanks Sephalos, everything worked. Please lock this thread :)
Title: Re: How do you actually use buttons?
Post by: Denferok on August 15, 2013, 06:48:52 AM
Locked