Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers AppGameKit Corner / Virtual Button

Author
Message
darzon
7
Years of Service
User Offline
Joined: 23rd Oct 2010
Location: Italy
Posted: 28th Dec 2017 18:16
Hi,
I need to put an alphabet letter on a Virtual Button.

I can see the Virtual Button but not the letter
I try with TextDepth but seems like that the letter "A" is always back to Button
Where is the bug in my code ?
I use Arial.ttf font

thank you

this is the code:

font=LoadFont("Arial.ttf")
tx2=createtext("A")
SetTextColor(tx2,0,0,0,255)
SetTextFont(tx2, font)
SetTextSize(tx2, 80)
SetTextPosition(tx2,200,200)
SetTextDepth(tx2,0)

AddVirtualButton(1,200,200,200)
SetVirtualButtonAlpha(1,255)
SetVirtualButtonColor(1,0,0,255)
SetVirtualButtonVisible(1,1)
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 28th Dec 2017 18:36
Doesnt

SetVirtualButtonText( virtualbuttonID, "text")

do it?

darzon
7
Years of Service
User Offline
Joined: 23rd Oct 2010
Location: Italy
Posted: 28th Dec 2017 19:25
yes, i tried also to include the line

SetVirtualButtonText( 1, "A")

But AppGameKit use always the default font and not Arial.ttf font

any idea ?

Conjured Entertainment
AGK Developer
12
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 29th Dec 2017 02:13 Edited at: 29th Dec 2017 02:14
You can always make an image for it if all else fails

The letters are usually really small anyway, unless you increase the size of the button, so using an image works well because you have more control.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
blink0k
AGK Developer
5
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 29th Dec 2017 03:34
That is a bit disappointing. Not being able to set the button font AND not being able to make the text appear in front of the button
puzzler2018
User Offline
Joined: 8th Oct 2017
Location:
Posted: 29th Dec 2017 13:16
Those virtual button images are hidden away somewhere in the appgatekit resources. so changing them in there will change it for every single app we create.

I would just leave them well alone - not to mention are we allowed to.

I would -

- Create a 1x1 pixel mouse dot
- Create a sprite of that mouse dot
- Move the sprite to getpointerx() and getpointery()

do
- Create new sprite (your own image) - this is a button
- repeat for how many buttons you need
loop

- check collisions of the mouse dot and the button sprites
- if clicked on them then do something

If unsure, then I can provide some code

Conjured Entertainment
AGK Developer
12
Years of Service
User Offline
Joined: 12th Sep 2005
Location: Nirvana
Posted: 29th Dec 2017 17:04 Edited at: 29th Dec 2017 17:11
Quote: "Those virtual button images are hidden away somewhere in the appgatekit resources. so changing them in there will change it for every single app we create.

I would just leave them well alone - not to mention are we allowed to."

That is not what I meant.

I meant using the commands to do so... Home --> Commands --> Input --> SetVirtualButtonImageUp

Quote: "

SetVirtualButtonImageUp

Description
Sets the image used by the button when it is not being pressed. You can use an image ID of 0 to return it to the default image.

Definition
SetVirtualButtonImageUp( index, imageID )

Parameters
index - The ID of the virtual button to set.
imageID - The image ID to use for this button."


There is a SetVirtualButtonImageDown too, if you want an effect when pressing it.

This method gives you full control of what you have on the button, when pressed or not.

Coding things my way since 1981 -- Currently using AppGameKit V2 Tier 1
PHeMoX
User Offline
Joined: 9th Jan 2018
Location:
Posted: 9th Jan 2018 14:16
Yeah, except it doesn't allow you to change the Font or more importantly Font size. We seem to need like a SetVirtualButtonFont and SetVirtualButtonFontSize for AppGameKit, which as far as I know do not exist as commands (yet?).

Especially Font Size is important. My Android phone has such a high screen resolution that any of the default text is like 4mm in actual height. I could also be wrong, but it seems the default text size also is very small, not taking into account any text scaling done by Android itself (assumption on my part, might not actually affect default text in AGK).

I would love the custom sprite button stuff to work by using something simple as GetSpriteHit at GetPointerX and GetPointerY location on the screen, BUT there seems to be a bit of an issue using that work around when you are using sprite user interface overlays that cover large parts of where a button should be. For example, lets assume there's a 'menu bar' for an Android app on top, with a transparent bottom area where the actual app runs / functions.

If you're going to use the GetSpriteHit stuff, you're going to get the ID returned from the sprite overlay (which has a bounding box across the entire screen), but not the images underneath which would be our custom buttons. Of course, I can crop the image so the bounding box is smaller, but it is kind of bad when you want a sprite that is on top of everything, even buttons when you scroll the screen using GetViewOffset commands.

So unless we can use other AppGameKit commands like maybe SpriteRayCast in some way and define which sprites on top to ignore, we would kind of need some additional commands to the SetVirtualButton commands. Don't get me wrong, I can add a text to the ButtonImageDown and ButtonImageUp using Photoshop, but changing text would be a huge time saver and wouldn't require loading in as many images, could re-use the same button backgrounds etc.

Anyone have some thoughts?? (By the way, wasn't there once this 'priority' feature that allowed you to scan for sprites underneath other sprites?)

(Also, yes, first post here. Thought I'd get back into game development again and came across AppGameKit 2 on Steam. Loving it so far!)

Van B
Moderator
15
Years of Service
User Offline
Joined: 8th Oct 2002
Location: Sunnyvale
Posted: 9th Jan 2018 15:10
If you really want to take control over virtual buttons, the best way is to stop using them.

Seriously, they aren't designed for looking good and have limits that you've already encountered.

Instead, make your own virtual buttons, with a sprite and a text and all the control you'd ever need. It's not like the code is anything you won't have to deal with anyway, like detecting a sprite click, but it means you can alter text on mouse over, add any animation to the button you want, changing text properties... it all adds up to a lot of benefits. Frankly, I'd waste no more time on virtual buttons, and start making actual buttons - really I think virtual buttons should only be used for game controls, not menus... not if you want things looking nice with variable text.
The code is dark and full of errors
PHeMoX
User Offline
Joined: 9th Jan 2018
Location:
Posted: 9th Jan 2018 16:44
Thanks for your comment. Yeah I have to agree with what you're saying.

Any ideas on how to deal with the sprite depth sorting though? I understand it's perhaps easier to just match the boundingboxes of a sprite as to not have transparent areas cover the sprite buttons you'd make yourself as you suggest, but it would be somewhat neat if we would get an option to scan for all sprites underneath in a certain location which would return their ID.

For example like a new GetSpriteHitThrough command, which would return a sprite ID just like GetSpriteHit, but instead of stopping at the sprite that's on top just return all sprite IDs encountered at that location regardless of sorting depth. That way more advanced user interfaces are probably quite a bit easier to program.

I don't think there's currently a way of ignoring transparent areas of a sprite with this, right? I mean, it's boundingbox-only detection, not 'visible pixel' detection. Anyway, I'm sure you'll get what I'm talking about. Would be neat if anyone has some additional ideas on this with AGK2.

Login to post a reply

Server time is: 2018-04-24 04:03:38
Your offset time is: 2018-04-24 04:03:38