Author Topic: Java Game Developing  (Read 1817 times)

And that is exaactly what he wanted.
I took it as he was asking what language to program in.
Should I attemp flash Java or C++?

Okay, I figured out how to open a window, throw a picture in there. Why isnt my character showing up?

Code: (Main) [Select]
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);
Code: (char) [Select]
public Character(){
ImageIcon i = new ImageIcon("c:\\mushroomm");
still = i.getImage();
x = 10;
y = 172;

Pretty sure "c:\\mushroomm" isn't a valid file path. It should be more like "Root folder//charecters//mushroomm"

... I think.

I'm going to be helping edman with this! :D


RpG's are pretty complex, good luck lol.

Pretty sure "c:\\mushroomm" isn't a valid file path. It should be more like "Root folder//charecters//mushroomm"

... I think.

Pretty sure thats not it, retiring for the night. Hopefully tomorrow I can put up an actual topic about gameplay and such.

Java is an excellent learning language if you're just starting. Start in Java and then build your way to other languages.

I recommend NetBeans as an IDE for Java.

Okay, I figured out how to open a window, throw a picture in there. Why isnt my character showing up?

You need to set the window's visibility to true and also redraw the image showing on the window to initialize it/update it whenever it changes.

Java is an excellent learning language if you're just starting. Start in Java and then build your way to other languages.

I recommend NetBeans as an IDE for Java.
Im currently in Eclipse. I feel this was way over hyped becauses minecraft was made on it.

You need to set the window's visibility to true and also redraw the image showing on the window to initialize it/update it whenever it changes.

I have that done, I just the char just doesn't paint.

Code incoming:

Code: (Main.java) [Select]
package Sider;

import java.awt.*;
import java.awt.event.*;


import javax.swing.*;

public class MainC extends JPanel implements ActionListener{
Character p;
Image img;
Timer time;

public MainC() {
p = new Character();
addKeyListener(new AL());
setFocusable(true);
ImageIcon i = new ImageIcon("c:/untitled.png");
img = i.getImage();
time = new Timer (5, this);
time.start();
}
public void actionPerformed (ActionEvent e){
repaint();
p.move();
}
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);
}

private class AL extends KeyAdapter{
public void keyReleased(KeyEvent e) {
p.keyReleased(e);
}
public void keyPressed(KeyEvent e){
p.keyPressed(e);
}
}
}
Code: (Character.java) [Select]
package Sider;

import java.awt.Image;
import java.awt.event.KeyEvent;

import javax.swing.ImageIcon;

public class Character {
int x, dx, y;
Image still;

public Character(){
ImageIcon i = new ImageIcon("C:\\character");
still = i.getImage();
x = 80;
y = 160;
}
public void move(){
x = x + dx;
}
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_LEFT)
{dx = -1;}

if (key == KeyEvent.VK_RIGHT){
dx = +1;}
}
public void keyReleased(KeyEvent e){
int key = e.getKeyCode();

if (key == KeyEvent.VK_LEFT)
{dx = 0;}

if (key == KeyEvent.VK_RIGHT){
dx = 0;}
}
}

I saw the PM you sent me, but I can't respond to them. Add me on Steam. I have an exam in half an hour so I'll be on later.

You don't need to import everything from the AWT/Swing libraries. Import only what you need, the rest will just bog down your code.

Still doesnt show up :C