I am setting up my pause menu. At depth 5 I have resume, restart, and an exit sprite. On depth 4 I have Yes and no setup to make sure the player made the right choice. When I hit restart hit it also hits no button behind it even though its visibility is set to 0.
click on sprite code
if ( agk::GetPointerPressed ( ) == 1 )
{
float startX = agk::GetPointerX ( );
float startY = agk::GetPointerY ( );
//Pause button is pressed----------------------------------------------------------------------------------------------
if(1 == agk::GetSpriteHitTest(pauseSprite, agk::ScreenToWorldX(startX), agk::ScreenToWorldY(startY)))
{
agk::SetSpriteVisible(blackScreenSprite, 1);
agk::SetSpriteVisible(resumeButtonSprite, 1);
agk::SetSpriteVisible(restartButtonSprite, 1);
agk::SetSpriteVisible(exitButtonSprite, 1);
}
//Pause button is pressed----------------------------------------------------------------------------------------------
if(1 == agk::GetSpriteHitTest(resumeButtonSprite, agk::ScreenToWorldX(startX), agk::ScreenToWorldY(startY)))
{
//calories = 0.0;
agk::Print("resume Hit");
agk::ResumeSprite(cynSprite);
agk::SetSpriteVisible(blackScreenSprite, 0);
agk::SetSpriteVisible(resumeButtonSprite, 0);
agk::SetSpriteVisible(restartButtonSprite, 0);
agk::SetSpriteVisible(exitButtonSprite, 0);
// whichLevel = currentLevel;
}
//Restart button is pressed
if(1 == agk::GetSpriteHitTest(restartButtonSprite, agk::ScreenToWorldX(startX), agk::ScreenToWorldY(startY)))
{
agk::Print("restart Hit");
agk::SetSpriteVisible(yesButtonSprite, 1);
agk::SetSpriteVisible(noButtonSprite, 1);
}
//Exit button is pressed
if(1 == agk::GetSpriteHitTest(exitButtonSprite, agk::ScreenToWorldX(startX), agk::ScreenToWorldY(startY)))
{
agk::Print("Hit exit");
agk::SetSpriteVisible(yesButtonSprite, 1);
agk::SetSpriteVisible(noButtonSprite, 1);
}
//Yes button is pressed
if(1 == agk::GetSpriteHitTest(yesButtonSprite, agk::ScreenToWorldX(startX), agk::ScreenToWorldY(startY)))
{
//calories = 0.0;
agk::Print("hit yes");
agk::ResumeSprite(cynSprite);
agk::SetSpriteVisible(blackScreenSprite, 0);
agk::SetSpriteVisible(resumeButtonSprite, 0);
agk::SetSpriteVisible(restartButtonSprite, 0);
agk::SetSpriteVisible(exitButtonSprite, 0);
}
//No button is pressed
if(1 == agk::GetSpriteHitTest(noButtonSprite, agk::ScreenToWorldX(startX), agk::ScreenToWorldY(startY)))
{
agk::Print("Hit no");
agk::SetSpriteVisible(blackScreenSprite, 1);
agk::SetSpriteVisible(resumeButtonSprite, 1);
agk::SetSpriteVisible(restartButtonSprite, 1);
agk::SetSpriteVisible(exitButtonSprite, 1);
agk::SetSpriteVisible(yesButtonSprite, 0);
agk::SetSpriteVisible(noButtonSprite, 0);
}
}
load images
int blackScreenImage;
int blackScreenSprite;
int resumeButtonImage;
int resumeButtonSprite;
int restartButtonImage;
int restartButtonSprite;
int exitButtonImage;
int exitButtonSprite;
int yesButtonImage;
int yesButtonSprite;
int noButtonImage;
int noButtonSprite;
int pauseImage;
int pauseSprite;
pauseImage = agk::LoadImage("Images/pauseButton.png");
pauseSprite = agk::CreateSprite(pauseImage);
agk::SetSpritePosition(pauseSprite,84.5f, 13.0f);
agk::SetSpriteVisible(pauseSprite, 1);
agk::SetSpriteSize(pauseSprite, 10.0f, -1);
agk::SetSpriteDepth(pauseSprite, 1);
agk::FixSpriteToScreen(pauseSprite, 1);
//set variable for moving screen
blackScreenImage = agk::LoadImage("Images/blackbg.png");
blackScreenSprite = agk::CreateSprite(blackScreenImage);
agk::SetSpritePosition(blackScreenSprite, 0.0f, 0.0f);
agk::SetSpriteVisible(blackScreenSprite, 0);
agk::SetSpriteColorAlpha(blackScreenSprite, 200);
agk::SetSpriteDepth(blackScreenSprite, 5);
agk::SetSpriteSize(blackScreenSprite, 100.0f, 100.0f);
agk::FixSpriteToScreen(blackScreenSprite, 1);
resumeButtonImage = agk::LoadImage("Images/resumebutton.png");
resumeButtonSprite = agk::CreateSprite(resumeButtonImage);
agk::SetSpritePosition(resumeButtonSprite, 50.0f, 30.0f);
agk::SetSpriteSize( resumeButtonSprite, 17.0f, -1);
agk::SetSpriteVisible( resumeButtonSprite, 0);
agk::FixSpriteToScreen( resumeButtonSprite, 1);
agk::SetSpriteDepth( resumeButtonSprite, 4);
exitButtonImage = agk::LoadImage("Images/exitbutton.jpg");
exitButtonSprite = agk::CreateSprite(exitButtonImage);
agk::SetSpritePosition(exitButtonSprite, 50.0f, 70.0f);
agk::SetSpriteSize( exitButtonSprite, 17.0f, -1);
agk::SetSpriteVisible( exitButtonSprite, 0);
agk::FixSpriteToScreen( exitButtonSprite, 1);
agk::SetSpriteDepth( exitButtonSprite, 4);
restartButtonImage = agk::LoadImage("Images/restartbutton.png");
restartButtonSprite = agk::CreateSprite(restartButtonImage);
agk::SetSpritePosition(restartButtonSprite, 50.0f, 50.0f);
agk::SetSpriteSize( restartButtonSprite, 17.0f, -1);
agk::SetSpriteVisible( restartButtonSprite, 0);
agk::SetSpriteDepth(restartButtonSprite, 1);
agk::FixSpriteToScreen( restartButtonSprite, 1);
agk::SetSpriteDepth( restartButtonSprite, 4);
yesButtonImage = agk::LoadImage("Images/yesbutton.png");
yesButtonSprite = agk::CreateSprite(yesButtonImage);
agk::SetSpritePosition(yesButtonSprite, 40.0f, 50.0f);
agk::SetSpriteSize( yesButtonSprite, 17.0f, -1);
agk::SetSpriteVisible( yesButtonSprite, 0);
agk::FixSpriteToScreen( yesButtonSprite, 1);
agk::SetSpriteDepth( yesButtonSprite, 3);
noButtonImage = agk::LoadImage("Images/nobutton.jpg");
noButtonSprite = agk::CreateSprite(noButtonImage);
agk::SetSpritePosition(noButtonSprite, 50.0f, 50.0f);
agk::SetSpriteSize( noButtonSprite, 17.0f, -1);
agk::SetSpriteVisible( noButtonSprite, 0);
agk::FixSpriteToScreen( noButtonSprite, 1);
agk::SetSpriteDepth( noButtonSprite, 3);