Overriding paintComponent(); Drawing multiple buffered images - java

I'm trying to make a tower defense game. So far I've made the JFrame (called GameFrame) where everything is displayed, added a background image (.PNG) and I'm trying to create the monsters and make them "move" over the path I've created. So, I created a GlassPane class which I set as glassPane in the GameFrame.
Here is the code for the GlassPane:
public class GlassPane extends JComponent implements ActionListener{
private ArrayList<MyPoint> path; //list of Points-pixel positions- (x,y pair) that monsters will follow
private ArrayList<Monster> wave; //list of monsters that will try to reach the rift
private Timer timer; //javax.swing.Timer
private boolean waveEnd;//signing that the wave has ended(ignore it)
public GlassPane(){
super();
createPath();//method is below
wave = new ArrayList<Monster>();//monsters added in nextWave()
timer = new Timer(4,this);//timer in order to slow down and smooth the movement of monsters
waveEnd = false;
}
#Override
protected void paintComponent(Graphics g){
super.paintComponent(g);
for(Monster m:wave){
if(m.isVisible())//visible is a private variable in Monster class(defines whether i want to paint that monster or not)
{
g.drawImage(m.getImage(), m.getX(), m.getY(), this);
}
}
}
public void nextWave(){
waveEnd = false;
for(int i =0;i<20;i++)
wave.add(new Monster());
wave.get(0).setVisible(true);//sets the first monster to be visible(paintable)
int visibles = 1;//index 0 is visible,so index 1 is next to become visible
while(!waveEnd){
if(visibles<19 && wave.get(0).getPathIndex()%50 == 0){
//meaning until all 20 monsters are visible(indexes 0-19),"every 50 steps(pixels) the first monster moves"
wave.get(visibles).setVisible(true);
//make another monster visible and start moving it
visibles++;//visible(moving) monsters increased by 1
timer.start();//"move all visible monsters one step forward with a small delay until the next movement to make it soft"
}
JOptionPane.showMessageDialog(new JFrame(), "Finished!","All monsters reached the rift!",JOptionPane.INFORMATION_MESSAGE);//let me know then wave is finished
}
private void createPath(){
//just making a lsit of pixels that I want monsters to follow
path = new ArrayList<MyPoint>();
for(int x=0;x<175;x++){
path.add(new MyPoint(x,0));
}
for(int y=0;y<175;y++){
path.add(new MyPoint(174,y));
}
for(int x=175;x<325;x++){
path.add(new MyPoint(x,174));
}
for(int y=175;y<425;y++){
path.add(new MyPoint(299,y));
}
for(int x=325;x<575;x++){
path.add(new MyPoint(x,424));
}
for(int y=424;y>175;y--){
path.add(new MyPoint(574,y));
}
for(int x=575;x<1001;x++){
path.add(new MyPoint(x,174));
}
}
#Override
public void actionPerformed(ActionEvent arg0) {
for(Monster m:wave)
if(m.isVisible())
m.move(path);
//"move every visible monster by one step"
if(m.get(19).getPathIndex() == 1674)//1674 is the path's last index
waveEnd = true;//if the last monster reaches the end,then all have
//meaning the wave is finished
this.repaint();//refresh any changes to the monsters' positions
}
}
The problem is that only the first monster is moving through the path, meaning only that one is painted when I invoke repaint(). What am I doing wrong in paintComponent(Graphics g)? Because I believe that's where my mistake is... How can I draw all "available" images each time one after another?
Note: They are buffered images in .PNG format if that matters at all.
I though about adding the Monster class code but I believe explaining the methods' function is enough to understand what's going on. Should someone need more details let me know. Thanks in advance.

I think you have to put parantheses around your loops.
The shorthand only loops over the first line after the loop
//Output:
//AAAAAAAAAAAAAAAAAA
//AAAAAAAAAAAAAAAAAA
//AAAAAAAAAAAAAAAAAA
//AAAAAAAAAAAAAAAAAA
//BBBBBBBBBBBBBBBBBB
for(Monster m:wave)
System.out.println("AAAAAAAAAAAAAA");
System.out.println("BBBBBBBBBBBBBBB");
//Output:
//AAAAAAAAAAAAAAAAAA
//AAAAAAAAAAAAAAAAAA
//AAAAAAAAAAAAAAAAAA
//AAAAAAAAAAAAAAAAAA
//BBBBBBBBBBBBBBBBBB
//BBBBBBBBBBBBBBBBBB
//BBBBBBBBBBBBBBBBBB
//BBBBBBBBBBBBBBBBBB
for(Monster m:wave)
{
System.out.println("AAAAAAAAAAAAAA");
System.out.println("BBBBBBBBBBBBBBB");
}

Related

Storing different objects in an array java

What I need to do is storing different objects of an "Obstacle" super class in an array, and then perform the same actions as if I had one. So I need to be able to draw all the objects and also make them collide with the ball class.
So I tried to put all the instances of an object in an array in a for loop, and then I tried to paint them. But I can't figure out how to use the functions on the objects if they are stored in an array.
I tried to do this:
for(int i = 0;i<objects.length;i++){
objects[0].paint(g);
}
but the "paint(g)" part is just highlighted in red and it doesn't work.
If someone could help me I would be really happy! I haven't stored objects in arrays before, so I'm kind of clueless as what to do.
I also tried making the for loop like this:
if(i>=1 && i<15){
Obstacle star = new StarObstacle(rand.nextInt(400),rand.nextInt(400));
objects[i]= star;
star.paint(g);
}
Here they actually show up, but the stars are just flying all over the screen, so something must be changing x and y values all the time.
edit: sorry accidentally added the whole code instead of only the part I need help on.
It's the for loop in the Main(int x,int y){} scope
package com.company;
import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.util.Random;
public class Main extends JPanel implements KeyListener {
Ball b;
TriangleObstacle o;
BorderObstacle border;
StarObstacle s;
Player player;
int bounceCount=0;
Object[] objects;
Random rand = new Random();
Main(int width, int height) {
//create a new black ball at the center of the screen
b = new Ball(width*0.5f, height*0.5f, 3, 0,0,0);
//make a border around the window
border = new BorderObstacle(width, height);
objects = new Object[30];
//setup a triangle obstacle
o = new TriangleObstacle(width*0.3f, height*0.7f, 200, 50);
s = new StarObstacle(400,300);
player = new Player();
this.addKeyListener(this);
this.setFocusable(true); //needed to make
for(int i = 0; i < objects.length;i++){
if(i==0){
objects[0]= new Player();
}
if(i>=1 && i<15){
objects[i]= new StarObstacle(rand.nextInt(400),rand.nextInt(400));
}
if(i>15){
objects[i]= new TriangleObstacle(30,30,rand.nextInt(400),rand.nextInt(400));
}
}
}
public void update() {
//move over all obstacles and check whether they should bounce the ball
border.bounceBall(b);
o.bounceBall(b);
s.bounceBall(b);
if(player.bounceBall(b)){
bounceCount++;
}
//move ball based on speed and location
b.move();
player.move(); //updates my player object.
this.repaint(); //runs the paint method on the object
}
#Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2 = (Graphics2D) g;
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g.setFont(new Font("TimesRoman", Font.PLAIN, 20));
g.drawString("Amount of bounces on Player: " + bounceCount, 300, 100);
b.paint(g);
o.paint(g);
s.paint(g);
player.paint(g);
border.paint(g);
}
public static void main(String[] args) {
int width = 800;
int height = 600;
JFrame frame = new JFrame("Pinball"); //create a new window and set title on window
frame.setSize(width, height); //set size of window
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //set the window to close when the cross in the corner is pressed
Main m = new Main(width,height-22); //-22 to account for menubar height //create a new object and runs constructor for initial setup of the program
frame.add(m); //add the content of the object to the window
frame.setVisible(true); //make the window visible
while (true) { //keep running a loop
//each time the loop is run do
m.update(); //run the update method on the object
try {
Thread.sleep(10); //stops this part of the program for 10 milliseconds to avoid the loop locking everything. Now the screen has time to update content etc.
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
#Override
public void keyTyped(KeyEvent e) {
}
#Override
public void keyPressed(KeyEvent e) {
int code = e.getKeyCode(); //gets input as keycode.
if(code==KeyEvent.VK_RIGHT){
player.setRight(true); //sets the movement for right to true, making it move by 5 pixels in the positive direction, for each update.
player.setLeft(false);
}
if(code==KeyEvent.VK_LEFT){
player.setLeft(true);
player.setRight(false);
}
}
#Override
public void keyReleased(KeyEvent e) { //keyReleased setting them to false to prevent the object to keep moving.
int code = e.getKeyCode();
if(code==KeyEvent.VK_RIGHT){
player.setRight(false);
}
if(code==KeyEvent.VK_LEFT){
player.setLeft(false);
}
}
}
You need to write your own method paint(Graphic g) in your classes "Player", "StarObstacle", "TriangleObstacle".
something like this:
class TriangleObstacle extend Obstacle {
public paint(Graphics g) {
g.drawPolygon (...);
}
}
Also, avoid to use an array of Objects (Objects[]). Better use your superclass Obstacles for the array (Obstacle[] myObstacle = new Obstacle[30];
And don't put the Player object inside the array of Obstacle it wouldn't make sense.
At final you could have:
Obstacle[] myObstacles = new Obstacle[30];
Player player = new Player();
....
for (Obstacle obstacle : myObstacles) {
obstacle.paint(g);
}
player.paint(g);
This:
for(int i = 0;i<objects.length;i++){
objects[0].paint(g);
}
Doesn't achieve what you want because you are always accessing index 0.
Try this:
for(int i = 0;i<objects.length;i++){
objects[i].paint(g);
}
This allows you to access and paint each object present on the index represented by i. I can't guarantee that this will solve the problem, but it is a problem.
You need to cast the object and use the correct index so :
objects[0].paint(g);
should be
((Observer)objects[i]).paint(g);
However this is completely the wrong approach. Please read up on java generics. http://docs.oracle.com/javase/tutorial/java/generics/
You should be using a List or some other collection with an upper bound wildcard eg
List<? extends Observer>
Which will provide type safety.
You must create an array of Obstacles instead of objects, the in your Obstacles interface add a method definition called paint(). Then you have to override the paint() method in every implementation of Obstacles. And when you call paint method in objects of the array it will call the corresponding method.
Instead of an array, can you put the objects in a list? Something like...
List<Obstacle> someList = [however you populate your array, just populate the list instead];
for(int i = 0; i<somelist.length; i++) {
someList.get(i).paint(g);
}

Java Swing: Draw a gameboard as a JButton grid backed by a 2D array of objects

I am programming a small space-themed dungeon crawler game with a GUI made with Swing in Java. I am using the MVC programming paradigm. The game is represented as a grid on which buttons can be clicked to move the player over the board or attack enemies.
In the model/logic of the game I generate an abstract representation of the game environment using a 2D array by randomly assigning objects to x (column) and y (row) coordinates using the following method:
//methods
public void setGalaxy() {
galaxyArray = new GalacticObject[this.row][this.col];
//construct the array
Random rand = new Random();
int random;
for (int i = 0; i < this.row; i++) {
for (int j = 0; j < this.col; j++) {
GalacticObject obj = new GalacticObject(i,j);
random = rand.nextInt(100);
if (random < 5) {
//asteroid (5 percent chance)
obj.makeAsteroid();
} else if (random < 9) {
//blackhole (4 percent chance)
obj.makeBlackHole();
} else {
//rest is open (= empty)
obj.makeOpen();
}
galaxyArray[i][j] = obj;
}
}
}
Now I want to draw the actual GUI game board backed by this 2D array of objects in a JPanel container using a grid of JButtons. I want to basically call all the objects in the galaxyArray and draw a JButton with an corresponding image overlay at the corresponding coordinates in a ButtonGrid. What would be the best way to achieve this using Swing?
Currently, I also have written the following draft for a method that draws a JButtonGrid but I still fail to see what is the best strategy of having it backed by a 2D array of objects.
Furthermore, adding the icon for the buttons is not working for reasons unclear to me. (I commented that part out.)
public JPanel makeGameBoard() {
/** This method makes a first version of the game board when the object is first called */
//create a new JPanel
JPanel boardPanel = new JPanel();
// create a gridButton of JButtons defined by the width and length
JButton[][] gridButton = new JButton[this.boardWidth][this.boardLength];
// set layout
boardPanel.setLayout(new GridLayout(this.boardWidth,this.boardLength));
//for-loops to place buttons in gridButton
for(int y = 0; y < this.boardLength; y++) {
for(int x = 0; x < this.boardWidth; x++){
// creates new button (with coordinates as string); gridButton[x][y] needs to be reused as coordinate system
gridButton[x][y]=new JButton(x+":"+y);
gridButton[x][y].setActionCommand(x+":"+y);
gridButton[x][y].setText("");
gridButton[x][y].addActionListener(new ActionListener(){
#Override
public void actionPerformed(ActionEvent e) {
String com = e.getActionCommand();
System.out.println(com);
}
});
// add icon to every button
// try {
// Image img = ImageIO.read(getClass().getResource("resources/invisible.png"));
// gridButton[x][y].setIcon(new ImageIcon(img));
// }
// catch (IOException ex) {
// System.out.println("Image file for gridButton not found!");
// }
// add the gridButton to the panel
boardPanel.add(gridButton[x][y]);
}
}
//return boardPanel
return boardPanel;
}
Essentially I am wondering what is the best strategy to access the objects stored in the galaxyArray from my makeGameBoard method so that the variables of the objects in the array can be used to draw an image on the button with corresponding coordinates in the grid.
/*EDIT Thanks to the suggestion and linked tutorials from the friendly people below, I have made it work! Here is the code for the board View for anyone having similar questions:
public void updateGameBoard(Galaxy board) {
/** This method initializes the board when the galaxy is first created in the game logic and updates it throughout the game */
Galaxy galaxyArray = board;
for (int r = 0; r < this.boardWidth; r++) {
for (int c = 0; c < this.boardLength; c++) {
//make galactic object and extract info from Galaxy
GalacticObject temporary = new GalacticObject(r,c);
temporary = galaxyArray.getGalacticObject(r,c);
//check the object and set the corresponding tile image
if (temporary.isAsteroid()) {
gridButton[r][c].setText("A");
} else if (temporary.isAsteroidField()) {
gridButton[r][c].setText("AF");
} else if (temporary.isBlackHole()) {
gridButton[r][c].setText("BH");
} else if (temporary.isOpen()) {
gridButton[r][c].setText("");
}
}
}
}
The exact details depend on how you implement the observer pattern. Following this outline, the example game cited here simply lets the main view, RCView, keep a private reference to the array named board, which is maintained by the game model, RCModel. Because RCView implements the Observer interface, the view's update() implementation simply iterates through the board and updates its array of tiles in response. Note that the update() method signature includes a reference to the Observable requesting the update. In your example,
public void update(Observable model, Object arg) {
GalacticObject galaxyArray = ((GameModel) model).getGalaxyArray();
//loop though model, updating view components
this.repaint();
}

Applying class methods to a whole ArrayList

I am wondering if there is a bit of code or that can apply a method from a class to all of the objects in the ArrayList? I'm making a basic space invaders program and I am trying to implement a move method that will apply to all of enemies, so that they move in a group rather than individually.
I've created the items in the array list here:
for (int i = 0; i < 6; i++) {
venWidth = venWidth - 139;
enemyList.add(new Venusian("/venusian.jpg", venWidth, height));
}
for (int i = 6; i < 12; i++) {
merWidth = merWidth - 145;
enemyList.add(new Mercurian("/mercurian.jpg", merWidth, merHeight));
}
for (int i = 12; i < 18; i++) {
marWidth = marWidth - 125;
enemyList.add(new Martian("/martian.jpg", marWidth, marHeight));
}
Here is where I call the move method:
for (int i = 0; i < enemyList.size(); i++) {
Invader Invaders = (Invader) enemyList.get(i);
Invaders.draw(g);
Invaders.Move(1024);
This makes them move independently and overlap, at the moment I am just moving them right and left using the boundaries of my created window. So is there any way of moving them together at the same time? I have searched for a way to apply a class method to all of the lists items but I haven't found anything after a couple of hours.
Any material, sources or advice relating to this would be greatly appreciated.
You will have to come up with a solution that can decouple the Invaders you are moving from those you are displaying.
This is due to the fact that your individual Invaders will always be more or less sequentially moved - even if you are working with multiple threads, etc. Even if you would start using Java8 Lambdas to write your code like this:
ArrayList<Invader> badGuys;
//fill your List here
badGuys.forEach( badGuy -> badGuy.move());
This would also create intermediate states where some Invaders were moved, some were not.
So you have to make sure that you only draw a consistent set of Invaders to your screen. You could do this several ways:
Only draw to screen after all Invaders were moved
Make a copy of your invaders for drawing, while the Invaders are being moved. After all Invaders were moved, start displaying the Invaders from the moved List
...
1st Edit: How do you draw the Invaders to screen? Is this happening in separate threads?
3rd EDIT: Okay so maybe you can stop your timerThread before starting to move your Invaders. And when you are finished with moving them you can restart the timer again. Check what methods your timer offers It should have start() and stop() or maybe suspend() methods.
Do something like this:
timer.stop();
badGuys.moveAll();
timer.start();
2nd EDIT: Just looked over your code again. There is no need for you to start your for loop number 2 and 3 from indexes other than 0. Your code will be easier to read if for example you just say:
for (int i = 0; i < 6; i++) { // start from 0 (to 6) instead of 6 to 12
merWidth = merWidth - 145;
enemyList.add(new Mercurian("/mercurian.jpg", merWidth, merHeight));
}
create an interface like Moveable. and put Move method on it. then implement it on Venusian, Martian and Mercurian. and use this interface on arraylist
interface Moveable {
public void Move(int dist);
}
class Mercurian implements Moveable {
public void Move(int dist)
{
//do something
}
}
class Venusian implements Moveable {
public void Move(int dist)
{
//do something
}
}
class Martian implements Moveable {
public void Move(int dist)
{
//do something
}
}
ArrayList<Moveable> enemyList = new ArrayList<Moveable>();

Programming Video Games for the Evil Genius:Project 10:Radical Racing-The Cars

Iv'e looked all over for answers to this book. And I know anyone else who has tried to read this book feels the same way. It's called "Programming Video Games for The Evil Genius" Is there anyone who has read this book? I'm on project 10:Radical Racing-The Cars. Everything compiles correctly but for some reason my cars are not showing up in the correct spot on the JFrame. They should be showing up under the two white lines. I'm positive the code is exactly the same as in the book, but the book is wrong. I have already tried changing the HEIGHT part of the point of origin but no matter what I do it does not budge. I can't attach an image because I don't have a rep of at least 10 .This is the code that the deals with the placement of the cars.
public class TheCars extends JFrame
{
final int WIDTH = 900; int HEIGHT = 650;
double p1Speed = .5, p2Speed = .5;
Rectangle p1 = new Rectangle(WIDTH/9,HEIGHT/2, WIDTH/30,WIDTH/30);
Rectangle p2 = new Rectangle(((WIDTH/9)+((int)((WIDTH/9)*1.5)/2)),(HEIGHT/2)+
(HEIGHT/10),WIDTH/30,WIDTH/30);
//the constructor
public TheCars()
{
//the following code creates the JFrame
super("Radical Racing");
setSize(WIDTH,HEIGHT);
setDefaultCloseOperation(EXIT_ON_CLOSE);
setVisible(true);
//start the inner class (which works on it's own because it is a thread)
Move1 m1 = new Move1();
Move2 m2 = new Move2();
m1.start();
m2.start();
}
//this will draw the cars and the racetrack
public void paint(Graphics g)
{
super.paint(g);
//set the color to blue for p1
g.setColor(Color.BLUE);
//now draw the actual player
g.fill3DRect(p1.x,p1.width,p1.width,p1.height,true);
//set the color to red for p2
g.setColor(Color.red);
//now draw the actual player
g.fill3DRect(p2.x,p2.width,p2.width,p2.height,true);
}
private class Move1 extends Thread
{
public void run()
//This should all be in an infinite loop so that the process repeats.
{
while(true)
{
//now put in the try block. This will let
//the program exit if there is an error
try
{
//first refresh the screen
repaint();
//increase speed a bit
if(p1Speed<=5)
p1Speed+=.2;
p1.y-=p1Speed;
//this delays the refresh rate
Thread.sleep(75);
}
catch(Exception e)
{
//if there is an exception (an error), exit the loop
break;
}
}
}
}
private class Move2 extends Thread
{
public void run()
{
//this should all be in an infinite loop so the process repeats
while(true)
{
//now put the code in a "try" block.
//this will let the program exit if there is an error
try
{
//first refresh the screen
repaint();
//increase the speed a bit
if(p2Speed<=5)
p2Speed+=.2;
p2.y-=p2Speed;
//this delays the refresh rate
Thread.sleep(75);
}
catch(Exception e)
{
//if there is an exception (an error), exitthe loop
break;
}
}
}
}
public static void main(String[]args)
{
new TheCars();
}
}
Assuming you're painting those Rectangle objects directly onto the screen, we have to assume that the expressions "HEIGHT/2" and "HEIGHT/2 + HEIGHT/10" are coming out equal, and nonzero but small. That would be the case if HEIGHT is an int, and the value is more than 2 and less than 10. Presumably the value would need to be a couple hundred, at least, for those boxes to show up in the middle of the screen. Check the value of HEIGHT (just using a System.out.println() would be fine) and make sure it's the actual height of the window.
EDIT
Now that we see the rest of the code: the second argument to each call to fill3DRect() is wrong. It should be the y member of the Rectangle objects, which is a large, varying number, but you're passing the width member, which is a small fixed number. Change both the calls to look like this and you'll be back on track:
g.fill3DRect(p1.x, p1.y, p1.width, p1.height, true);

Frame per second counting in Android game

I'm looking for a method of counting Frames Per Second in game applications, the problem is that i dont have the source code for any of those apps, they dont have such functionality implemented inside. To be honest i dont really expect this to be possible but it was worth to ask.
And to be perfectly clear i understand that i need a basic knowledge and code of the main painting loop to count FPS.
Best Regards
What is the problem of making FPS counting when you have a main paint loop (don't you?).
I'm not familiar with Android features, but I'm sure it is done there the same in any game on any OS. The easiest way to make a game - is to make 2 threads. First one will be for logic actions (calculating trajectories, object position change over time, etc.). Second thread will take current game state (calculated by first thread) and draw it on the screen.
Here is the commented code on both threads with FPS counter:
//Class that contain current game state
class GameState {
private Point objectPosition;
public Point getObjectPosition() {
return objectPosition;
}
public void setObjectPosition(Point pos) {
this.objectPosition = pos;
}
}
//Runnable for thread that will calculate changes in game state
class GameLogics implements Runnable {
private GameState gameState; //State of the game
public GameLogics(GameState gameState) {
this.gameState = gameState;
}
public void run() {
//Main thread loop
while (true) { //Some exit check code should be here
synchronize (gameState) {
gameState.setObjectPosition(gameState.getObjectPosition()+1); //Move object by 1 unit
}
Thread.sleep(1000); //Wait 1 second until next movement
}
}
}
//Runnable for thread that will draw the game state on the screen
class GamePainter implements Runnable {
private Canvas canvas; //Some kind of canvas to draw object on
private GameState gameState; //State of the game
public GamePainter(Canvas canvas, GameState gameState) {
this.canvas = canvas;
this.gameState = gameState;
}
public void drawStateOnCanvas() {
//Some code that is rendering the gameState on canvas
canvas.drawLine(...);
canvas.drawOtherLine(...);
....
}
public void run() {
//Last time we updated our FPS
long lastFpsTime = 0;
//How many frames were in last FPS update
int frameCounter = 0;
//Main thread loop
//Main thread loop
while (true) { //Some exit check code should be here
synchronize (gameState) {
//Draw the state on the canvas
drawStateOnCanvas();
}
//Increment frame counter
frameCounter++;
int delay = (int)(System.getCurrentTimeMillis() - lastFpsTime);
//If last FPS was calculated more than 1 second ago
if (delay > 1000) {
//Calculate FPS
double FPS = (((double)frameCounter)/delay)*1000; //delay is in milliseconds, that's why *1000
frameCounter = 0; //Reset frame counter
lastFpsTime = System.getCurrentTimeMillis(); //Reset fps timer
log.debug("FPS: "+FPS);
}
}
}
}
I'm not too knowledgeable with Android Game development, but in Java2D (it's a bit hacky but it works...) I would xboot a jar with the edited JRE class which controls the rendering (eg Canvas) into the process.
This is a good read on game loop. It explains the various implementations and pros/cons of game loops.
And this is a good tutorial on implementing the gameloop + FPS counter in Android.

Categories

Resources