Q1: I've been trying to set background images on each location in the grid that won't be destroyed after an actor is placed in their location, but it's driven me to trying to create my own grid that I can place objects on (there's tons that work for components but I can't find anything for regular old objects). I can't seem to get this new grid to allow me to place objects in each square so I'm reverting back to grid world. Is there any way to place an object behind an actor on gridworld? This object won't need the ability to move or act or anything.
tl;dr: How can I place two objects in one location and keep the ability to move on one of them?
Grid World Mod
Page 1 of 17 Replies - 3956 Views - Last Post: 07 June 2012 - 03:37 PM
Replies To: Grid World Mod
#2
Re: Grid World Mod
Posted 05 June 2012 - 08:42 PM
Moved to GridWorld.
Without modifying the GridWorld GUI classes, this is not possible. You would have to deal with a JLayeredPane, most likely, or perhaps custom painting (though doubtful). If you aren't familiar with the Java GUI, I wouldn't try and attack this one. GridWorld itself is designed to teach people basic OOP, not to be expanded as an intensive game engine.
Without modifying the GridWorld GUI classes, this is not possible. You would have to deal with a JLayeredPane, most likely, or perhaps custom painting (though doubtful). If you aren't familiar with the Java GUI, I wouldn't try and attack this one. GridWorld itself is designed to teach people basic OOP, not to be expanded as an intensive game engine.
#3
Re: Grid World Mod
Posted 05 June 2012 - 08:49 PM
Thanks. And crap. This is supposed to be my final project for the year, I guess I'll either have to figure out how to make a grid that I can do this with or start over. Back to the drawing board =\.. 3 days til it's due!
#4
Re: Grid World Mod
Posted 05 June 2012 - 08:53 PM
Are you familiar with the Swing GUI at all? Just extend JPanel and override the paintComponent() method. Draw the grid yourself using the Graphics drawLine() method, then draw the Images as well using the Graphics drawImage() method.
#5
Re: Grid World Mod
Posted 05 June 2012 - 09:38 PM
This isn't working out.
This prints one Infantry.jpg image in the top left corner.
JFrame win;
Container contentPane;
Graphics g;
MyPanel panel1, panel2, panel3, panel4;
win = new JFrame("My First Graphics - Christmas");
win.setSize(260,280);
win.setLocation(200,100);
win.setVisible(true);
contentPane = win.getContentPane();
g = contentPane.getGraphics();
panel1 = new MyPanel();
contentPane.add(panel1);
panel2 = new MyPanel();
contentPane.add(panel2);
panel3 = new MyPanel();
contentPane.add(panel3);
panel4 = new MyPanel();
contentPane.add(panel4);
g.setColor(new Color(0,0,0));
for (int i = 50; i < 250; i += 50)
{
g.drawLine(0,i,300,i);
g.drawLine(i,0,i,300);
}
class MyPanel extends JPanel
{
public void paintComponent(Graphics g) {
Image image = new ImageIcon("Infantry.jpg").getImage();
g.drawImage(image,0,0,this);
}
}
This prints one Infantry.jpg image in the top left corner.
#6
Re: Grid World Mod
Posted 05 June 2012 - 10:04 PM
I don't mean to be rude, but this looks like you haven't worked with the Java GUI much. With three days left and given where you seem to be, this is an ambitious project.
Rather than creating multiple MyPanel objects and using getGraphics(), which isn't good practice, let's just use one JPanel and store the Images there. As for the position of the Image, the coordinate (0,0) is the top left corner of the screen.
Hopefully the above skeleton will help you decompose the problem and organize your code some.
Rather than creating multiple MyPanel objects and using getGraphics(), which isn't good practice, let's just use one JPanel and store the Images there. As for the position of the Image, the coordinate (0,0) is the top left corner of the screen.
class MyPanel extends JPanel{
private List<Image> images; //the images to paint
public MyPanel(){
//initialize images
}
public void paintComponent(Graphics g){
super.paintComponent(g); //handle key super-class functionality
drawGrid(g);
drawImages(g);
}
public void drawGrid(Graphics g){}
public void drawImages(Graphics g){}
}
Hopefully the above skeleton will help you decompose the problem and organize your code some.
#7
Re: Grid World Mod
Posted 06 June 2012 - 11:10 PM
Yeah, graphics weren't a big part of the course I'm taking that's why I opted for gridworld at first.
I've reverted back to gridworld and just left out the part I was struggling with earlier. Thanks fo ya help, mate.
I've reverted back to gridworld and just left out the part I was struggling with earlier. Thanks fo ya help, mate.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote







|