Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
   Home   Help   Search   Login   Register   
  Show Posts
Pages: [1]
1  Game Development / Performance Tuning / not enough time? on: 2002-12-24 21:22:02
hi i have a thread that paint and "does the mathematics" then it sleep for 40 ms!
now i have the problem that it doesn'T count any more!
it paints but doesn't move the components!to little time?
i don't know what to do!!heeelp!
here te code of the tread:



class CAlien extends Thread
{
   Canvas anzeige;
   int m_xPos,m_yPos;
   int m_xGo,m_yGo;//Schrittweite
   public CAlien(Canvas a,int x,int y){
       anzeige=a;
       m_xPos=x;
       m_yPos=y;
       m_xGo=7;
       m_yGo=13;
   }
   public CAlien(Canvas a){
   anzeige=a;
   double xtmp=(Math.random()*780)+10;
   double ytmp=(Math.random()*480)+10;
   m_xPos=(int)xtmp;
   m_yPos=(int)ytmp;
   }
   public void run(){
       bewegen();
       while(isInterrupted()==false){
       anzeigen();
       try
       {
           sleep(40);
       }
       catch(InterruptedException e){
       return;
       }
       }
   }
   void anzeigen(){
       Graphics g1=db.getGraphics();
       Graphics g=anzeige.getGraphics();
       g1.setFont(m_anzeiger);
       //g1.drawImage(m_bild,m_xPos,m_yPos,null);
       g1.setColor(Color.black);
       g1.fillOval(m_xPos+5,m_yPos+5,30,30);
       g1.setColor(Color.orange);
       g1.fillOval(m_xPos, m_yPos,30,30);
       g1.setColor(Color.black);
       g1.fillOval(m_xPos+9,m_yPos+6,3,3);
       g1.fillOval(m_xPos+17,m_yPos+6,3,3);
       g1.drawRect(m_xPos+7,m_yPos+18,16,4);
       g1.setColor(Color.black);
       g1.drawString(m_tref,350,470);
       g1.setColor(Color.black);
       g1.fillRect(zt.xPos+5,zt.yPos+5,zt.breite,zt.hohe);
       g1.setColor(Color.red);
       g1.fillRect(zt.xPos,zt.yPos,zt.breite,zt.hohe);
       g1.dispose();
       g.drawImage(db,0,0,null);
       g.dispose();
   }
   void bewegen(){
       int xNeu,yNeu;
       Graphics g=db.getGraphics();
       Dimension m=anzeige.getSize();
       xNeu=m_xPos+m_xGo;
       yNeu=m_yPos+m_yGo;
       if(xNeu<0){
           xNeu=0;
           double tmp=(Math.random()*15)+5;
           m_xGo=(int)tmp;
           m_treffer--;
       }
       if(xNeu+30 >=m.width){
           xNeu=m.width-30;
           double tmp=(Math.random()*15)+5;
           m_xGo=(int)-tmp;
           m_treffer--;
       }
       if(yNeu<0){
           yNeu=0;
           double tmp=(Math.random()*15)+5;
           m_yGo=(int)tmp;
           m_treffer--;
       }
       if(yNeu+30>=m.height){
           yNeu=m.height-30;
           double tmp=(Math.random()*15)+5;
           m_yGo=(int)-tmp;
           m_treffer--;
       }
       g.setColor(Color.gray);
       g.fillRect(m_xPos-1,m_yPos-1,m_xPos+37,m_yPos+37);
       g.fillRect(380,450,100,40);
       m_xPos=xNeu;
       m_yPos=yNeu;
       anzeigen();
       g.dispose();
   }
}
2  Game Development / Performance Tuning / Re: faster way to do that on: 2002-12-23 18:40:11
yeah!i've done it with dublebouffering!very cool!thank u 4 help!
3  Game Development / Performance Tuning / Re: faster way to do that on: 2002-12-23 17:27:08
now i have done the painting in one thread and the "mathematics" in two threads!
the flickering is better now!thanks!but what is double buffering?
4  Game Development / Performance Tuning / faster way to do that on: 2002-12-23 08:24:21
in advance:sorry for my bad english! Grin
what i have:
a canvas(800*500)
and two thread which do a lot of painting on this one canvas!
the one is leeping 50ms!
the faster 20ms!
both do their their own paiting!
it's flickering like mad you can imagine!
so what can i do to "get that flickering out of my canvas"?
5  Games Center / Archived Projects / how to speed up? on: 2002-12-23 07:42:31
i have thsis game:
http://www.fadi.at/6b/knoll/b.htm

