Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Create your own 2D game [Tutorial]
#1
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...
Reply
#2
Rule 1 of tutorials! EVER!

Never teach until you've mastered something. That's why I'm no longer extending my PHP tutorial.

You see, your making mistakes, and when you make mistakes, we learn with them. That's very very bad. Also, if there is anyway in java to comment, I would comment this a lot more.
[Image: chaosthegreat.png]
Reply
#3
Ok Ok..... fine, i'll make my tutorial done. Will take 2 hours untill done but please mods don't delete untill I make it finished please... already this was a long time to write.
Reply
#4
Nice,

I appreciate your effort with this tutorial, but as Chaos said, you wouldn't be writing a tutorial on something that you have not yet mastered. How long have you been programming Java, honestly? You shouldn't be writing any tutorials for websites until you have been learning the language for at least a year and you feel like you have a solid understanding of it.

You must also keep in mind that right now, I'm currently writing a huge series of Java tutorials for you guys. With all that being said, is there still a reason why you are writing this tutorial?

Also, there are too many flaws to count in what you wrote. I must request that you stop writing this immediately because if someone actually takes this tutorial into consideration and follows it, here is what will happen:

1.) They will find that they have no clue what they are doing.
2.) They will find (if they even get far enough to test out your "code") that nothing you wrote works.
3.) They will become angry with you.
4.) They will have gained false knowledge that will potentially hurt them in the future if they actually do think it will work but they decide to pick up the language for themselves.

Again, I appreciate the fact that you like Java, but you've only been learning it for a little while. Master it first, please? Thank you for understanding.
-CoderRyne
Ryne Thiel
Reply
#5
Moving this to the Programming section, this is the section for Buildism tutorials.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)