Hi all,
I'm trying to use the accelerometer commands together with physics but I can't seam to achieve it. The idea is to control the ball using the accelerometer and the ball should pick speed if the iphone in a steep angle. Can any one please help me?
p.s the images used in the code bellow come from the AppGameKit data folder
#include "Main.h"
using namespace AGK;
app App;
int iIndex = 5;
int iTime = 100;
void app::Begin (void){
agk::SetVirtualResolution ( 320, 480 );
agk::EnableClearColor ( 0 );
int backdrop = agk::CreateSprite ( agk::LoadImage ( "../Data/background1.jpg" ) );
agk::LoadImage ( 2, "../Data/ball1.png" );
agk::CreateSprite(5,2);
agk::SetSpritePosition(5,50.0f, 0.0f);
agk::SetSpriteSize(5,25.0f,25.0f);
agk::SetSpriteShape(5, 2 );
agk::SetSpritePhysicsMass(5, 0.5f);
agk::SetSpritePhysicsRestitution ( 5, 0.5f );
agk::SetSpritePhysicsOn ( 5, 2 );
agk::SetPhysicsGravity ( 1.5f, 1.5f );
}
void app::Loop(void){
float x = agk::GetDirectionX ();
float y = agk::GetDirectionY ();
float speed = agk::GetDirectionSpeed() * 10;
float angle = -90 + agk::GetDirectionAngle();
x = (float) agk::GetSpriteX (5) + x + (speed * agk::Cos(angle));
y = (float) agk::GetSpriteY (5) + y + (speed * agk::Sin(angle));
agk::SetSpritePosition ( 5, x, y );
agk::Sync();
}
void app::End(void){
}