i want create basic 2d java game. where do i start? can i find any tutorials or examples? i start learning threads now.
like this:
Attachment 2105
Printable View
i want create basic 2d java game. where do i start? can i find any tutorials or examples? i start learning threads now.
like this:
Attachment 2105
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.
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.
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.
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.
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 ....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 http://www.java-forums.org/new-java/...tion-help.html i do same thing but it move not smoothly.
Look at the drawImage method used in the paint method. That is where you would put the image you want as backgroundQuote:
how 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.Quote:
can i use keylistener instead of keyadapter
Read the API doc for the KeyAdapter class.Quote:
difference between keyAdapter and keyListener?
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.
You could also checkout this:
Minesweeper Clone in Java
The graphics are not that pretty, but the logical engine behind it is quite ok.
missiles code doesn't work in :Moving sprites is there any simple examples like this?
Can you post the code that "doesn't work" and explain what the problem is?Quote:
missiles code doesn't work
ok, i solved my problem. i must used thread for enemies, right? is there any basic thread for games examples?
I don't remember seeing one on this forum.Quote:
is there any basic thread for games examples?
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.
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.Quote:
how many thread should i use
i used actionperformed and time functions. can it work with threads or should i change my code?
The Timer class uses a Thread when it calls your actionPerformed method.
Read the API doc for the Timer class you are using.
timer class calls actionPerformed, threads calls run method. so what is the different?