I am trying to create a level meter type of display. The sprite (a rectangle) height is created randomly but I want the base of the sprite to remain at the same X,Y location. So I thought simple math would work, however I am seeing both ends of the sprite "move" as I am wanting the bottom to stay put. It seemed like the sprite's Y position should be the base location minus the height of the sprite. That is not working for some reason.
sprX and sprY is the location that I want the bottom of the sprite to be. sprH is the random height change.
If I want the base at 300 with the sprite height of say 50, then the sprite Y position should be 250. Correct? Because 250 plus 50 is 300. But that is not what happens!
But I am experiencing something like the height of the sprite is moving about a center location and not either end. I cannot see why my code would do this. Any insights?
Here is the code that runs in a loop:
if (MainLoop.scrolltext.laser == 1)
{
agk::DeleteImage(imgTemp);
agk::DeleteSprite(sprTemp);
sprX = 350;
sprY = 300;
sprW = 50;
r = agk::Random(0, 50);
sprH = float(100 + r);
sprLeft = sprX;
sprUpper = sprY - sprH;
sprRight = sprLeft + sprW;
sprLower = sprY;
laserIndColor = agk::MakeColor(0, 255, 100);
agk::DrawBox(0, 0, sprW, sprH, laserIndColor, laserIndColor, laserIndColor, laserIndColor, 1);
imgTemp = agk::GetImage(0, 0, sprW, sprH);
agk::ClearScreen();
sprTemp = agk::CreateSprite(imgTemp);
agk::SetSpritePosition(sprTemp, sprLeft, sprUpper);
agk::SetSpriteDepth(sprTemp, 1);
agk::SetSpriteVisible(sprTemp, 1);
MainLoop.scrolltext.laserOff = 1;
} //if (MainLoop.scrolltext.laser == 1)
home.wavecable.com/~mindsclay