Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
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 / Newbie & Debugging Questions / Re: BufferStrategy - CPU Usage on: 2013-04-29 01:01:14
Ah yeah should have known that Tongue

Cheers for the code (nice way of doing it Smiley ) & info
2  Game Development / Newbie & Debugging Questions / Re: what is the correct method to loads images on: 2013-04-29 00:40:03
This should work, this will work if your using applet or not.

1  
2  
3  
4  
5  
6  
7  
8  
BufferedImage bImage;

try {
         URL url = this.getClass().getResource("graphics/hero.png");
         this.bImage = ImageIO.read(url);
      } catch (IOException e) {
         e.printStackTrace();
      }
3  Game Development / Newbie & Debugging Questions / Re: BufferStrategy - CPU Usage on: 2013-04-28 23:54:57
Yeah, i have a limit to FPS,
The commented code isn't really the problem i tested it out.
I've commented out each part to see what could be causing the issue and when i took away the BufferStrat it went down to 10-20%
4  Game Development / Newbie & Debugging Questions / BufferStrategy - CPU Usage on: 2013-04-28 23:32:26
Is there a less CPU intensive way to create a double buffer, bec just now when am doing it this way it takes up 50-60% of CPU without it, it's 10-20%.
I know i could use OpenGL or Slick etc.. but am trying to create this whole thing without any Libraries (except System Library).

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  
   public void draw() {
      if (this.getBufferStrategy() == null) {
         createBufferStrategy(2);
         return;
      }
     
      Graphics2D g = (Graphics2D) getBufferStrategy().getDrawGraphics();
      g.setColor(Color.BLACK);
      g.fillRect(0, 0, WIDTH+2, HEIGHT);
      g.setColor(Color.white);
      g.setFont(new Font("Serif", Font.PLAIN, 14));
      g.drawString("Ups: " + this.Ups , 4, 12);
      g.drawString("FPS: " + this.frameRate , 4, 24);
//      for(int i = 0; i < test.length; i++){
//         if(getCurrentState().toLowerCase().contains(test[i].getClass().getSimpleName().toLowerCase())){
//            try {
//               Method m = test[i].getClass().getDeclaredMethod("draw", Graphics2D.class);
//               m.invoke(test[i], g);
//            }catch (NoSuchMethodException | IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
//               System.out.println("graphics Error!");
//               System.out.println(e.toString());
//            }
//         }
//      }
     g.dispose();
      getBufferStrategy().show();
   }


Any information would be appreciated
Cheers
5  Discussions / General Discussions / Re: Is Java Missing its Window of Opportunity with Gaming? on: 2012-12-28 20:27:41
Don't really think java is missing its window with games because of they way the languages is it's self because its Easy to learn, easier to find solutions to your problems, Easy to show of your programs. So in my opinion people are finding their way to us with just finding someone with the same issues.

I've programmed a game in c++ and trying to get some help with something is a lot more difficult, which in my opinion that is going in the wrong direction things should be getting easier not harder. I know they are library's etc but they are still a lot more to when your just wanting to put something online or trying to find a fix for a problem you have been getting with the your code.

I also think it counts on developers showing off good quality programs that interest people and make people wondering how it was done.

Bit of a noobie but that's my thoughts Smiley
6  Game Development / Newbie & Debugging Questions / Re: Applet with lwjgl & slick on: 2012-08-09 22:37:45
I got it working, i think it was because i never took lwjgl.jar & lwjgl_util_applet.jar out of the applet version Tongue... finally got it working only took 2 days  Roll Eyes

Thanks for your help really appreciate it Smiley
7  Game Development / Newbie & Debugging Questions / Re: Applet with lwjgl & slick on: 2012-08-09 18:17:03
am using the lastest version of lwjgl, just double checked there by download them... still the same error Sad
8  Game Development / Newbie & Debugging Questions / Re: Applet with lwjgl & slick on: 2012-08-09 17:53:51
This occurred while 'Extracting downloaded packages'
error in opening zip file
java.util.zip.ZipException: error in opening zip file
   at java.util.zip.ZipFile.open(Native Method)
   at java.util.zip.ZipFile.<init>(Unknown Source)
   at java.util.zip.ZipFile.<init>(Unknown Source)
   at java.util.jar.JarFile.<init>(Unknown Source)
   at java.util.jar.JarFile.<init>(Unknown Source)
   at org.lwjgl.util.applet.AppletLoader.extractNatives(AppletLoader.java:1789)
   at org.lwjgl.util.applet.AppletLoader.run(AppletLoader.java:877)
   at java.lang.Thread.run(Unknown Source)

