[ad_1]
Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –
Java Game Development – 7 – Loading Images
by
Tags:
Comments
47 responses to “Java Game Development – 7 – Loading Images”
-
the pinnacle of photoshop
-
How do you make all of the drawn elements fit the resized screen? s there not an easier way than using the many parameters in drawImage()?
-
The background image does not comes up. How to fix this issue?
-
For me this sounds a bit stupid. You wont be able to load these pictures anywhere else than on this computer. why dont you load them from a resource folder in your project?
-
For mac users – /Users/"Your username"/Desktop/test/back.jpg – for the address of pictures.
-
Do I have to use photoshop
-
didn't worked.
|
here |
/
import javax.swing.*;
import javax.swing.ImageIcon;
import java.awt.*;public class Image extends JFrame {
public static void main(String[] args) {
Thread t1 = new Thread(new Apple("Slava"));
Thread t2 = new Thread(new Apple("Dima"));
Thread t3 = new Thread(new Apple("Mom"));
t1.start();
t2.start();
t3.start();DisplayMode dm = new DisplayMode(800,600,16,DisplayMode.REFRESH_RATE_UNKNOWN);
Image i = new Image();
i.run(dm);
}private Screen s;
private java.awt.Image bg;
private java.awt.Image pic;
private boolean loaded;public void run(DisplayMode dm){
setBackground(Color.PINK);
setForeground(Color.RED);
setFont(new Font("Arial", Font.PLAIN, 24));
loaded = false;
s = new Screen();
try{
s.setFullScreen(dm, this);
loadpics();
try{
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}catch(Exception e){}
}finally{
s.restoreScreen();
}}
private void loadpics() {
bg = new ImageIcon("res\back.png").getImage();
pic = new ImageIcon("res\face.png").getImage();
loaded = true;
repaint();
}public void paint(Graphics g){
if(g instanceof Graphics2D){
Graphics2D g2 = (Graphics2D)g;
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);}
if(loaded){
g.drawImage(bg, 0, 0 ,null);
g.drawImage(pic, 170, 180, null);
}
}
}can anybody help me?
-
For those having problems with the background not resizing to fullscreen change the:
g.drawImage(bg,0,0,null);to the following code:
g.drawImage(bg,0,0,s.getFullScreenWindow().getWidth(),s.getFullScreenWindow().getHeight(),0,0,bg.getWidth(null),bg.getHeight(null),null);it should now resize the background to fit your screen.
-
the "bg" comes up as a mini image and not the background
-
is is worth it to stick through this playlist if each video has errors due to java updates?
-
the issue why it won't work for some of you is probably pathing. If you have a folder "workspace" which Eclipse makes itself, go in there, enter the Project name of your Java game developement, paste images there and change pathing to just :
bg = new ImageIcon("background800by600.jpg").getImage();
pic = new ImageIcon("bicon100by100.png").getImage(); -
died when you said swine flu
-
Its not working for me :/
Maybe I don't have the right path setup because I'm running Ubuntu 15.04
All I see is the pink background -
Works everything fine. I installed jdk 1.8.0_45 instead 1.7 and changed default location of JRE in Eclipse to jre1.8.0_45.
-
"Sorry. Swine flu."
-
Fixed probs!
-
All I get is a black screen, why is this???
-
im getting an error when i do the private Screen s;
did i forget to import something or am i just doing something wrong? -
i need some help! when i run the program is gives me this error:
Exception in thread "main" java.lang.NullPointerException
at Images.run(Images.java:38)
at Images.main(Images.java:13)
also that i don't have the restoreScreen function so i substituted it for returnScreen -
HAHA Swine Flu
-
another ways to load images:
bg = Toolkit.getDefaultToolkit().getImage("back.jpg"); // put image in the project folder
bg = new ImageIcon(getClass().getResource("back.jpg")).getImage(); // put image in src / <name_of_project> / -
no syntax errors but just the pink screen :/
-
This is a bit outdates. Can you do an updated series?
-
Awesome, this worked brilliantly. We were given a template to work from but I didnt really understand most of it. I much rather this method were I can understand how it works a lot easier
-
Why do people pronounce png as ping? There's no i in there. If anything it should be pong.
-
"Image" is coming back as an unknown type. I did include ImageIcon, so I don't see what the problem is…………
-
I have a question.
For some reason, even if the code is 100% same as Bucky's , I get errors as certain lines such as "s.setFullScreen(dm,this);" (-line 27).
I re-wrote all error lines like 5 times then I rewrote the entire code but the error persists.
I tried to remove the line but when I press "run" it tells me there are errors but shows an empty list.
Any ideas?
-
My Background image (800×600, png) isn't going to full screen. Is this normal?
P.S.: Bucky RULES!
-
how to make an image without background
-
Don't foget to put the projectmap in the loacation
C:\map\projectmap\image.jpg
NOT
C:\map\image.jpg -
Just spend about 2 days trying to load those stupid images then I finally came back here and bang! in less then a minute my spaceship was visible THX once again if I had spare money I would send you some 😀
-
I just wanted to repost something that was said by Tom Christensen that helped me solve my exception error.
I got a nullpointerexception error. I changed the private screen s to Screen s = new Screen(); and it worked fine. -
I am facing a problem that screen is blinking a lot. How can I fix this issue?
-
Thank you sir, it works on my netbeans from my mac 🙂
-
love your videos!
-
Please any one how do I insert my .PNG image when Im on mac
-
Nah it's like gif, people pronounce it with a soft and hard g, so gif or jiff. Since these are acronyms anyway, there's not really a universally accepted way to pronounce them.
I pronounce it pee en gee though. -
just put .jpg instead, it read it correctly for me then.
-
jpeg not supported? -.-
-
a ping?? why don't you call it a P(ee) e(N) G(ee) ??
or is this the way to pronounce it in america?
-I'm from belgium and we pronounce PNG by saying each letter.. -
i had the same problem with my mac eclipse. i switched "\" for "//"
-
No
-
Comment the whole class out or remove the main method
-
wouldn't it be easier to do:
public void loadpics(Image i, String path) {
i = new ImageIcon(path).getImage()
} -
Using png or gif image format, you can create a transparent background. Don't think you can with jpeg
-
If you are using netbeans you can create a new package and then store them in that. If you have your images stored a level above the class you are using to load them you need to use ".." before the first "" to step up a level.
-
sorry..its in my res folder still its not working
Leave a Reply