Hello.
I'm writing a basic Asteroid game in GDI using double buffering. The ship, the background and the asteroids (which are drawn using Polygon()) were initially colored with a solid color HBRUSH, but now I'm trying to replace all of the colors with BMP textures. For the background, I used LoadBitmap() and CreatePatternBrush() to add a starry texture. That method doesn't seem to work with the asteroids though, because they are moving, so I get a scrolling texture. Is there any way to fix that? Here's my code for moving/drawing the asteroids:
Code:HBITMAP asteroidsBitmap = LoadBitmap ( GetModuleHandle ( NULL ), MAKEINTRESOURCE ( IDB_BITMAP2 ) );
HBRUSH asteroidsBrush = CreatePatternBrush ( asteroidsBitmap );
Thanks.Code:// Move asteroids
for ( int element = 0; element < MAX_ROCKS; element++ )
{
if ( rocks [ element ].alive )
{
x = rocks [ element ].xCenter;
y = rocks [ element ].yCenter;
x += rocks [ element ].xMove;
y += rocks [ element ].yMove;
// Check if out of range on x axis
if ( ( x < 25 ) || ( x > ( WINDOW_WIDTH - 25 ) ) )
x = WINDOW_WIDTH - x;
// Check if out of range on y axis
if ( ( y < 25 ) || ( y > ( WINDOW_HEIGHT - 25 ) ) )
y = WINDOW_HEIGHT - y;
rocks [ element ].xCenter = x;
rocks [ element ].yCenter = y;
SelectObject ( backDC, asteroidsBrush );
SetAsteroidVertices ( element );
Polygon ( backDC, asteroidVertices, 9 );
}
}