Java game design question (graphical objects)
Posted
by
vemalsar
on Game Development
See other posts from Game Development
or by vemalsar
Published on 2011-02-09T17:21:58Z
Indexed on
2011/02/09
23:35 UTC
Read the original article
Hit count: 237
architecture
|java
Hello Guys,
I'm beginner in game development, in Java and here on this site too and I have a game design question. Please comment my idea:
I have a main loop which call update and draw method. I want to use an ArrayList which store graphical objects, they have coordinate and image or text to draw and my game objects extends this class. In update, I can choose which objects should be put in the array and in draw method I'll display the elements of array on the screen. I'm using a buffer and draw first there, but it is not important now I guess...Here is a simple (not full) code, only the logic:
public class GamePanel extends JPanel implements KeyListener
{
ArrayList<graphicalObjects> graphArray = new ArrayList<graphicalObjects>();
public void update()
{
//change the game scene, update the graphArray, process input etc.
}
public void draw()
{
//draws every element of graphArray to a JPanel
}
public static main(String[] args)
{
while(true)
{
update();
draw();
}
}
}
My questions:
Should have I use interface or abstract class for graphicalObjects? graphicalObjects class and the ArrayList really needs or there is some better solution?
How to draw objects? They draw themself with their own method or in the draw method I have to draw manually based on graphicalObjects variables (x,y coordinates, image etc.)?
If this conception is wrong, please suggest another one!
All comments are welcome and sorry if this is dumb question, thanks!
© Game Development or respective owner