08-11-2011, 01:27 PM
(This post was last modified: 08-11-2011, 05:53 PM by mrchickenpop.)
I've been studying on 2D game creating now for a kinda long time and now I decided to create a tutorial for everyone who wants to make their own 2D game's like buildism.
[Tutorial]
-What you need?-
You need to study on java hardly tough it's kinda easy to use.
You will also need for example Net Beans. Net Beans is a good program to use if you want to build on your 2D game.
-Now, get started-
First you need to open Net beans or whatever you use.
Then you will have to make sure you do a Package which contains 3 classes.
You can just name the Package whatever you want.
I named my package: MyGame
The 3 classes are going to be: Frame, Dude, Board.
The 3 classes are going to look like this:
1: package MyGame;
2:
3: public class Frame {
4:
5: }
6:
1: package MyGame;
2:
3: public class Dude {
4:
5: }
6:
1: package MyGame;
2:
3: public class Board {
4:
5: }
6:
Make sure you add all the scripts into new page's.
Just Don't add the frame and the board and the dude classes into the same page if you understand what I mean.
Now when you made the following steps, the scripts can talk to each other trough the "package MyGame;".
Now the next steps...
Now in the Frame class, you add:
1: package MyGame;
2:
3: public class Frame {
4:
5: public static void main (String[] args) {
6: }
7: }
And now you will have to start creating the frame, and when it's finished it should look like this:
1: package MyGame;
2:
3: import javax.swing.*;
4:
5: public class Frame {
6:
7: public static void main (String[] args) {
8: JFrame frame = new JFrame ("game") ;
9: frame.add (new Board () ) ;
10: frame.setDefaultCloseOperation (JFram
11: e.EXIT_ON_CLOSE) ;
12: frame.setSize (1200,365) ;
13: frame.setVisible (true) ;
14: }
15: }
16:
The "JFrame frame = new JFrame ("game") ; is the game name.
you can change the "game" to whatever you want to but remember to change it inside the " " and use the Shift x 2 button to create the ".
And the (1200,365) is the background image.
And you can put the main character and the background image into C:/ so that you can axes 'em from there into your (frame) class.
And as you could see the code: "frame.add (new Board () ) ;" will basically start the board class.
So lets move into the Board class.
Next steps...
You have to add some basic stuff into the Board class because it constructs the board from the frame so you have to add:
1: package MyGame;
2:
3: public class Board {
4:
5: public Board () {
6:
7: }
8: }
9:
Good work! Now you have to create an instance of the Dude into the board. You simply add: Dude p; And when you done that you need to get the Dude's Image, so you will need to add: Image img; And you will need to import it into the background.
Now you will need to add: p = new Dude () ; under the Public Board text, and add: setFocusable (true) ; under the New Dude text. Now you will need to expand the JPanel so you need to add: extends JPanel { beside the "public class Board" text. A few more things...
I forgot to ... just add: import java.awt.Image;
and add: import javax.swing.*;
Add 'em under the package text.
Good work.
Now the next steps...
Now you will need to get your image so you will need to add:
ImageIcon i = new ImageIcon ("C:/test.png") ;
I will add more sometime...
[Tutorial]
-What you need?-
You need to study on java hardly tough it's kinda easy to use.
You will also need for example Net Beans. Net Beans is a good program to use if you want to build on your 2D game.
-Now, get started-
First you need to open Net beans or whatever you use.
Then you will have to make sure you do a Package which contains 3 classes.
You can just name the Package whatever you want.
I named my package: MyGame
The 3 classes are going to be: Frame, Dude, Board.
The 3 classes are going to look like this:
1: package MyGame;
2:
3: public class Frame {
4:
5: }
6:
1: package MyGame;
2:
3: public class Dude {
4:
5: }
6:
1: package MyGame;
2:
3: public class Board {
4:
5: }
6:
Make sure you add all the scripts into new page's.
Just Don't add the frame and the board and the dude classes into the same page if you understand what I mean.
Now when you made the following steps, the scripts can talk to each other trough the "package MyGame;".
Now the next steps...
Now in the Frame class, you add:
1: package MyGame;
2:
3: public class Frame {
4:
5: public static void main (String[] args) {
6: }
7: }
And now you will have to start creating the frame, and when it's finished it should look like this:
1: package MyGame;
2:
3: import javax.swing.*;
4:
5: public class Frame {
6:
7: public static void main (String[] args) {
8: JFrame frame = new JFrame ("game") ;
9: frame.add (new Board () ) ;
10: frame.setDefaultCloseOperation (JFram
11: e.EXIT_ON_CLOSE) ;
12: frame.setSize (1200,365) ;
13: frame.setVisible (true) ;
14: }
15: }
16:
The "JFrame frame = new JFrame ("game") ; is the game name.
you can change the "game" to whatever you want to but remember to change it inside the " " and use the Shift x 2 button to create the ".
And the (1200,365) is the background image.
And you can put the main character and the background image into C:/ so that you can axes 'em from there into your (frame) class.
And as you could see the code: "frame.add (new Board () ) ;" will basically start the board class.
So lets move into the Board class.
Next steps...
You have to add some basic stuff into the Board class because it constructs the board from the frame so you have to add:
1: package MyGame;
2:
3: public class Board {
4:
5: public Board () {
6:
7: }
8: }
9:
Good work! Now you have to create an instance of the Dude into the board. You simply add: Dude p; And when you done that you need to get the Dude's Image, so you will need to add: Image img; And you will need to import it into the background.
Now you will need to add: p = new Dude () ; under the Public Board text, and add: setFocusable (true) ; under the New Dude text. Now you will need to expand the JPanel so you need to add: extends JPanel { beside the "public class Board" text. A few more things...
I forgot to ... just add: import java.awt.Image;
and add: import javax.swing.*;
Add 'em under the package text.
Good work.
Now the next steps...
Now you will need to get your image so you will need to add:
ImageIcon i = new ImageIcon ("C:/test.png") ;
I will add more sometime...