9  Game Development / Newbie & Debugging Questions / Applet with lwjgl & slick on: 2012-08-09 15:49:47
Hey am trying to learn how applets work with lwjgl & slick, but i can't seem to get it working... Here are the steps i take -

  • Export Game as "JAR file"
  • get - slick.jar, lwjgl.jar, natives-win.jar & lwjgl_util_applet.jar... i put it on my desk top
  • then i create a html file (notepad) the put the code it it.

this is the code i have in my html file -

<html>
<head>
<title>Applet Test</title>
</head>
<body bgcolor = "#222222">
<br><p>
<br><p>
<center>
<applet code="org.lwjgl.util.applet.AppletLoader"
        archive="lwjgl_util_applet.jar"
        codebase="."
        width="800" height="600">
 
  <param name="al_title" value="myslickgame">
  <param name="al_main" value="org.newdawn.slick.AppletGameContainer">
  <param name="game" value="Display">
 
  <param name="al_jars" value="Animation.jar, lwjgl.jar, slick.jar">
 
  <param name="al_windows" value="natives-win.jar">
</applet>
</center>
</body>
</html>


my game code -

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  
import org.newdawn.slick.AppGameContainer;
import org.newdawn.slick.BasicGame;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

public class Display extends BasicGame {
   public static void main(String[] args){
      try{
      AppGameContainer app = new AppGameContainer(new Display());
      app.setDisplayMode(800, 600, false);
      app.start();
      }catch (SlickException e){ e.printStackTrace(); }
   }

   public Display() {
      super("Applet Game");
   }

   @Override
   public void render(GameContainer gc, Graphics g) throws SlickException {
      g.setColor(Color.white);
      g.fillOval(150, 150, 50, 50, 5);
   }

   @Override
   public void init(GameContainer gc) throws SlickException {
      // TODO Auto-generated method stub

   }

   @Override
   public void update(GameContainer gc, int delta) throws SlickException {
      // TODO Auto-generated method stub

   }

}


Error 'extracting downloaded packages'
Am not using any images in my code just appGameContainer using the Graphics to create an filloval

Cheers for taking a look Smiley
10  Discussions / Miscellaneous Topics / Re: Who would you consider a programmer? on: 2012-08-01 23:02:07
Am pretty sure we all know the biggest secret of knowing who's a programmer...


Having a beard or long hair... Or both & if not that cloths that just say "meh".
But yeah if not they things I think you can tell if you start having a conversation about programming what tools, engine you use etc. Smiley
11  Java Game APIs & Engines / Java 2D / Re: Sprite Animation on: 2012-07-30 22:14:46
Here is the main parts of my animation which i use to add the animation & get all the information i need to get it working. -

Animation 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  
public BufferedImage sprite;
   private ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
   private boolean running = false;
   private long previousTime, speed;
   private int frameAtPause, currentFrame;

   public void update(long time) {
      if (running) {
         if (time - previousTime >= speed) {
            currentFrame++;
            if (currentFrame < frames.size()) {
               sprite = frames.get(currentFrame);
            } else {
               currentFrame = 0;
               sprite = frames.get(currentFrame);
            }
            previousTime = time;
         }
      }
   }

   public Animation(ArrayList<BufferedImage> frames) {
      this.frames = frames;
   }

   public void setSpeed(long speed) {
      this.speed = speed;
   }

   public void play() {
      running = true;
      previousTime = 0;
      frameAtPause = 0;
      currentFrame = 0;
   }

   public void stop() {
      running = false;
      previousTime = 0;
      frameAtPause = 0;
      currentFrame = 0;
   }

   public void pause() {
      frameAtPause = currentFrame;
      running = false;
   }

   public void resume() {
      currentFrame = frameAtPause;
      running = true;
   }
}



BufferedImageLoader Class -
1  
2  
3  
4  
5  
public BufferedImage loadImage(String pathRelativeToThis) throws IOException {
      URL url = this.getClass().getResource(pathRelativeToThis);
      BufferedImage img = ImageIO.read(url);
      return img;
   }


