Game Development Community

Simple Push Button: Class or behavior?

by Paul Bruner · in iTorque 2D · 11/30/2011 (3:02 pm) · 3 replies

Ok, I solved this by using all scripting. Basically I used a movemap and a class that controls the entire screen, create the buttons in script, then watch for touches. The question is how do you do this in a simple behavior.

I have two pictures. One normal unpressed button, and one button where the image looks pressed. Once the user touches the button it goes to the pressed sprite and if he lets go it will change level. If he drags his finger outside the button bounds, the button becomes unpressed and when the user releases his finger the button does nothing.

Doing this with all global onTouchDown, Up, Drag works fine. But it feels like there is an easier way to do it using a more portable behavior, but I am not to sure how to go about it. I am just starting and its very hard for me to not script the whole thing and not touch the gui:P

#1
12/06/2011 (2:08 pm)
Ugh. Of course you would have a nifty GUI object that does this
GuiBitmapButtonCtrl()

In case anyone else is looking for a good, simple tutorial go
http://tdn.garagegames.com/wiki/TGB/MiniTuturials/GUIMainMenuBitmap

One caveat though. In the bitmap field change
bitmap = "gui/images/START.png";
to
bitmap = "gui/images/START";

Otherwise in iTorque, it looks for START.png_n, START.png_d, etc and the image loader gets confused without a proper extension.
#2
10/13/2012 (6:29 pm)
I've added a link on the wiki to an iTorque compatible version for everyone.

tdn.garagegames.com/wiki/TGB/MiniTuturials/GUIMainMenuBitmap
#3
10/13/2012 (10:24 pm)
There's also button behavior scripts in the Featuredemo, although you probably will want to modify them by adding a onMouseLeave function that calls onTouchUp, if you want to go that route.