Posted: 2nd Dec 2011 1:33
Is there a way to do this? I can position the joystick itself easily enough, but am a little stuck when it comes to the button or buttons. I have tried SetVirtualButtonPosition but it seems that is only for buttons you create yourself rather than the ones for the joystick.
I could make buttons and drop the joystick button commands, but that would cause issues with people actually using a joystick. Am I missing something silly?
Posted: 2nd Dec 2011 15:30
You can use the AGKButton commands to pick up joystick buttons and have them on screen when no joystick is connected.
Posted: 3rd Dec 2011 1:42
Can you elaborate on this? I see the GetVirtualButtonExists( index ) command, but as it needs an index to test against, and 1 to 12 do not seem to register, I am a still stuck. As I don't have a device to test on, I want to force the buttons on screen for me to setup as best I can, so when I get chance to test it will be more useful. Tests have worked pretty well, but the games were unplayable because of the buttons being offscreen or such.
Posted: 4th Dec 2011 9:17
You need to create the button in much the same way you did the joystick.

It often helps to see it in use so here's a quick demo;
+ Code Snippet
// Add a Joystick
addVirtualJoystick ( 1, 88 , 88 , 20 )
// Add a Button
addVirtualButton ( 1 , 12 , 86 , 20 )
setVirtualButtonText ( 1, "Change" + chr ( 10 ) + "Colour" )
// Create a Sprite to show effect
mySprite = createSprite ( 0 )
setSpriteSize ( mySprite , 20 , 20 )
setSpriteOffset ( mySprite , 10 , 10 )
// Set Sprite initial position in two variables
spriteX = 50
spriteY = 30

do
	// Change Sprite position variables based on Virtual Joystick inputs
	spriteX = spriteX + getVirtualJoystickX ( 1 ) * 5
	spriteY = spriteY + getVirtualJoystickY ( 1 ) * 5
	// Limit Sprite movement to screen area and above Joystick & Button
	if spriteX < 10 then SpriteX = 10
	if spriteX > 90 then SpriteX = 90
	if spriteY < 10 then SpriteY = 10
	if spriteY > 60 then SpriteY = 60

	// If button pressed , change sprite colour to a random value
	if getVirtualButtonPressed ( 1 ) then setSpriteColor ( mySprite , random ( 128 , 240 ) , random ( 128 , 240 ) , random ( 128 , 240 ) , 255 )

	// Set New Sprite Position from Sprite position variables
	setSpritePositionByOffset ( mySprite , spriteX , spriteY )
	Sync()
loop

This should help you get your head around it.
Posted: 4th Dec 2011 20:10
Thanks Marl, however, I am actually using the joystick commands rather than the virtual joystick ones. Basically, because it defaults to the virtual joystick on non joystick or keyboard enabled devices. I thought it ideal to use in general. However, the position of the buttons for that seem impossible to change. It does seem to take the point away from it reverting automatically, when you can't control how it looks afterwards.
I really think this should be looked at in future updates. A simple command to position your actual joystick buttons, would make things a lot better. The code Marl put up above for instance works fine, but only as a virtual joystick, not as a real one. Using the actual joystick commands gives you the ability to test with both a joystick, keys and the virtual joystick. With the obvious problem of screen placement I have mentioned.