How to make a button that can be clicked?

All topics about ZGameEditor goes here.

Moderator: Moderators

Post Reply
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

How to make a button that can be clicked?

Post 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?
User avatar
Kjell
Posts: 1881
Joined: Sat Feb 23, 2008 11:15 pm

Post 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
Attachments
Piano.zgeproj
(4.11 KiB) Downloaded 442 times
User avatar
VilleK
Site Admin
Posts: 2277
Joined: Mon Jan 15, 2007 4:50 pm
Location: Stockholm, Sweden
Contact:

Post 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.
Imerion
Posts: 200
Joined: Sun Feb 09, 2014 4:42 pm

Post by Imerion »

Thanks to both of you! I managed to figure it out and buttons work great now!
User avatar
jchp7787
Posts: 13
Joined: Tue Feb 11, 2014 3:08 am
Location: Cuba

Post by jchp7787 »

the example of the piano also served me to my ejejejje 8)
User avatar
jonaspm
Posts: 89
Joined: Fri Jul 06, 2012 3:51 pm
Contact:

Post by jonaspm »

It helped me too :D
User avatar
jonaspm
Posts: 89
Joined: Fri Jul 06, 2012 3:51 pm
Contact:

Post 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
Post Reply