I've got it working how I want it to work but it's confusing as hell!
Let me explain what I'm really after. To start with I want the text box disabled. I then want the user to press a button next to it to edit what's in the text box. This is for a username. When they press the button the textbox is active and they can start typing. Once they've finished they press the button again to save and then it's finished. Each press of the button will change the button label, from "Edit" to "Save" and then eventually "Taken" if the username is already taken. This isn't a normal register form. Each user gets assigned a username when they update/install the app, and if they choose to they can change it.
txtBox = CreateEditBox()
SetEditBoxSize(txtBox, 80, 5)
SetEditBoxPosition(txtBox, 10, 10)
SetEditBoxActive(txtBox, 0)
sprButton = CreateSprite(0)
SetSpriteSize(sprButton, 20, 5)
SetSpritePosition(sprButton, 40, 20)
do
if (GetPointerPressed() = 1)
spriteHit = GetSpriteHit(ScreenToWorldX(GetPointerX()), ScreenToWorldY(GetPointerY()))
else
if (GetPointerReleased() = 1)
if (spriteHit = sprButton and buttonPressed = 0)
SetEditBoxActive(txtBox, 1)
SetEditBoxFocus(txtBox, 1)
buttonPressed = 1
endif
endif
endif
if (GetEditBoxHasFocus(txtBox) = 0 and spriteHit = sprButton and buttonPressed = 1)
Message("Pressed")
spriteHit = 0
endif
Sync()
loop
For now the problem is solved it's doing what I want. But most scenarios wouldn't want the textbox deactivated first. A normal scenario would be to click in the textbox, type something and then press the submit button. That works on a normal computer but on a device when you click anywhere outside of the textbox even if you press on a sprite, GetPointerPressed doesn't register. I knew there was a reason why I try to avoid using edit boxes in AppGameKit