Java-Gaming.org Hi !
Featured games (83)
games approved by the League of Dukes
Games in Showcase (522)
Games in Android Showcase (127)
games submitted by our members
Games in WIP (590)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Need advice on Active Rendering. Please help  (Read 1717 times)
0 Members and 1 Guest are viewing this topic.
Offline pars

Senior Newbie




Java games rock!


« Posted 2003-01-16 08:34:22 »

I dont have that much experience in Java, and only a few days ago I realised that I need to use Active rendering instead of passive rendering for my pacman game. The game runs fine when I run it on my own PC (P4 2Ghz 512 ram) and I get around 33 fps.  But if I run it on computers with lower specs (below 1Ghz) the game runs really slow (about 17 fps). I know this could be because of passive rendering since pacman is not really a processor hungry application to use all of the system's recources.

The problem is I can't really find much information on active rendering (except the article on Sun's website). Could you point my to some tutorials or examples on active rendering. (or if you could give me some guidelines)

Thanx
Offline Herkules

Senior Devvie




Friendly fire isn't friendly!


« Reply #1 - Posted 2003-01-16 08:50:39 »

It's not clear what your problem is. But obviously you have one. Pacman should easily perform with 500fps on a modern box, even with Java.

Have you looked into the demos around?

HARDCODE    --     DRTS/FlyingGuns/JPilot/JXInput  --    skype me: joerg.plewe
Offline pars

Senior Newbie




Java games rock!


« Reply #2 - Posted 2003-01-16 11:37:37 »

Well the problem is that in my game, almost all the logic is performed in the paint/paintComponent method.  From what I read in Sun's website, this is passive rendering and is not really good idea to use for a game.  

But the problem is I have not been able to find much information and tutorials about active rendering.  So I don't exactly know how to use it for my game.


>Pacman should easily perform with 500fps on a
modern box, even with Java.


500 fps, wow!!!!  and I thought getting 33 fps is ideal.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline erikd

JGO Ninja


Medals: 16
Projects: 4
Exp: 14 years


Maximumisness


« Reply #3 - Posted 2003-01-16 11:52:05 »

Quote

>Pacman should easily perform with 500fps on a  
modern box, even with Java.

500 fps, wow!!!!  and I thought getting 33 fps is ideal.


<brag>I got an emulated pacman running at 60fps on a 266Mhz laptop once  Cool </brag>

For a simple active rendering example, look into http://java.sun.com/docs/books/tutorial/extra/fullscreen/example-1dot4/MultiBufferTest.java
and replace the painting of the colored background (lines 43 and 44) with your own code.

But maybe you have another problem. Profile your code with the -Xprof switch.

Greetings,
Erik

Offline markuskidd

Junior Devvie


Medals: 1



« Reply #4 - Posted 2003-01-16 11:54:41 »

The first step you need to do is to call setIgnoreRepaint(true) on your main frame. From then on, you know that when you're seeing something on the screen, you're active rendering Cheesy

One straightforward way (untested, but should work) of getting some active rendering would be to put this in your run loop of the main frame...

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
public void run() {
    while(true) {
        if(buffer == null) {
            buffer = new Image(640, 480); // where this number is the size of your window - Insets
            continue;
       }
       Graphics bufferG = buffer.getGraphics();
       getContentPane().paintComponent(bufferG);
       getContentPane().paintChildren(bufferG);
       getContentPane().getGraphics().paint(buffer, getInsets().left, getInsets().top);
    }
}

private Image buffer;
Offline pars

Senior Newbie




Java games rock!


« Reply #5 - Posted 2003-01-16 16:43:26 »

I have spent the past week trying to convert my code but without success.   To be honest, I don't have that much experience in java, and this thing is giving me a headache.  I am totally confused.

below is a simple animation code in passive rendering (similar to the code that I use in my game). Can you please help me to convert it to active rendering.  If you have the time to help me with this, then I am sure I will be able to do it for the rest of my game.  I hope I'm not asking for too much.

Thanx

The below code uses 7 GIF images for pacman animation.
-----------------------------------
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  
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class PacmanM extends JPanel implements ActionListener
{
      private ImageIcon images[];
      private static final int TOTAL_IMAGES=7, ANIM_DELAY=50;
      private int currentImage = 0;
      private Timer animationTimer;
      private int delay = 0;

      public PacmanM(int delay)
      {
            this.delay = delay;
            setupAnimation();
           
      }
     
      public PacmanM()
      {
            setupAnimation();
      }
     
      public void setupAnimation()
      {
            this.setSize(this.getPreferredSize());
            this.images = new ImageIcon[TOTAL_IMAGES];
           

            for (int i = 0; i < images.length; i++)
            {
                  images[i] = new ImageIcon("pac"+i+".gif");
            }
            startAnimation();
      }
     
      public void paintComponent(Graphics g)
      {
            super.paintComponent(g);
            g.setColor(Color.blue);
            g.fillRect(0,0,this.getWidth(), this.getHeight());
            if (images[currentImage].getImageLoadStatus() == MediaTracker.COMPLETE)
            {  
                  images[currentImage].paintIcon(this, g, 0, 0);
                  currentImage = (++currentImage) % TOTAL_IMAGES;
            }      
      }
     
      public void startAnimation()
      {
            if (animationTimer == null)
            {
                  currentImage = 0;
                  animationTimer = new Timer( ANIM_DELAY + delay, this);
                  animationTimer.start();
            }
            else
            {
                  if (!animationTimer.isRunning())
                  animationTimer.restart();
            }
      }
     
      public void stopAnimation (){ animationTimer.stop(); }
      public void actionPerformed(ActionEvent e){ repaint(); }
      public Dimension getMinimumSize() { return getPreferredSize(); }
      public Dimension getPreferredSize (){return new Dimension(400,400);}
     
      public static void main(String[] args )
      {
            PacmanM PacMan = new PacmanM();
            JFrame main = new JFrame("PacMan");
            main.getContentPane().add(PacMan, BorderLayout.CENTER);
           
            main.addWindowListener(new WindowAdapter()
            {
                  public void windowClosing(WindowEvent e)
                  {
                        System.exit(0);
                  }
            });
                  main.pack();
                  main.show();
      }    
}
Offline pars

Senior Newbie




Java games rock!


« Reply #6 - Posted 2003-01-27 17:09:18 »

anyone?
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

trollwarrior1 (29 views)
2014-11-22 12:13:56

xFryIx (71 views)
2014-11-13 12:34:49

digdugdiggy (50 views)
2014-11-12 21:11:50

digdugdiggy (44 views)
2014-11-12 21:10:15

digdugdiggy (38 views)
2014-11-12 21:09:33

kovacsa (62 views)
2014-11-07 19:57:14

TehJavaDev (67 views)
2014-11-03 22:04:50

BurntPizza (64 views)
2014-11-03 18:54:52

moogie (80 views)
2014-11-03 06:22:04

CopyableCougar4 (80 views)
2014-11-01 23:36:41
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!