Page 1 of 1

How to make a button that can be clicked?

Posted: Sun Mar 02, 2014 12:01 pm
by Imerion
I have another small problem. I'd like to create clickable buttons, so my game could be playable on touchscreens. I created a cursor; a simple model which draws a sprite and updates the following code :

Code: Select all

CurrentModel.Position.X = SmallballHD.MousePosition.X*8;
CurrentModel.Position.Y = SmallballHD.MousePosition.Y*4.5;
The button is a similar model with a sprite, with a KeyPress action set to register at MouseLeft ( { ). If mouseleft is pressed, this code is executed :

Code: Select all

if (CurrentModel.CollidedWith.Category==11); {
  GameMode=0;
  @SetAppState(State : InGame);
  @RemoveModel();
}
For some reason, this crashes the entire game. How would I do a clickable button?

Posted: Sun Mar 02, 2014 9:30 pm
by Kjell
Hi Imerion,

Not sure what is causing your problem, but attached is a ( simple ) example containing 24 "buttons" :wink: Keep in mind that on Android you probably want to use the touch functions instead.

K

Posted: Mon Mar 03, 2014 8:26 am
by VilleK
If you get crashes, try running your game in the preview window and watch the log window for any warning messages. The runtime engine is minimized and does not have any error checking but the preview window does.

Posted: Tue Mar 04, 2014 11:28 am
by Imerion
Thanks to both of you! I managed to figure it out and buttons work great now!

Posted: Tue Mar 04, 2014 6:06 pm
by jchp7787
the example of the piano also served me to my ejejejje 8)

Posted: Sun Mar 09, 2014 1:16 am
by jonaspm
It helped me too :D

Posted: Sat Mar 29, 2014 5:16 am
by jonaspm
Hey Ville, i think that currently it is hard to build a button-based menu... or HUD

Do you think that a friendly component could be added to ZGE?

Thanks in advance! :D