SpriteSheet -

   
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
public BufferedImage spriteSheet;
   
   public SpriteSheet(BufferedImage ss){
      this.spriteSheet = ss;
   }
   
   public BufferedImage grabSprite(int x, int y, int width, int height){
      BufferedImage sprite = spriteSheet.getSubimage(x,  y,  width,  height);
      return sprite;
   }


cheers for taking the time to look Smiley
12  Java Game APIs & Engines / Java 2D / Re: Sprite Animation on: 2012-07-30 21:34:09
This is how my current code works:

I have a screen manager & a display you input the display that you want to show, so it updates from the display from the screen manager here is the code:

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
private void render() {
      BufferStrategy bs = getBufferStrategy();

      if (bs == null) {
         createBufferStrategy(2);
         return;
      }

      Graphics g = bs.getDrawGraphics();
      g.fillRect(0, 0, frame.getWidth(), frame.getHeight());
      screen.paintStage(g);
      screen.updateStage(this);
      g.dispose();
      bs.show();
   }


1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
public void paintStage(Graphics g){
      if(currentState == Stage1Name){
         Stage1.paint(g);
      }
   }
   
   public void updateStage(Display display){
      if(currentState == Stage1Name){
         Stage1.update(display);
      }
   }


& i have an ArrayList for BufferedImage this is getting the current image really. -


   
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
public BufferedImage sprite;
   private ArrayList<BufferedImage> frames = new ArrayList<BufferedImage>();
   private boolean running = false;
   private long previousTime, speed;
   private int frameAtPause, currentFrame;

   public void update(long time) {
      if (running) {
         if (time - previousTime >= speed) {
            currentFrame++;
            if (currentFrame < frames.size()) {
               sprite = frames.get(currentFrame);
            } else {
               currentFrame = 0;
               sprite = frames.get(currentFrame);
            }
            previousTime = time;
         }
      }
   }



I know this is "sprite = frames.get(currentFrame);" the problem because when i comment it out it goes from 90 odd fps to 1000 odd fps.
Thanks taking the time to look Smiley
13  Java Game APIs & Engines / Java 2D / Sprite Animation on: 2012-07-30 19:10:42
Hey ive been doing some tutorials for Sprite Animation, & i have made an animation but my fps goes down really low & it just slows down the program in general.
I first thought it was BufferedImage but change it but still made no no difference. I'll post the main part that is making it lag so much (its updating each image).

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
//Updating the animation image
public void update(long time) {
      if (running) {
         if (time - previousTime >= speed) {
            currentFrame++;
            if (currentFrame < frames.size()) {
               sprite = frames.get(currentFrame); <<< main part of the lag
            } else {
               currentFrame = 0;
               sprite = frames.get(currentFrame);
            }
            previousTime = time;
         }
      }
   }

//updating the animation on screen
public void update(Display display) {
         animation.update(System.currentTimeMillis());
     
   }


Thanks for taking a look Smiley

14  Game Development / Newbie & Debugging Questions / Re: Oval Collision on: 2012-07-27 23:42:23
bump
15  Game Development / Newbie & Debugging Questions / Oval Collision on: 2012-07-27 22:13:13
Hey am trying to find different ways to get hit detection but finding it hard to figure out how to get it with an oval here is what i have just now,
 wondering if they are a similar way to do this -

public cpuMovement(int x, int y, int width, int height){
   this.x = x;
   this.y = y;
   this.width = width;
   this.height = height;
   this.rect = new Rectangle(x, y, width, height);
}

public static void Collision(cpuMovement cm){
      for (int i = 0; i < Physics.cpuMove.size(); i++) {
         if(Physics.cpuMove.get(i).getRect().intersects(cm.getRect())){
            if(Physics.cpuMove.get(i) != cm){
               System.out.println("Working");
      }
   }
}
}

The top bit of code is working but how would i get an oval hit detection
Cheers for your time Smiley


Pages: [1]
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Get high quality music tracks for your game!

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

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (88 views)
2013-05-17 21:29:12

alaslipknot (96 views)
2013-05-16 21:24:48

gouessej (128 views)
2013-05-16 00:53:38

gouessej (123 views)
2013-05-16 00:17:58

theagentd (131 views)
2013-05-15 15:01:13

theagentd (119 views)
2013-05-15 15:00:54

StreetDoggy (161 views)
2013-05-14 15:56:26

kutucuk (184 views)
2013-05-12 17:10:36

kutucuk (185 views)
2013-05-12 15:36:09

UnluckyDevil (191 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
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!
Page created in 0.225 seconds with 21 queries.