Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (121)
games submitted by our members
Games in WIP (577)
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 / Shared Code / Re: problem in array of objects on: 2005-04-15 17:24:53
oke thanks stupid i didnt think of that earlier  Embarrassed
2  Game Development / Performance Tuning / Re: Calculating the FPS on a simple game on: 2005-04-12 11:11:44
by the way i tried both in my game and the results were like this
threaded fpscounter result : 120-140
role fpscounter result : 130 - 150
3  Game Development / Performance Tuning / Re: Calculating the FPS on a simple game on: 2005-04-12 10:57:09
i do my fps calculating this way

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public class FPSCounter implements Runnable{
      protected int fps = 0, fpscounter = 0;
      Thread proces = new Thread(this);
      public FPSCounter(){
            proces.start();
      }
      public void run(){
            while(true){
                  try{Thread.sleep(1000);}catch(InterruptedException ie){}
                  fps = fpscounter;
                  fpscounter = 0;
            }
      }
     
      public void addFPS(){
            fpscounter++;
      }
      public int getFPS(){
            return fps;
      }
}


and then i implement it this way

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
public class game{
    FPSCounter fps
    int intfps= 0; //initially start with 0

    game(){
        fps = new FPScounter;
    }

    renderloop(){
        while(true){
             intfps = fps.getFPS();
             ---->startrendering
              renderstring(intfps" fps");//draw a string in the topleft corner
             ----> end of rendering
             fps.addFPS()
        }
    }



}


i have read once that the sleep waits at least the given time but sometimes it waits a little longer is this true?

what would you think of this or is it too inefficent or inaccurate?
4  Game Development / Shared Code / problem in array of objects on: 2005-04-12 10:45:44
in my game i create an array of objects (one for npc one for static objects) when i load for example 5 npc's in the array i can draw all of them in a loop like
1  
2  
3  
for(int = i;i<npcarraay.length;i++){
     g.drawnpc(npcarray[i].getpos());//getpos is a function from the object npc to retrive the position i use setpos to set the position and the getpos returns an int[]
}


but when i try to fill the array the position from all npc objects in the array have the same position as the last npc i added here is the code for the npc class

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
import java.io.*;
import java.lang.*;

public class NPC implements Serializable, Runnable{
      Thread tProces = new Thread(this);
      protected int iLvl;
      public boolean death = false;
      protected String sName;
      protected int[] iPos;
      protected Boolean bSolid = true;
     
      public NPC(int _iLvl){
            sName = "";
            iPos = new int[]{0,0};
            iLvl = _iLvl;
            tProces.start();
      }
     
      public NPC(String _sName, int _iLvl){
            sName = _sName;
            iPos = new int[]{0,0};
            iLvl = _iLvl;
            tProces.start();
      }
     
      public NPC(int[] _iPos, int _iLvl){
            sName = "";
            iPos = _iPos;
            iLvl = _iLvl;
            tProces.start();
      }
     
      public NPC(String _sName, int[] _iPos, int _iLvl){
            sName = _sName;
            iPos = _iPos;
            iLvl = _iLvl;
            tProces.start();
      }
     
      public void run(){
            while(true){
                  try{Thread.sleep(1000);}catch(InterruptedException ie){}
                  Wander();
            }
      }
     
      public String getName(){return sName;}
      public int[] getPos(){return iPos;}
      public Boolean isSolid(){return bSolid;}
     
      public void setName(String _sName){
            sName = _sName;
      }
      public void setPos(int[] _iPos){
            iPos = _iPos;
      }
     
     
      public void walkN(){
            for(int i = 0; i < 10; i++){
                  iPos[1] -=1;
                  try{Thread.sleep(100);}catch(InterruptedException ie){}
            }
      }
     
      public void walkO(){
            for(int i = 0; i < 10; i++){
                  iPos[0] +=1;
                  try{Thread.sleep(100);}catch(InterruptedException ie){}
            }
      }
     
      public void walkZ(){
            for(int i = 0; i < 10; i++){
                  iPos[1] +=1;
                  try{Thread.sleep(100);}catch(InterruptedException ie){}
            }
      }
     
      public void walkW(){
            for(int i = 0; i < 10; i++){
                  iPos[0] -=1;
                  try{Thread.sleep(100);}catch(InterruptedException ie){}
            }
      }
     
