Just apply a force upwards on the sprite to counteract gravity. Use SetSpritePhysicsForce()
In real life, that is all that is happening in a helium balloon - so it makes sense to copy real life in our simulations. In the case of a helium balloon it still has weight and mass and it is still affected by gravity....its just that the equivalent air volume of the balloon weighs more than the balloon and the helium in it. This is just buoyancy. Buoyancy occurs in any fluid medium (air/water). This is basic physics.
So in a simulation...Set gravity to the normal value (9.8m/s/s or whatever value you want) so normal items accelerate towards the floor. Then apply a force upwards at the sprite that you want to float. (a balloon for example)
If you apply no force...the sprite falls downwards under the force of gravity
If you apply an upwards force equal to the gravitational force (=Mass * 9.8m/s/s) then the sprite just sits there and doesn't move at all. (You are simply counteracting gravity)
If you apply a force greater than gravity...the sprite accelerates upwards. (like a Nasa rocket)
So if you open the Gravity sample that comes with app game kit, in your "Physics" directory. You can replace the code in that example with this code
// gravitational pull downwards
// virtual resolution
SetVirtualResolution ( 320, 480 )
// display a background
CreateSprite ( LoadImage ( "background4.jpg" ) )
// load an image
LoadImage ( 1, "small_silver.png" )
// create 5 sprites
CreateSprite ( 1, 1 )
CreateSprite ( 2, 1 )
CreateSprite ( 3, 1 )
CreateSprite ( 4, 1 )
CreateSprite ( 5, 1 )
// set their positions
SetSpritePosition ( 1, 0, 200 )
SetSpritePosition ( 2, 50, 200 )
SetSpritePosition ( 3, 100, 200 )
SetSpritePosition ( 4, 150, 200 )
SetSpritePosition ( 5, 200, 200 )
// turn physics on
SetSpritePhysicsOn ( 1, 2 )
SetSpritePhysicsOn ( 2, 2 )
SetSpritePhysicsOn ( 3, 2 )
SetSpritePhysicsOn ( 4, 2 )
SetSpritePhysicsOn ( 5, 2 )
// alter default gravity
SetPhysicsGravity ( 0, 9.8 )
// main loop
do
// Apply some upwards forces
SetSpritePhysicsForce(3,GetSpriteX(3)+25,GetSpriteY(3)+25,0,-9.8*100) // Counter act gravity
SetSpritePhysicsForce(4,GetSpriteX(4)+25,GetSpriteY(4)+25,0,-14*100) // float upwards
SetSpritePhysicsForce(5,GetSpriteX(5)+25,GetSpriteY(5)+25,0,-25*100) // fly upwards
// Print out the mass of a box
print ("Box Mass: " + str(GetSpritePhysicsMass(1)))
// update screeen
Sync ( )
loop
It jsut adds a few forces at certain sprites
It shows some boxes which fall to the floor under the force of gravity
A box that stays still
A box that floats upwards
And a box that goes even faster upwards
Its easy really
Please note....you need to apply forces at the centre of the sprite. Specifically at the 'centre of mass' of the sprite (often abbrieviated to COM). Otherwise you cause the sprite to rotate as well.
And... you need to apply the force every frame. This is so you can control the force on a frame by frame basis. You can have cars that accelerate, turn, crash and decelerate etc...
Gravity is the only force that is applied for you by AGK....all the others are up to you....
Use the force....wisely