and that's the code:
can u tell me how 2 speed up,cause it's damned flickering::

the code:::::::



/*
* CLoseShooter1.java
*
* Created on 21. Dezember 2002, 16:26
*/

/**
*
* @author  Johannes
*/
import java.awt.*;
import java.applet.*;
import java.awt.event.*;
import java.util.*;
import java.applet.Applet;
public class CLoseShooter2 extends Applet{
   int m_treffer,kaputt;
   Font m_anzeiger;
   String m_tref;
   Image m_bild;
   Canvas malFlaeche;
   Canvas oben,rechts,unten,links,stats;
   CAlien a;
   AudioClip ac;
   Zerstorer zt;
   public CLoseShooter2()
   {
       m_tref="";
       m_anzeiger=new Font("Arial",Font.BOLD,20);
       MediaTracker laden=new MediaTracker(this);
       try
       {
           ac=getAudioClip(getCodeBase(),"moan.wav");
           laden.waitForAll();
           ac.loop();
           
       }
       catch(Exception e){
       ;
       }
       
       //m_bild =getImage(getCodeBase(),"alienboese.gif");
       /*
       laden.addImage(m_bild,0);
       try
       {
           laden.waitForID(0);
       }
       catch(InterruptedException e){
           m_bild=null;
           return;
       }
       */
       kaputt=0;
       setLayout(new BorderLayout());
       m_treffer=0;
       oben=new Canvas();
       unten=new Canvas();
       rechts=new Canvas();
       links=new Canvas();
       stats=new Canvas();
       stats.setBackground(Color.yellow);
       oben.setBackground(Color.red);
       unten.setBackground(Color.red);
       links.setBackground(Color.red);
       rechts.setBackground(Color.red);
       stats.setSize(400,10);
       oben.setSize(800,10);
       unten.setSize(400,10);
       rechts.setSize(10,480);
       links.setSize(10,480);
       malFlaeche=new Canvas();
       malFlaeche.setBackground(Color.gray);
       malFlaeche.setForeground(Color.red);
       malFlaeche.setSize(780, 480);
       add("Center",malFlaeche);
       add("North",oben);
       add("East",rechts);
       add("West",links);
       add("South",unten);
       //add("South",stats);
       malFlaeche.addMouseListener(new CMaus());
     
   
   }
   public void init(){
   double tmp1=(Math.random()*780)+10;
   double tmp2=Math.random()*480+10;
   a=new CAlien(malFlaeche,(int) tmp1,(int)tmp2);
   a.start();
   m_treffer++;
   m_tref="Lose : "+String.valueOf(m_treffer);
   if(kaputt==1){
   zt.stop();
   }
   zt=new Zerstorer(malFlaeche);
   zt.start();
   }
   public void aufraumen(){
       Graphics g=malFlaeche.getGraphics();
       g.setColor(Color.gray);
       g.fillRect(a.m_xPos,a.m_yPos,37,37);
       g.fillRect(zt.xPos,zt.yPos,zt.breite+10,zt.hohe+10);
   }
  public void tststs()
  {
      zt.stop();
      init();
  }
   
class CMaus extends MouseAdapter
   {
       public void mousePressed(MouseEvent f){
           int ax=f.getX();
           int ay=f.getY();
           if(ax>=a.m_xPos && ax<=a.m_xPos+30){
               if(ay>=a.m_yPos && ay<=a.m_yPos+30){
                   aufraumen();
                   malFlaeche.setForeground(Color.green);
                   a.stop();
                   zt.stop();
                   init();
               }
           }
       }
   }
 
class CAlien extends Thread
{
   Canvas anzeige;
   int m_xPos,m_yPos;
   int m_xGo,m_yGo;//Schrittweite
   public CAlien(Canvas a,int x,int y){
       anzeige=a;
       m_xPos=x;
       m_yPos=y;
       m_xGo=7;
       m_yGo=13;
   }
   public CAlien(Canvas a){
   anzeige=a;
   double xtmp=(Math.random()*780)+10;
   double ytmp=(Math.random()*480)+10;
   m_xPos=(int)xtmp;
   m_yPos=(int)ytmp;
   }
   public void run(){
   anzeigen();
   while(isInterrupted()==false){
   bewegen();
   try
   {
   sleep(40);
   }
   catch(InterruptedException e){
   return;
   }
   }
   }
   void anzeigen(){
       
       Graphics g=anzeige.getGraphics();
       g.setFont(m_anzeiger);
       g.setColor(Color.black);
       g.fillOval(m_xPos+5,m_yPos+5,30,30);
       g.setColor(Color.orange);
       g.fillOval(m_xPos, m_yPos,30,30);
       g.setColor(Color.black);
       g.fillOval(m_xPos+9,m_yPos+6,3,3);
       g.fillOval(m_xPos+17,m_yPos+6,3,3);
       g.drawRect(m_xPos+7,m_yPos+18,16,4);
       g.setColor(Color.black);
       g.drawString(m_tref,350,470);
       g.setColor(Color.black);
       g.fillRect(zt.xPos+5,zt.yPos+5,zt.breite,zt.hohe);
       g.setColor(Color.red);
       g.fillRect(zt.xPos,zt.yPos,zt.breite,zt.hohe);
       g.dispose();
       
   }
   void bewegen(){
       int xNeu,yNeu;
       Graphics g=anzeige.getGraphics();
       Dimension m=anzeige.getSize();
       xNeu=m_xPos+m_xGo;
       yNeu=m_yPos+m_yGo;
       if(xNeu<0){
           xNeu=0;
           double tmp=(Math.random()*15)+5;
           m_xGo=(int)tmp;
       }
       if(xNeu+30 >=m.width){
           xNeu=m.width-30;
           double tmp=(Math.random()*15)+5;
           m_xGo=(int)-tmp;
       }
       if(yNeu<0){
           yNeu=0;
           double tmp=(Math.random()*15)+5;
           m_yGo=(int)tmp;
       }
       if(yNeu+30>=m.height){
           yNeu=m.height-30;
           double tmp=(Math.random()*15)+5;
           m_yGo=(int)-tmp;
       }
       g.setColor(Color.gray);
       g.fillRect(m_xPos-1,m_yPos-1,m_xPos+37,m_yPos+37);
       g.fillRect(380,450,100,40);
       m_xPos=xNeu;
       m_yPos=yNeu;
       anzeigen();
       g.dispose();
   }
}

class Zerstorer extends Thread
{
   Canvas zeichner;
   int xPos,yPos,breite,hohe,go;
   public Zerstorer(Canvas a){
   zeichner=a;
   xPos=250;
   yPos=250;
   hohe=10;
   breite=50;
   go=5;
   }
   void bewegen(){
       Graphics g=zeichner.getGraphics();
       Dimension m=zeichner.getSize();
       int xNeu;
       xNeu=xPos+go;
       if(xNeu<=0)
       {
           xNeu=0;
           go=-go;
       }
       if(xNeu+breite>=m.width){
           xNeu=m.width-breite;
           go=-go;
       }
       g.setColor(Color.gray);
       g.fillRect(xPos-5,yPos-5,breite+10,hohe+10);
       xPos=xNeu;
       g.dispose();
       if(a.m_xPos+35>=xPos && xPos>=a.m_xPos){
           if(a.m_yPos<=260 || a.m_yPos>220){    
           //m_treffer--;
           //a.stop();
           //aufraumen();
           //tststs();
           }
       }
   }
   public void run(){
       while(isInterrupted()==false){
       bewegen();
       breite+=1;
       try
       {
           sleep(50);
       }
       catch(InterruptedException e){
       ;
       }
       }
   
        }

        }
}


