How do I use sprites as buttons?

Get help using Construct 2

Post » Fri Jul 15, 2016 2:11 pm

Hey Guys - Today i was challenging the GUI for my game. Usually i use Buttons to do that, but i would need to include sprites. I recognized, that it isnt that easy to use sprites as buttons, with the same characteristics of a construct2 button.

Is there a simple way to do this? In my game you can tap on the whole screen, this will affect into some camera zooming. With the Construct2 buttons this was no problem, because the tap gesticure wouldnt be calculated as it will be if i use sprites instead. If the sprite buttons would work like a construct2 button (avoid input on my stage behind the button) - everything would be fine.

Or is there a possability to change the Button style? And add a sprite instead of this grey background?

Can someone help me out with this?
B
9
S
2
Posts: 147
Reputation: 1,041

Post » Sat Jul 16, 2016 12:58 am

You could disable the zoom effect. Not sure how you coded it but you use "On overlap" or "is InTouch" with the sprite but invert it. So the zoom effect doesn't happen.
Image
B
75
S
23
G
3
Posts: 673
Reputation: 9,283

Post » Tue Jul 19, 2016 12:22 pm

Option 1/ As you suggested yourself.
Yes you can alter the style of a button.

Use the action Button > 'Set CSS Style'. I did not use CSS myself yet.
The codes this action needs you can find when you google on "CSS style text".

Option 2/ Use sprites.

There are a lot of technics to do this with sprites.

Let me suggest just one. All GUI buttons go in 1 container. Create one of them to created them all when needed. Destroy one to destroy them all when they are no more needed. Choose one of those buttons to reference to. Lets say that button is 'TheOkButton'.

Now the zoom you gots to cage with ...

System > Compare two values > TheOkButton.count = 0. (if there are no TheOkButton sprites on the screen, the zoom can work.
Then all the stuff you have in place to zoom.

No clickable/touchable problems during normal gameplay, they are just not there.
B
33
S
18
G
28
Posts: 2,493
Reputation: 20,950

Post » Tue Jul 19, 2016 4:58 pm

So basically you were taking advantage of the fact that buttons did not trigger the "on tap" condition, while sprites do. To solve this, add a condition to your ”on tap"event - an inverted "is touching" spriteButton.
Mistakes were made.
B
52
S
26
G
110
Posts: 1,623
Reputation: 62,167

Post » Wed Jul 20, 2016 3:58 am

Hi, you can use Button behavior : viewtopic.php?t=76546&start=0
B
17
S
10
G
19
Posts: 140
Reputation: 11,457

Post » Thu Jul 21, 2016 8:28 am

@99Instances2Go
@Saad Swad
@oosyrag
@TheDom

Thank you very much for your answers - i will try it out today. I will give you a Feedback if its working :) Nice ones!

I dont want to use the CSS stuff for this project, so if i would get the sprites to work with the same characteristics - it would be absolutly nice!

@99Instances2Go would be a nice suggestion, but the buttons are visible the whole time the game is running. Currently iam working with the Plugins youve/Saad Swad sendet me (rex). But at the moment i couldnt figure out a solution.
B
9
S
2
Posts: 147
Reputation: 1,041


Return to How do I....?

Who is online

Users browsing this forum: Yahoo [Bot] and 33 guests