Background Colour has vanished!

A

Ali

Hi,

I wrote the following code and when I loaded the images as static
images my background displayed as black (set at start of code),
however, now I've started (trying!) to get my image to move, my
background has defaulted to white. Can anyone tell my why this is and
how to correct it?

Thanks very much,
Ali :eek:)


import java.awt.*;
import java.awt.geom.*;
import java.applet.*;

public class SpaceInvaders extends Applet
{
StringBuffer message;

public void init()
{

}

public void start()
{
message = new StringBuffer("Game Started!");
}

public void stop()
{

}

public void paint(Graphics g)
{
Graphics2D g2 = (Graphics2D) g;

// GETS WINDOW SIZE //
int gw = getSize().width;
int gh = getSize().height;

// SETS BACKGROUND COLOUR //
setBackground(Color.black);


// LOADS SPACE INVADER GRAPHICS //
Image Invader1a = getImage(getDocumentBase(),"invader1a.gif");
Image Gun = getImage(getDocumentBase(),"gun.gif");
Image Shield = getImage(getDocumentBase(),"shield.gif");
Image InvaderCover = getImage(getDocumentBase(),
"invaderCover.gif");

// LOADS IMAGES //

int imageX = (gw/2)-16;
int imageY = gh-80;

g2.drawImage(Gun, imageX, imageY+20, this);
g2.drawImage(Shield, imageX-171, imageY, this);
g2.drawImage(Shield, imageX-21, imageY, this);
g2.drawImage(Shield, imageX+129, imageY, this);

// MOVING INVADERS //

int x = 0;
int y = 100;
int moveX = 35;
int moveY = 20;

for (y=100; y<101; y=100)
{
g2.drawImage(InvaderCover, x, y, this);


if (x>300)
{
moveX = -35;
}
else if (x<1)
{
moveX = 35;
}

x += moveX;
g2.drawImage(Invader1a, x, y, this);

for (int delay=0; delay<50000000; delay++);
}
}
}
 
P

Prateeksha Web Services

Hello

for drawing of images in the game, you have to use bltbit function. the new
image is just add to the previous image by using bits calculations. say the
new image white dots are not displayed at all. this is used for all games.

I have not been programming in java as of late. hence i cannot submit you
fill source code. but you will find it on the net.

sumeet shroff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,049
Latest member
Allen00Reed

Latest Threads

Top