-
flicker problem
hi, im new to java, trying to learn!!
ive been given an assignment which involves creating a java game so i decided to go for the classic duck shoot game.
Ive created the background lake and the little ducks that swim accross the lake.
my problem is the little ducks flicker as they travel accross the page
ill post my code below if anyone has any ideas?
i tried to use the buffer to stop this and it doesnt work, im probly doing somthing stupid.
any ideas?
CHEERS
ASH
//////////////////////////////////////
// //
// Ashley Kay's Java Applet //
// Version 1 //
// //
// Duck Shoot Game //
// //
//////////////////////////////////////
import java.applet.*;
import java.awt.event.*;
import java.awt.*;
public class duckShoot extends Applet implements ActionListener
{
Image image, duckpic;
private Graphics gBuffer;
private Image Buffer;
DUCK1 duck1=null;
T2 t2=null;
public void init()
{
//create graphics buffer, the size of the applet
Buffer=createImage(600,400);
gBuffer=Buffer.getGraphics();
}
public void start()
{
duckpic=getImage(getDocumentBase(), "duckfamily.gif");
image=getImage(getDocumentBase(), "lake.jpg");
duck1=new DUCK1(this);
duck1.start();
resize(640,480);
repaint();
t2=new T2(this);
t2.start();
}
public void stop()
{
if(duck1!=null)
duck1.stop();
if(t2!=null)
t2.stop();
}
class DUCK1 extends Thread
{
duckShoot app;
int x;
//pass reference to Applet
DUCK1(duckShoot parent)
{
app=parent;
}
public void run()
{
//method loops forever if thread exsists, other processes can run aswell
while(true) {
if(x++>600)
x=0;
app.repaint();
try{Thread.sleep(10);}catch(InterruptedException e){}
}
}
}
class T2 extends Thread
{
duckShoot app;
int x;
//pass reference to Applet
T2(duckShoot parent)
{
app=parent;
}
public void run()
{
//method loops forever if thread exsists, other processes can run aswell
while(true) {
if(x++>600)
x=0;
app.repaint();
try{Thread.sleep(1);}catch(InterruptedException e){}
}
}
}
public void actionPerformed(ActionEvent e)
{
}
public void update(Graphics g)
{
paint(g);
}
public void paint(Graphics g)
{
g.drawImage(image, 0,0,this);
g.drawString("Score : ", 5, 20);
g.drawImage(duckpic,duck1.x, 300,this);
g.drawImage(duckpic,t2.x, 200, this);
}
}
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks