Hi All, thanks in advance!
After a looooong time away from coding I thought I would get back it AppGameKit and c++ again! So quickly got the template to compile etc but testing very simple physics collisions (of 2d sprites) and the collision seems not to trigger?
void app::Begin(void)
{
agk::SetVirtualResolution (DEVICE_WIDTH, DEVICE_HEIGHT);
agk::SetClearColor( 151,170,204 ); // light blue
agk::SetSyncRate(60,0);
agk::SetScissor(0,0,0,0);
agk::SetPhysicsDebugOn();
//Debug test srpites
TestSprA = agk::CreateSprite(0);
agk::SetSpriteSize(TestSprA, 64, 64);
agk::SetSpriteColor(TestSprA, 0, 255, 0, 255);
agk::SetSpritePosition(TestSprA, 512, 600);
agk::SetSpritePhysicsOn(TestSprA, 1);
agk::SetSpriteActive(TestSprA, 1);
TestSprB = agk::CreateSprite(0);
agk::SetSpriteSize(TestSprB, 64, 64);
agk::SetSpriteColor(TestSprB, 0, 0, 255, 255);
agk::SetSpritePosition(TestSprB, 512, 700);
agk::SetSpritePhysicsOn(TestSprB, 1);
agk::SetSpriteActive(TestSprB, 1);
}
int app::Loop (void)
{
int ObjCounter = 0;
agk::Print( agk::ScreenFPS() );
//Debug Sprites
if (agk::GetRawKeyState(37))
{
agk::SetSpriteX(TestSprB, agk::GetSpriteX(TestSprB) - 2);
}
if (agk::GetRawKeyState(39))
{
agk::SetSpriteX(TestSprB, agk::GetSpriteX(TestSprB) + 2);
}
if (agk::GetRawKeyState(38))
{
agk::SetSpriteY(TestSprB, agk::GetSpriteY(TestSprB) - 2);
}
if (agk::GetRawKeyState(40))
{
agk::SetSpriteY(TestSprB, agk::GetSpriteY(TestSprB) + 2);
}
agk::Print("TestCollision");
unsigned int Test = agk::GetSpriteFirstContact(TestSprB);
if (Test )
{
agk::Print("HIT"); //NEVER HIT?
}
else
{
agk::Print("NO HIT");
}
if (agk::GetSpriteCollision(TestSprA, TestSprB))
{
agk::Print("BOUNDNG"); //THIS WORKS
if (agk::GetSpriteFirstContact(TestSprB) == 1)
{
agk::Print("PHYSICS"); //NEVER HIT?
}
}
agk::Sync();
return 0; // return 1 to close app
}
The bounding box collisions registers, but the physics ones do not?
As the above did not work, I moved to basic Script to check and this does not work:
// static and dynamic sprites
// virtual resolution
SetVirtualResolution ( 320, 480 )
SetPhysicsDebugOn()
// display a background
CreateSprite ( LoadImage ( "background7.jpg" ) )
// load an image
LoadImage ( 1, "small_blue.png" )
// create 5 sprites
CreateSprite ( 1, 1 )
CreateSprite ( 2, 1 )
CreateSprite ( 3, 1 )
CreateSprite ( 4, 1 )
CreateSprite ( 5, 1 )
Global XPos = 140
Global yPos = 200
// position our sprites
SetSpritePosition ( 1, 50, 0 )
SetSpritePosition ( 2, 100, 0 )
SetSpritePosition ( 3, 140, 200 )
SetSpritePosition ( 4, 170, 0 )
SetSpritePosition ( 5, 220, 0 )
// set 1 and 2 to be dynamic, 3 to be static and 4 and 5 to be dynamic
SetSpritePhysicsOn ( 1, 1 )
SetSpritePhysicsOn ( 2, 1 )
SetSpritePhysicsOn ( 3, 1 )
SetSpritePhysicsOn ( 4, 1 )
SetSpritePhysicsOn ( 5, 1 )
// main loop
do
if GetRawKeyState(37) = 1
xPos = xPos - 2
endif
if GetRawKeystate(39) = 1
xPos = xPos + 2
endif
if GetrawKeystate(38) = 1
yPos = yPos - 2
endif
if GetRawKeyState(40) = 1
yPos = yPos + 2
endif
SetSpritePosition(3, xPos, yPos)
if GetSpriteFirstContact(3) = 1
//Never gets Here?
print("HIT")
endif
// update the screen
Sync ( )
loop
What Am I missing?
Am I missing something?
I control all the juicy in here!