Hello again.
I have NO idea what I am doing wrong here, but for some reason I cannot
get the proper value from either agk::GetSpriteXByOffset or
agk::GetSpriteYByOffset. I had a problem before while applying force,
thought I solved it--didn't after actually trying it (I ported my old BASIC code
to my CPP code). I found my problem (or what I think it is), and it
seems to do with getting X Y positions. This is what I am doing and how I found
the issue I am having:
/*
SubApps are something I made for fast prototyping to avoid making new
projects. Essentially the main app has a pointer to a SubApp and the main app's
canned methods (Begin, End, Loop) call each of the SubApp's methods.
Also Vars is a class I made that contains a bunch of enumerations and variables I
use every where. It's a bad name, but whatever.
*/
//INTERFACE
class PhysicsTetris:public SubApp
{
public:
unsigned spriteID;
unsigned imageID;
public:
PhysicsTetris();
~PhysicsTetris();
public:
virtual void Begin();
virtual void End();
virtual void init();
virtual bool Loop();
virtual void update();
};
//IMPLEMENTATION
void PhysicsTetris::Begin(void)
{
init();
}
void PhysicsTetris::End(void)
{
agk::DeleteAllText ();
agk::DeleteAllSprites();
agk::DeleteAllObjects();
agk::DeleteAllImages ();
}
void PhysicsTetris::init()
{
agk::SetVirtualResolution(Vars::WINDOW_WIDTH, Vars::WINDOW_HEIGHT);
agk::SetScissor (0, 0, 0, 0);
agk::SetClearColor (0, 0, 0);
agk::SetSyncRate (60, 0);
agk::SetPhysicsGravity (0, 1);
agk::SetPhysicsDebugOn ();
//Make a red red image.
imageID = agk::CreateImageColor(255,0,0,255);
//Make a red sprite with the red image.
spriteID = agk::CreateSprite(imageID);
//Set up the sprite with some dimensions, and physics.
agk::SetSpriteSize (spriteID, 50, 50);
agk::SetSpriteOffset (spriteID, agk::GetSpriteWidth(spriteID)/2,
agk::GetSpriteHeight(spriteID)/2);
agk::SetSpritePositionByOffset(spriteID, 600, 100);
agk::SetSpritePhysicsOn (spriteID, Vars::PHYSX_DYNAMIC);
agk::SetSpritePhysicsMass (spriteID, 100);
}
bool PhysicsTetris::Loop(void)
{
update();
/** End the application when Escape key hit. */
if (agk::GetRawKeyState(Vars::KEY_ESCAPE))//
return true;
else
return false;
}
void PhysicsTetris::update()
{
agk::Print(agk::ScreenFPS());
//THIS IS WHERE THE PROBLEM IS! All it prints is 600 and 100.
//The sprite ID is the same as when it is created (10001 in my case), but
//these values never change. Even as it falls the values stay the same.
agk::Print(agk::GetSpriteXByOffset(spriteID));
agk::Print(agk::GetSpriteYByOffset(spriteID));
agk::StepPhysics(.1f);
agk::Sync();
}
What am I doing wrong? I stripped out all of my wrapper classes and just use
the base stuff from the "agk" namespace as you can see above. I've done it the
same way with BASIC and it works fine. I love CPP too much to go back to BASIC,
so some help would be amazing.
EDIT[solved]: The error was between the chair and keyboard. The above code actually works.... I'm not sure what I was smoking when I wrote this.
-mrradd-