What's new

Tutorial Java Game Programming

Status
Not open for further replies.

DCCS

Forum Expert
Joined
Jun 10, 2013
Posts
7,175
Solutions
22
Reaction
17,644
Points
3,471
You do not have permission to view the full content of this post. Log in or register now.

Java Game Programming for Beginners

Creating a game using Java may look daunting at first, but when you get the hang of the basics, you’ll realize that it’s a programming language designed to make things easier for developers.


Before, triple A games were created either through C or You do not have permission to view the full content of this post. Log in or register now.. However, that changed when mobile gadgets took over as the most popular platform for gaming. Many games for the Android and iOS platform today are being developed using Java. Award-winning titles like Angry Birds and Temple Run were both developed using it. The first software to offer online ****** entertainment back in 1996, Inter******, has jumped on the bandwagon in using Java to develop its slot machine games. One of today’s popular MMORPGs, You do not have permission to view the full content of this post. Log in or register now., is also a product of Java programming.

With these basics, you will be able to set yourself in the right direction for developing games using Java. Credits to You do not have permission to view the full content of this post. Log in or register now. for this easy-to-follow game programming tutorial.

The Window
To create a game, you’ll need to create a window to hold everything together. Here’s a snippet that will give you a 300×400 window—something that you can easily find in many Java tutorials:

Code:
import javax.swing.JFrame;
import javax.swing.WindowConstants;

public class FrameDemo{
public static void main(String args[]){
JFrame myFrame = new JFrame("Sample Frame");
myFrame.setSize(300,400);
myFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
myFrame.setVisible(true);
}
}

With this code, you will be able to control the window of your game. You can minimize, maximize, and change the size settings to your preference. Apart from keeping things together, the window serves as a command center for the code that will manage your application’s user interface.

Animation
Of course, a game without animation would be pretty boring. Here’s an example of how you can code a simple moving object for your game. If you’re thinking about doing a sports game like tennis or a simple pøkêr table game with card animation, this will get you started.

First, you need to determine the starting position of the ball (x and y). Then, to make it move, you have to modify the position with each shift.

Code:
package com.edu4java.samplegame;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import javax.swing.JFrame;
import javax.swing.JPanel;

@SuppressWarnings("serial")
public class Game extends JPanel {
int x = 0;
int y = 0;
private void moveBall() {
x = x + 1;
y = y + 1;
}
@Override
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2d.fillOval(x, y, 30, 30);
}

public static void main(String[] args) throws InterruptedException {
JFrame frame = new JFrame("Sample Frame");
Game game = new Game();
frame.add(game);
frame.setSize(300, 400);
frame.setVisible(true);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

while (true) {
game.moveBall();
game.repaint();
Thread.sleep(10);
}
}
}

If you already know the basics of coding in Java, this should be cake for you. But if you’re new to Java programming, there are tons of lessons that you can learn from You do not have permission to view the full content of this post. Log in or register now.’s tutorial pages.+
 
nice one po sir, you should also share the basics of java programming to them then. step by step if necessary. i know it is too much for a suggestion, but as we can see, medyo kulang pa talaga sa contents ang PHC pagdating sa programming and scripting fields. of course thousands of sites and links exist throughout the net kaya pwede nilang sabihing "hindi na kailangan dito yon", pero mas maganda sana kung mismong sa PHC manggagaling yung mga tutorials mula basics, isa pa mas madali nila maiintindihan pag tagalog. ang point ko lang po is para hindi na kailanganin pang lumabas sa site natin ang mga ka PHCitizens natin para matutunan nila mga basics ng programming mula sa external sites. gusto ko din sana magshare dito ng basic knowledge sa programming, the problem is i still don't have the rights to do so kasi hindi pa ko pro. hehe sorry kung masyadong mahaba
 
nice one po sir, you should also share the basics of java programming to them then. step by step if necessary. i know it is too much for a suggestion, but as we can see, medyo kulang pa talaga sa contents ang PHC pagdating sa programming and scripting fields. of course thousands of sites and links exist throughout the net kaya pwede nilang sabihing "hindi na kailangan dito yon", pero mas maganda sana kung mismong sa PHC manggagaling yung mga tutorials mula basics, isa pa mas madali nila maiintindihan pag tagalog. ang point ko lang po is para hindi na kailanganin pang lumabas sa site natin ang mga ka PHCitizens natin para matutunan nila mga basics ng programming mula sa external sites. gusto ko din sana magshare dito ng basic knowledge sa programming, the problem is i still don't have the rights to do so kasi hindi pa ko pro. hehe sorry kung masyadong mahaba
Eto Tutorial - 10 Programming Languages You Should Learn Right Now | PHCorner Community

Lahat ng important programming language nandyan (y) Pwede ka namang mag-share ng knowledge mo kahit hindi ka pa pro.
 
sige thanks sa support i think gusto ko nga mag start ng programming basics thread dito sa PHC soon, starting from the legendary statement hello world pataaas. (y)(y)(y)
 
sige thanks sa support i think gusto ko nga mag start ng programming basics thread dito sa PHC soon, starting from the legendary statement hello world pataaas. (y)(y)(y)
Yeah Good luck :) until makagawa ka ng "I love you Virus"
 
tama c boss fazz12 mgnda suggest nya para sa mga gaya ko na bago lang papasok sa mundo ng programming hehe
 
this is a very good thread maganda kung makapag share din tayo dito ng e-books for reference , and ma curate yung sub-forum for other languages as well
 
Status
Not open for further replies.

Similar threads

Back
Top