first sorry for my bad English
Hello everyone I'm developing a 2d game using java and when a want to animate a sequence of images only the last image is loaded & i don't know why my code seems Logic
So that when I press "Q" button there most be an animation there.
code:
Dude Class
import java.awt.*;
import java.awt.event.KeyEvent;
import javax.swing.*;
public class Dude {
int x, dx, y, dy;
Image still;
Image walking;
Image effet;
ImageIcon i = new ImageIcon("C:/1.gif");
ImageIcon run=new ImageIcon("C:/NeroRun.gif");
ImageIcon down=new ImageIcon("C:/nero_down.gif");
Image[]attack=new Image[15];
ImageIcon saut_effet=new ImageIcon("C:/saut_effet.gif");
ImageIcon saut=new ImageIcon("C:/saut.gif");
ImageIcon effect=new ImageIcon("C:/saut_effet.gif");
//ImageIcon attack;
public Dude() throws {
still = i.getImage();
x = 10;
y = 260;
for(int j=0;j<15;j++){
ImageIcon ii=new ImageIcon("C:/Games/frame-"+(j+1)+".gif");
attack[j] = ii.getImage();
System.out.println("Nice");
}
}
public void move(){
x = x + dx;
y = y + dy;
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public Image getImage(){
return still;
}
public Image getEffet(){
return effet;
}
public void keyPressed(KeyEvent e) throws InterruptedException{
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = -3;
still=run.getImage();
System.out.println("Left");
if(y==260){y+=55;}
}
if (key == KeyEvent.VK_RIGHT) {
dx = 3;
still=run.getImage();
System.out.println("Right");
if(y==260){y+=55;}
effet=null;
}
if (key == KeyEvent.VK_DOWN) {
still=down.getImage();
System.out.println("Down");
if(y==260){y+=90;}
effet=null;
}
if (key == KeyEvent.VK_UP){
if(y==260){y-=130;}
effet=effect.getImage();
still=saut.getImage();
}
if(key == KeyEvent.VK_Q){
if(y==260){y-=135;
for(int j=0;j<15;j++){
still=attack[j];
}
//attack=new ImageIcon("C:/first_attack.gif");
//still=attack.getImage();}
effet=null;
}
}
}
public void keyReleased(KeyEvent e){
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT){
dx = 0;
still=i.getImage();
y=260;
effet=null;
}
if (key == KeyEvent.VK_RIGHT){
dx = 0;
still=i.getImage();
y=260;
effet=null;
}
if (key == KeyEvent.VK_DOWN){
dx = 0;
still=i.getImage();
y=260;
effet=null;
}
if (key == KeyEvent.VK_UP){
still=i.getImage();
y=260;
effet=null;
}
if (key == KeyEvent.VK_Q){
still=i.getImage();
y=260;
effet=null;
}
}
}
Borad1 Class:
package FirstTest;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.ImageIcon;
import javax.swing.JPanel;
import javax.swing.Timer;
import org.newdawn.slick.SlickException;
/**
*
* #author SiLeNT J0cK3R
*/
class Board1 extends JPanel implements ActionListener{
Dude p;
Image img;
Timer time;
public Board1() throws SlickException{
p = new Dude();
addKeyListener(new AL());
setFocusable(true);
ImageIcon i = new ImageIcon("C:/Background.png");
img = i.getImage();
time = new Timer(5, this);
//Music.music();
time.start();
}
#Override
public void actionPerformed(ActionEvent e){
p.move();
repaint();
//System.out.println("Repaint");
}
#Override
public void paint(Graphics g){
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(img, 0, 0, null);
g2d.drawImage(p.getImage(), p.getX(), p.getY(),null);
//Pour animer les effets loresequ'on effectue un saut
g2d.drawImage(p.getEffet(),p.getX(),300,null);
//Pour animer les ennemies
}
private class AL extends KeyAdapter{
#Override
public void keyReleased(KeyEvent e){
p.keyReleased(e);
}
#Override
public void keyPressed (KeyEvent e){
try {
p.keyPressed(e);
} catch (InterruptedException ex) {
Logger.getLogger(Board1.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
}
for(int j=0;j<15;j++){
still=attack[j];
}
When identifying the Q key, you seem to just walk through the animation frames (images).For an animation to be visible, some time would have to pass between each change of an animation frame.
I would suggest you take a look at some examples and tutorials. Like the Space Invaders clone found here: www.cokeandcode.com
Related
I am trying to "teleport" objects to the opposite positions whenever they get out of screen. I've managed to do this with right & bottom sides, but for some reason, which I haven't figured out, the star objects won't go off screen on TOP & LEFT sides UNLESS the lerping speed is high enough.
Preview:
Main.java
package asteroids;
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.RenderingHints;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.image.BufferStrategy;
import java.awt.image.BufferedImage;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Random;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
public class Main extends Canvas implements KeyListener {
private boolean gameOver;
private BufferStrategy backBuffer;
private Dimension dimension = new Dimension(Config.WINDOW_WH[0], Config.WINDOW_WH[1]);
private List<Star> stars = new ArrayList<Star>();
private HashMap<Integer,Boolean> keyDownMap = new HashMap<Integer, Boolean>();
private Ship ship;
private Image bg;
private float starGoalX, starGoalY;
public Main() {
// Initialize Window
initWindow();
addKeyListener(this);
this.createBufferStrategy(2);
backBuffer = this.getBufferStrategy();
bg = new ImageIcon(getClass().getResource("/bg.png")).getImage();
// init variables
gameOver = false;
// Generating stars
generateStars();
// Init spaceship
ship = new Ship(25,36,"ship.png");
// Init loop
gameLoop();
}
public void initWindow(){
JFrame window = new JFrame("Asteroids");
setPreferredSize(dimension);
window.add(this);
window.pack();
window.setResizable(false);
window.setVisible(true);
window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
window.requestFocus();
}
public float lerp(float starGoal, float vel, float speed) {
return starGoal + speed * (vel - starGoal);
}
public void update() {
if(keyDownMap.containsKey(KeyEvent.VK_ESCAPE)){
gameOver = false;
System.exit(0);
}
for(Star s: stars) {
s.posx += lerp(this.starGoalX, s.velX, Config.lerpSpeed);
s.velX += this.starGoalX * Config.lerpSpeed;
s.posy += lerp(this.starGoalY, s.velY, Config.lerpSpeed);
s.velY += this.starGoalY * Config.lerpSpeed;
checkPos(s);
s.update();
}
}
public void checkPos(Star s) {
if(s.posx < -s.width)
s.posx = Config.WINDOW_WH[0]-s.width;
else if(s.posx > Config.WINDOW_WH[0])
s.posx = 0;
if(s.posy < -s.height)
s.posy = Config.WINDOW_WH[1]-s.height;
else if(s.posy > Config.WINDOW_WH[1])
s.posy = 0;
}
public void render(){
Graphics2D g = (Graphics2D) backBuffer.getDrawGraphics();
if (!backBuffer.contentsLost()) {
g.drawImage(this.bg,0,0,Config.WINDOW_WH[0], Config.WINDOW_WH[1], null);
// Draw Stars
g.setColor(Color.WHITE);
for(Star s: stars)
g.fillOval(s.posx - (s.width/2), s.posy - (s.height/2), s.width, s.height);
// Draw ship
g.drawImage(
this.ship.getImage(),
this.ship.posx, this.ship.posy,
this.ship.width, this.ship.height, null);
backBuffer.show();
g.dispose();
}
}
public void generateStars() {
for(int i = 0;i < 50;i++) {
int starX = new Random().nextInt(Config.WINDOW_WH[0]+100)+5;
int starY = new Random().nextInt(Config.WINDOW_WH[1]+100)+5;
stars.add(new Star(starX, starY));
}
}
public void gameLoop(){
while(!gameOver){
update();
render();
try{ Thread.sleep(20);}catch(Exception e){};
}
}
public static void main(String[] args) {
new Main();
}
#Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
#Override
public void keyPressed(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_LEFT) this.starGoalX = Config.lerpSpeed;
if(e.getKeyCode() == KeyEvent.VK_RIGHT) this.starGoalX = -Config.lerpSpeed;
if(e.getKeyCode() == KeyEvent.VK_UP) this.starGoalY = Config.lerpSpeed;
if(e.getKeyCode() == KeyEvent.VK_DOWN) this.starGoalY = -Config.lerpSpeed;
keyDownMap.put(e.getKeyCode(), true);
}
#Override
public void keyReleased(KeyEvent e) {
if(e.getKeyCode() == KeyEvent.VK_LEFT
|| e.getKeyCode() == KeyEvent.VK_RIGHT) this.starGoalX = 0;
if(e.getKeyCode() == KeyEvent.VK_UP
|| e.getKeyCode() == KeyEvent.VK_DOWN) this.starGoalY = 0;
keyDownMap.remove(e.getKeyCode());
}
}
Star.java
package asteroids;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Shape;
import java.awt.event.KeyEvent;
import java.awt.geom.Ellipse2D;
import java.util.HashMap;
import java.util.Random;
public class Star {
int width, height;
int posx, posy;
float velX, velY, velGoalX, velGoalY;
/** CONSTRUCTOR **/
public Star(int x, int y) {
int rand = new Random().nextInt(Config.STAR_SIZES.length);
width = Config.STAR_SIZES[rand];
height = Config.STAR_SIZES[rand];
posx = x;
posy = y;
}
public void update() {
// pass
}
}
Ship.java
package asteroids;
import java.awt.Image;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import javax.swing.ImageIcon;
public class Ship {
public int posx, posy;
public int width, height;
private Image image;
public Ship(int w, int h, String img) {
this.posx = Config.WINDOW_WH[0]/2;
this.posy = Config.WINDOW_WH[1]/2;
this.width = w;
this.height = h;
this.image = new ImageIcon(getClass().getResource("/"+img)).getImage();
}
public Image getImage() {
return this.image;
}
public void setPosx(int x) {posx = x;}
public void setPosy(int y) {posy = y;}
public void setImg(Image img) {
this.image = img;
}
public void update(HashMap keyDownMap) {
// pass
}
}
Config.java
package asteroids;
import java.awt.Color;
public class Config {
// MAIN CANVAS SETTINGS
public static int[] WINDOW_WH = {500, 500};
public static String WINDOW_BG_IMG = "";
public static Color WINDOW_BG_CLR = new Color(40, 42, 45);
// OBJECT SETTINGS
public static int[] STAR_SIZES = {10,5,8,3,7};
public static float lerpSpeed = 0.8f;
}
I'm working on a fairly basic game for myself. New to Java Swing but not to Cpp. Onto the problem at hand.
As I start to run the GUI app, I'm shot with a Null Pointer Exception and given four links where they happen(I use Eclipse as my IDE). But when I look at them I see no problem with the lines or anything around them.
So I came to see if any of you can spot what I can't find.
This class grabs the picture from the source folder and sets up the keys for giving movement.
import java.awt.event.KeyEvent;
import java.awt.Image;
import javax.swing.ImageIcon;
public class SPRITES
{
private int x_sped;
private int y_sped;
private int x;
private int y;
private Image sprite;
public SPRITES()
{
ImageIcon pine = new ImageIcon(this.getClass().getResource("Untitled.png")); //exception here, line 17
sprite = pine.getImage();
x = 0;
y = 0;
}
public void move()
{
x += x_sped;
y += y_sped;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public Image getImage()
{
return sprite;
}
public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();
if(key == KeyEvent.VK_A)
{
x_sped = -1;
}
if(key == KeyEvent.VK_D)
{
x_sped = 1;
}
if(key == KeyEvent.VK_W)
{
y_sped = -1;
}
if(key == KeyEvent.VK_S)
{
y_sped = 1;
}
}
public void keyReleased(KeyEvent e)
{
int key = e.getKeyCode();
if(key == KeyEvent.VK_A)
{
x_sped = 0;
}
if(key == KeyEvent.VK_D)
{
x_sped = 0;
}
if(key == KeyEvent.VK_W)
{
y_sped = 0;
}
if(key == KeyEvent.VK_S)
{
y_sped = 0;
}
}
}
The second one is for getting the frame setting up with completely making the frame and finishing up the making of the movement.
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.Timer;
public class Stage extends JPanel implements ActionListener
{
private static final long serialVersionUID = 1L;
private Timer start_stop;
private SPRITES player;
public Stage()
{
addKeyListener(new TAdapter());
setFocusable(true);
setBackground(Color.black);
setDoubleBuffered(true);
player = new SPRITES();
start_stop = new Timer(5, this);
start_stop.start();
}
public void paint(Graphics character)
{
super.paint(character);
Graphics2D G2D = (Graphics2D) character;
G2D.drawImage(player.getImage(), player.getX(), player.getY(), this);
Toolkit.getDefaultToolkit().sync();
character.dispose();
}
public void actionPerformed(ActionEvent arg0)
{
player.move();
repaint();
}
private class TAdapter extends KeyAdapter
{
public void keyReleased(KeyEvent e)
{
player.keyReleased(e);
}
public void keyPressed(KeyEvent e)
{
player.keyPressed(e);
}
}
}
This last one should tie it all together...granted I knew how to fix the exception.
import javax.swing.JFrame;
#SuppressWarnings("serial")
public class Framing extends JFrame
{
public Framing()
{
add(new Stage());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(600, 600);
setLocationRelativeTo(null);
setTitle("FLY");
setResizable(false);
setVisible(true);
}
public static void main(String[] args)
{
new Framing();
}
}
What is causing these exceptions to happen? How can I fix the problem and what should I work on to avoid this happening again?
I think you are misreading the stacktrace from eclipse. All the links except for the first(The one at the top) is the call stack, which show the calls made to the place where you got a nullpointer exception.
Which fit because the code:
new Framing()
Calls
add(new Stage())
which calls
player = new SPRITES();
Which calls
ImageIcon pine = new ImageIcon(this.getClass().getResource("Untitled.png"));
And this is where your nullpointer exception is. My guess is that getResources("Untitled.png"); returns null which then causes the ImageIcon constructor to throw a nullpointer exception.
I'm trying to get a simple sprite moving around my screen. I can't get my head around what is wrong with this code as i've followed instructions from a different source code but removed some complexity added from other features in other code.
Right now I'm just trying to get it to move around freely on the screen.
Later I intend for the animation to change while its moving.
Code for both classes is below.
package game;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.Timer:
public class Game extends JPanel implements ActionListener {
int x, y, b_width, b_height;
Player player;
Timer timer;
public Game() {
addKeyListener(new KeyRecorder());
player = new Player();
timer = new Timer(5, this);
timer.start();
}
public void paint(Graphics g){
g.drawImage(player.image, player.getX(), player.getY(), this);
}
#Override
public void actionPerformed(ActionEvent e) {
player.move();
repaint();
}
public class KeyRecorder extends KeyAdapter{
public void keyPressed(KeyEvent e){
player.keyPressed(e);
repaint();
}
public void keyReleased(KeyEvent e){
player.keyReleased(e);
}
}
}
And the sprite:
package game;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
public class Player {
private String sprite = "sprite.png";
int x, y, dx, dy;
int width, height;
Image image;
public Player() {
ImageIcon ii = new ImageIcon(this.getClass().getResource(sprite));
image = ii.getImage();
}
public int getX(){
return x;
}
public int getY(){
return y;
}
public void move() {
x = x + dx;
y = y + dy;
}
public void keyPressed(KeyEvent e){
int key = e.getKeyCode();
if(key == KeyEvent.VK_UP){
dy -= 3;
}
if(key == KeyEvent.VK_DOWN){
dy += 3;
}
if(key == KeyEvent.VK_LEFT){
dx -= 3;
}
if(key == KeyEvent.VK_RIGHT){
dx += 3;
}
}
public void keyReleased(KeyEvent e){
int key = e.getKeyCode();
if(key == KeyEvent.VK_UP){
dy -= 0;
}
if(key == KeyEvent.VK_DOWN){
dy += 0;
}
if(key == KeyEvent.VK_LEFT){
dx -= 0;
}
if(key == KeyEvent.VK_RIGHT){
dx += 0;
}
}
}
Custom painting is done by overriding the paintComponent() method, not the paint() method.
KeyEvents are only received by comonents with focus. It doesn't look like you panel has focus. In the constructor you need to add:
setFocusable(true);
I don't know a huge amount about swing, but are you calling "repaint()" for every frame you want drawn? For example
thePanel.repaint();
If it flickers, you may also want to set the panel to double buffered
setDoubleBuffered(true);
I hope those helps you anyway. If that doesn't answer your question, perhaps this will http://docs.oracle.com/javase/tutorial/uiswing/painting/ I don't have time to read through it but I did skim it and it looks good.
I'm currently tying to make my first game in java, i had successfully made a side scrolling game until i wanted to change the map (the background) a bit bigger. I started experiencing a strange problem with the background image.
it worked just fine with resolutions of up to and including 5250px x 5148px.
If I exceed this the image simply failed to display.
I've tried reducing the file size but images above this resolution still fail to display regardless of file size.
My game consists of three files
Frame, Dude and Board, they are as followed
Frame.java
package OurGame;
import javax.swing.*;
public class Frame {
public static void main(String[] args)
{
JFrame frame = new JFrame("Game");
frame.add(new Board());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(500,500);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
}
Dude.java
package OurGame;
import java.awt.Image;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
public class Dude {
int x, dx, y, dy, nx2, ny2;
Image still;
public Dude()
{
ImageIcon i = new ImageIcon("/Users/Connor/Desktop/square.jpg");
still = i.getImage();
x = 250;
y = 250;
nx2 = 485;
ny2 = 485;
}
public void move()
{
x = x + dx;
y = y + dy;
nx2 = nx2 + dx;
ny2 = ny2 + dy;
}
public int getX()
{
return x;
}
public int getY()
{
return y;
}
public Image getImage()
{
return still;
}
public void keyPressed(KeyEvent e)
{
int key = e.getKeyCode();
if(key == KeyEvent.VK_A)
{
dx = -1;
}
if(key == KeyEvent.VK_D)
{
dx = 1;
}
if(key == KeyEvent.VK_W)
{
dy = -1;
}
if(key == KeyEvent.VK_S)
{
dy = 1;
}
}
public void keyReleased(KeyEvent e)
{
int key = e.getKeyCode();
if(key == KeyEvent.VK_A)
{
dx = 0;
}
if(key == KeyEvent.VK_D)
{
dx = 0;
}
if(key == KeyEvent.VK_W)
{
dy = 0;
}
if(key == KeyEvent.VK_S)
{
dy = 0;
}
}
}
Board.java
package OurGame;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Board extends JPanel implements ActionListener{
private static final long serialVersionUID = 1L;
Dude p;
Image img;
Timer time;
public Board()
{
p = new Dude();
addKeyListener(new AL());
setFocusable(true);
ImageIcon i = new ImageIcon("/Users/Connor/Desktop/background.jpg");
img = i.getImage();
time = new Timer(5, this);
time.start();
}
public void actionPerformed(ActionEvent e)
{
p.move();
repaint();
}
public void paint(Graphics g)
{
super.paint(g);
Graphics2D g2d = (Graphics2D) g;
g2d.drawImage(img, 485-p.nx2, 485-p.ny2, null);
g2d.drawImage(p.getImage(), 200, 200, null);
}
private class AL extends KeyAdapter
{
public void keyReleased(KeyEvent e)
{
p.keyReleased(e);
}
public void keyPressed(KeyEvent e)
{
p.keyPressed(e);
}
}
}
I'm kind of a beginner when it comes to java programming, and I have a project in school where I'm going to create a game much like Icy Tower. And my question is, how am I going to write to make the character stand on the ground and be able to jump up on objects?
Here's my code so far:
Part one
package Sprites;
import java.awt.Image;
import java.awt.event.KeyEvent;
import javax.swing.ImageIcon;
public class jumper {
private String jump = "oka.png";
private int dx;
private int dy;
private int x;
private int y;
private Image image;
public jumper() {
ImageIcon ii = new ImageIcon(this.getClass().getResource(jump));
image = ii.getImage();
x = 50;
y = 100;
}
public void move() {
x += dx;
y += dy;
}
public int getX() {
return x;
}
public int getY() {
return y;
}
public Image getImage() {
return image;
}
public void keyPressed(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = -5;
ImageIcon ii = new ImageIcon(this.getClass().getResource("oki.png"));
image = ii.getImage();
}
if (key == KeyEvent.VK_RIGHT){
dx = 5;
ImageIcon ii = new ImageIcon(this.getClass().getResource("oka.png"));
image = ii.getImage();
}
if (key == KeyEvent.VK_SPACE) {
dy = -5;
}
if (key == KeyEvent.VK_DOWN) {
dy = 5;
}
}
public void keyReleased(KeyEvent e) {
int key = e.getKeyCode();
if (key == KeyEvent.VK_LEFT) {
dx = 0;
}
if (key == KeyEvent.VK_RIGHT){
dx = 0;
}
if (key == KeyEvent.VK_SPACE) {
dy = 0;
}
if (key == KeyEvent.VK_DOWN) {
dy = 0;
}
}
}
Part two
package Sprites;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import javax.swing.JPanel;
import javax.swing.Timer;
public class board extends JPanel implements ActionListener {
private Timer klocka;
private jumper jumper;
public board() {
addKeyListener(new TAdapter());
setFocusable(true);
setBackground(Color.WHITE);
setDoubleBuffered(true);
jumper = new jumper();
klocka = new Timer(5, this);
klocka.start();
}
public void paint(Graphics g) {
super.paint(g);
Graphics2D g2d = (Graphics2D)g;
g2d.drawImage(jumper.getImage(), jumper.getX(), jumper.getY(), this);
Toolkit.getDefaultToolkit().sync();
g.dispose();
}
public void actionPerformed(ActionEvent e) {
jumper.move();
repaint();
}
private class TAdapter extends KeyAdapter {
public void keyReleased(KeyEvent e) {
jumper.keyReleased(e);
}
public void keyPressed(KeyEvent e) {
jumper.keyPressed(e);
}
}
}
Part three
package Sprites;
import javax.swing.JFrame;
public class RType extends JFrame {
public RType() {
add(new board());
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(800, 600);
setLocationRelativeTo(null);
setTitle("R - type");
setResizable(false);
setVisible(true);
}
public static void main(String[] args) {
new RType();
}
}
I really appreciate all the help I can get!
This might help. It's a set of tutorials aimed at helping people make tile-based games. Including side-on platform games. See http://www.tonypa.pri.ee/tbw/tut07.html. By the way, you're doing quite intensive image-loading stuff in the character movement methods. Don't do that. Cache the images first. Also, you can double-buffer your Canvas to make it smooth. See the code here for details.