      public void Wander(){
            int calc = (int) (Math.random()*4)+1;
            switch(calc){
                  case 1:walkO();
                  break;
                  case 2:walkW();
                  break;
                  case 3:walkZ();
                  break;
                  case 4:walkN();
                  break;
            }
      }
}
5  Java Game APIs & Engines / Java 2D / Re: any ideas on RPG map scrolling? on: 2005-04-12 07:17:44
this is how i do this issue in the constructor i give all the currents objects in the world(im going to work on it to only give all obvjects in an given area) but then at drawing time ((i use a volatileimage for double buffering thats hardware accelerated) i ignore all objects that are out of the field and draw the rest to the volatile image my player is always in the middle the player has coordinates in the world and everything else is drawn relative to the player (player is drawn at 300,300 on the canvas but in the world hes at 0,0 when an object is in the world is -40,40 its drawn at 260,340 and if hes in the world at 318,48 its not drawn bceause its too far away. i tested it with over a million random object within an area of 500000 pixels(it was drawing like 1000 objects on the screen and it ran pretty smooth)

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
63  
64  
65  
66  
67  
68  
69  
70  
71  
72  
73  
74  
75  
76  
77  
78  
79  
80  
81  
82  
83  
84  
85  
86  
87  
88  
89  
90  
91  
92  
93  
94  
95  
96  
97  
98  
99  
100  
101  
102  
103  
104  
105  
106  
107  
108  
109  
110  
111  
112  
package lima.Games.GUI;

import java.awt.*;
import java.awt.event.*;
import java.util.*;
import lima.Games.objects.*;
import java.awt.image.VolatileImage;

public class DrawArea extends Canvas{
     
      int i = 0,fps = 0;
     
      private Players player;
      private NPC[] npc;
      private StaticObjects[] sobject;

      private VolatileImage volatileImg;
      int[] playerpos;
     
      public DrawArea(Players player, NPC[] npc, StaticObjects[] sobject){

            this.player = player;
            this.npc = npc;
            this.sobject = sobject;
            setSize(600,600);
           
           
      }

      public void paint(Graphics g){

            createBackBuffer();

              do {//creating the buffer and draw everything if there is some kind of problem and the image is lost do it again

                    GraphicsConfiguration gc = this.getGraphicsConfiguration();

                  int valCode = volatileImg.validate(gc);
                  if(valCode==VolatileImage.IMAGE_INCOMPATIBLE){
                  createBackBuffer(); // recreate the hardware accelerated image.

            }

            Graphics offscreenGraphics = volatileImg.getGraphics();
            //offscreenGraphics
            offscreenGraphics.clearRect(0,0,600,600); //clear  the offscreen image

            offscreenGraphics.drawString(fps+" fps", 20, 20);

            offscreenGraphics.drawString(player.getPos()[0]+","+player.getPos()[1]+": "+player.getName(),(300)-10,(300)+20);
            offscreenGraphics.drawRect((300)-10,(300)-10,20,20, true);


            for(int i = 1; i < npc.length; i++){

                  if(getX(npc[i])-10 < 0 || getY(npc[i])-10 < 0){//if the x or y is to far to the west or north dont draw it
                  }else if(getX(npc[i])+10 > 600 || getY(npc[i])+10 > 600){//same goes for here but then for east and south
                  }else{

                        offscreenGraphics.drawString(npc[i].getPos()[0]+","+npc[i].getPos()[1]+": "+npc[i].getName(),getX(npc[i])-10,getY(npc[i])+20);
                        offscreenGraphics.drawRect(getX(npc[i])-10,getY(npc[i])-10,20,20,true);
                  }
            }


            for(int i = 1; i < sobject.length; i++){
                  if(getX(sobject[i])-10 < 0 || getY(sobject[i])-10 < 0){
                  }else if(getX(sobject[i])+10 > 600 || getY(sobject[i])+10 > 600){
                  }else{

                        offscreenGraphics.drawString(sobject[i].getPos()[0]+","+sobject[i].getPos()[1]+": "+sobject[i].getName(),getX(sobject[i])-10,getY(sobject[i])+20);
                        offscreenGraphics.drawRect(getX(sobject[i])-10,getY(sobject[i])-10,20,20,true);
                  }
            }

            g.drawImage(volatileImg,0,0,this);
            } while(volatileImg.contentsLost());
      }
     
      public void Update(Players player, NPC[] npc, StaticObjects[] sobject, int fps){

            this.player = player;
            this.npc = npc;
            this.sobject = sobject;
            this.fps = fps;
            repaint();
      }
     
      public void update(Graphics g)
    {
            paint(g);
    }
     
      private void createBackBuffer() {
            GraphicsConfiguration gc = getGraphicsConfiguration();
            volatileImg = gc.createCompatibleVolatileImage(getWidth(), getHeight());
      }
     
      public int getX(Objects thing){//this retrieves the x coordinates to draw the object relative to the player
            int thisx = thing.getPos()[0];
            thisx = thisx - player.getPos()[0];
            thisx = 300+thisx;
            return thisx;
      }
     
      public int getY(Objects thing){//sme as getX but then for the y coordinates
            int thisy = thing.getPos()[1];
            thisy = thisy - player.getPos()[1];
            thisy = 300+thisy;
            return thisy;
      }
}
6  Game Development / Shared Code / Re: Java 3D Games Programming Chapters online on: 2005-04-11 17:23:08
great book thanks for all the info i'm currently working on a mmorpg i was doing well with the rpg part but the networking and 3d where of great help (im doing 2d my own way ill distribute it when its a little more flawless).
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.

theagentd (20 views)
2014-10-25 15:46:29

Longarmx (53 views)
2014-10-17 03:59:02

Norakomi (47 views)
2014-10-16 15:22:06

Norakomi (35 views)
2014-10-16 15:20:20

lcass (39 views)
2014-10-15 16:18:58

TehJavaDev (69 views)
2014-10-14 00:39:48

TehJavaDev (69 views)
2014-10-14 00:35:47

TehJavaDev (61 views)
2014-10-14 00:32:37

BurntPizza (74 views)
2014-10-11 23:24:42

BurntPizza (46 views)
2014-10-11 23:10:45
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

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
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!