Results 1 to 20 of 85
Thread: i want write 2d java game
- 12-03-2011, 06:48 PM #1
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
- 12-03-2011, 06:55 PM #2
Re: i want write 2d java game
One thing you should look at is how to make animated drawings. There are a lot of moving ball programs (like pong) here on the Forum for code samples.
- 12-04-2011, 07:03 PM #3
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
Re: i want write 2d java game
i try find some examples but i only find some advanced examples. most of them using game engines. i want use only threads. it will do not much things. my plane will move, enemies will move, we will shoot each other.
- 12-04-2011, 07:16 PM #4
Re: i want write 2d java game
I've never seen the "game engines" you talk about here on this Forum. There are many "moving ball" programs heret that would show thread usages.
- 12-04-2011, 07:16 PM #5
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: i want write 2d java game
Start here: Programing An Applet Game Of Pong - Java Tutorials | Dream.In.Code
Although some of his practices aren't the greatest, it should give you a decent starting point.
- 12-06-2011, 08:42 PM #6
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
Re: i want write 2d java game
i found a website :The Java 2D games tutorial i practices these example.
how can i add background image to this code and can i use keylistener instead of keyadapter, timer ....Java Code:public class Board extends JPanel implements ActionListener { private Timer timer; private Craft craft; public Board() { addKeyListener(new TAdapter()); setFocusable(true); setBackground(Color.BLACK); setDoubleBuffered(true); craft = new Craft(); timer = new Timer(5, this); timer.start(); } public void paint(Graphics g) { super.paint(g); Graphics2D g2d = (Graphics2D)g; g2d.drawImage(craft.getImage(), craft.getX(), craft.getY(), this); Toolkit.getDefaultToolkit().sync(); g.dispose(); } public void actionPerformed(ActionEvent e) { craft.move(); repaint(); } private class TAdapter extends KeyAdapter { public void keyReleased(KeyEvent e) { craft.keyReleased(e); } public void keyPressed(KeyEvent e) { craft.keyPressed(e); } } }
i wrote this code null pointer exception help i do same thing but it move not smoothly.
- 12-06-2011, 09:27 PM #7
Re: i want write 2d java game
Look at the drawImage method used in the paint method. That is where you would put the image you want as backgroundhow can i add background image to this code
The KeyAdapter class implements the KeyListener interface and provides empty methods that you need to fill in.can i use keylistener instead of keyadapter
- 12-06-2011, 11:14 PM #8
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
- 12-06-2011, 11:16 PM #9
Re: i want write 2d java game
Read the API doc for the KeyAdapter class.difference between keyAdapter and keyListener?
- 12-06-2011, 11:30 PM #10
- Join Date
- Jan 2011
- Location
- Richmond, Virginia
- Posts
- 3,069
- Blog Entries
- 3
- Rep Power
- 7
Re: i want write 2d java game
Was just about to post what norm said. Get used to searching the API, often it is all you need. Key adapter is just easier than using a listener.
- 12-06-2011, 11:44 PM #11
Member
- Join Date
- Oct 2011
- Posts
- 15
- Rep Power
- 0
Re: i want write 2d java game
You could also checkout this:
Minesweeper Clone in Java
The graphics are not that pretty, but the logical engine behind it is quite ok.
- 12-07-2011, 03:13 PM #12
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
Re: i want write 2d java game
missiles code doesn't work in :Moving sprites is there any simple examples like this?
- 12-07-2011, 04:05 PM #13
Re: i want write 2d java game
Can you post the code that "doesn't work" and explain what the problem is?missiles code doesn't work
- 12-07-2011, 05:47 PM #14
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
Re: i want write 2d java game
ok, i solved my problem. i must used thread for enemies, right? is there any basic thread for games examples?
- 12-07-2011, 05:49 PM #15
Re: i want write 2d java game
I don't remember seeing one on this forum.is there any basic thread for games examples?
- 12-08-2011, 12:34 PM #16
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
Re: i want write 2d java game
how many thread should i use and which classes are runnable? now i have board, craft, missiles and test classes. i will add enemyplane class.
- 12-08-2011, 12:53 PM #17
Re: i want write 2d java game
Depends on your program design. At least two, one for the user's GUI and one that is called by a timer to change positions of the things you are displaying.how many thread should i use
- 12-08-2011, 10:07 PM #18
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
Re: i want write 2d java game
i used actionperformed and time functions. can it work with threads or should i change my code?
- 12-08-2011, 10:10 PM #19
Re: i want write 2d java game
The Timer class uses a Thread when it calls your actionPerformed method.
Read the API doc for the Timer class you are using.
- 12-08-2011, 10:25 PM #20
Member
- Join Date
- Oct 2011
- Posts
- 50
- Rep Power
- 0
Similar Threads
-
Need a Help to write a program like write a word for the given number
By manideep.d132 in forum New To JavaReplies: 7Last Post: 11-30-2011, 06:58 PM -
trying to write a program for hangman word game
By durdanto in forum New To JavaReplies: 1Last Post: 02-12-2011, 02:53 AM -
How to write it in Java
By agajantorayev in forum New To JavaReplies: 8Last Post: 08-11-2010, 07:37 AM -
how to write except in java??
By napi1234 in forum New To JavaReplies: 1Last Post: 08-09-2010, 04:49 AM -
How do i write this in java...?
By johnny7white in forum New To JavaReplies: 1Last Post: 11-28-2007, 07:05 PM


1Likes
LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks