Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (768)
Games in Android Showcase (230)
games submitted by our members
Games in WIP (854)
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  
  More advanced method of rendering  (Read 1775 times)
0 Members and 1 Guest are viewing this topic.
Offline StonePickaxes

JGO Coder


Medals: 5
Projects: 2


Nathan Kramber


« Posted 2012-02-29 00:41:37 »

So, up until this point, I have been doing my rendering the good old fashioned way: simply using g.drawImage(img, x, y, null);

I was thinking, and this seems like a very inefficient way to do it. I remember watching Notch's Minicraft livestream and him using an array called pixels[] and I THINK he was just adding pixels or whatever to that array, and rendering that.

My main problem with the g.drawImage way is the extra code it takes whenever I add a new entity to render. For example, when I add a new class that needs rendering, I make the class with a render method

1  
2  
3  
4  
public void render(Graphics g) 
   {
      g.drawImage(main.spritesheet.sprites[67], x, y, null);
   }


then I add the object to my main class and do this for my main rendering

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
public void renderUpdates()
   {
      if (state.equals("menumain")) menumain.render(g);
      if (state.equals("playing"))
      {
         for (Wall wall : wallList) wall.render(g);
         for (Pellet pellet : pelletList) pellet.render(g);
         
         ghosts.render(g);
         player.render(g);
      }
   }


the renderUpdates method is called from within my render method.

So, my question: Are there any established tutorial sets out there that demonstrate a more efficient method? It's hard trying to learn from the livestream, because nothing is explained. If not, what are your methods for doing it? Do I just need to start using a library like Slick2D or LWGJL?

Thanks a bunch,
-Nathan

Check out my website!
Offline ra4king

JGO Kernel


Medals: 508
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-02-29 03:38:47 »

There's nothing inefficient about using g.drawImage(image,x,y,null); at all, unless the image is HUGE. Just remember to not modify its internal data buffer and it will be optimized as much as possible by Java2D. Slick2D and LWJGL allow you to access OpenGL, which will cause your games to run MUCH faster but for now if you're still a beginner in game design, I recommend you stick with Java2D.

Offline StonePickaxes

JGO Coder


Medals: 5
Projects: 2


Nathan Kramber


« Reply #2 - Posted 2012-03-01 01:41:45 »

My problem isn't with efficiency, it's with the time it takes to add the new class to renderUpdates(), then write the render method for EVERY class.

I'm sure it doesn't work like that with a professional game, where hundreds or thousands of things are rendered every frame.

Does anyone know how Notch does that with the pixels[] array? If anything, I'd just like to know how it's done.

-Nathan

Check out my website!
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline Geemili

Senior Devvie


Medals: 9
Projects: 1
Exp: 2 years


No Games Finished


« Reply #3 - Posted 2012-03-01 02:42:25 »

I would just make a class called 'entity', or something like that. Then, each time you have a new 'entity' you want to render, you just add it to an ArrayList. Each time render is called, you loop through that ArrayList and call their render statement.
Pages: [1]
  ignore  |  Print  
 
 

 
EgonOlsen (1329 views)
2018-06-10 19:43:48

EgonOlsen (1206 views)
2018-06-10 19:43:44

EgonOlsen (931 views)
2018-06-10 19:43:20

DesertCoockie (1372 views)
2018-05-13 18:23:11

nelsongames (1111 views)
2018-04-24 18:15:36

nelsongames (1359 views)
2018-04-24 18:14:32

ivj94 (2094 views)
2018-03-24 14:47:39

ivj94 (1251 views)
2018-03-24 14:46:31

ivj94 (2250 views)
2018-03-24 14:43:53

Solater (804 views)
2018-03-17 05:04:08
Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08

Deployment and Packaging
by gouessej
2018-08-22 08:03:45

Deployment and Packaging
by philfrei
2018-08-20 02:33:38

Deployment and Packaging
by philfrei
2018-08-20 02:29:55

Deployment and Packaging
by philfrei
2018-08-19 23:56:20

Deployment and Packaging
by philfrei
2018-08-19 23:54:46
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!