We’d love to hear from you. Whether you have a question that you’d like us to answer as part of our FAQ,  you’ve identified something that just doesn’t quite look right in one of our tutorials, you have a business opportunity or for any other reason, please use this simple form to contact us.

We’ll do our best to provide a prompt response.

Like what you see?...pass it on!

Handling Input

Instead of simply moving our sprite slowly across the X-axis, lets instead change it so we can move up and down using a gamepad, keyboard or onscreen controller. Thankfully with AppGameKit, this is really simple, as we can use a single virtual joystick interface that uses a real joystick if it exists, an on-screen joystick if needed or default WASD keyboard controls if on a PC without a joystick attached.

Now enter the following code:

#include "MainScene.scene"

//Properties
verticalSpeed as float = 5.0

MainScene_setup()

SetJoystickScreenPosition ( 100, GetVirtualHeight() - 100, 90 )
if(GetVirtualJoystickExists(1))
	SetVirtualJoystickVisible(1,1)
	SetButtonScreenPosition(1,GetVirtualWidth() - 50, 100, 80)
	SetVirtualButtonSize(1,100,50)
    SetVirtualButtonText(1,"Fire")
endif

do	
	MainScene_sync()
	Print(ScreenFPS())
	Sync()
	
	//Virtual Joystick handling
	yAxisMovement# = GetJoystickY()
	if( abs(yAxisMovement#) > 0.1)
		spriteX# = GetSpriteX(MainScene_Player)
		spriteY# = GetSpriteY(MainScene_Player)
		SetSpritePosition(MainScene_Player,spriteX#, spriteY# + (verticalSpeed) * yAxisMovement#)
	endif
	
	if(GetButtonPressed(1))
		print("BOOM")
	endif
loop

This code will display a virtual joystick on a mobile device or using an actual joystick. You can also use the WASD keys for up and down, as well as the spacebar to shoot. Note, if you don’t want default settings, you can handle each task manually such as handling raw input, raw joystick support, touch, etc.

Speaking of mobile support, now might be a good time to demonstrate one of the coolest features of AGK:S, the ability to broadcast to an Android or iOS device. To do so, you need to install the client from either the App Store or Google Play Store. Once installed, run the application on your device of choice.

AppGameKit broadcast to Android or iOS

You can now broadcast your application to your device using the broadcast button on the toolbar.

AppGameKit broadcast button

And tada!

AppGameKit

Loading Scenes<<PreviousTable of ContentsNext>>Adding Bullets and Sound

Like what you see?...pass it on!

script ends --->