6  Java Game APIs & Engines / Java 2D / Re: display image in thread on: 2002-12-22 13:30:52
thanks!but now i have another problem!
how i can i load an ordinary .gif image with an applet?

the code  I got at forum.java.sun.com:

myImage =getImage(getCodebase(),"alien.gif");

but it doesn't work!
what the compiler tells me:


CLoseShooter1.java [30:1] cannot resolve symbol
symbol  : method getCodebase  ()
location: class CLoseShooter1
       m_bild =getImage(getCodebase(),"alien.gif");
7  Java Game APIs & Engines / Java 2D / display image in thread on: 2002-12-21 17:16:24
hi i want to draw an image in a thread that i have loaded in the mainprogramm!
with an applet:
g.draw_Image(myImage,xPos,yPos,?Huh)
and what to write instead of the ?"Huh"  Huh
Pages: [1]
 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (38 views)
2014-09-24 16:13:29

Pippogeek (29 views)
2014-09-24 16:12:22

Pippogeek (18 views)
2014-09-24 16:12:06

Grunnt (42 views)
2014-09-23 14:38:19

radar3301 (24 views)
2014-09-21 23:33:17

BurntPizza (61 views)
2014-09-21 02:42:18

BurntPizza (31 views)
2014-09-21 01:30:30

moogie (36 views)
2014-09-21 00:26:15

UprightPath (49 views)
2014-09-20 20:14:06

BurntPizza (53 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!