Slick Forums

Discuss the Slick 2D Library
It is currently Fri May 24, 2013 8:04 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Image loading issue?
PostPosted: Mon Mar 19, 2012 12:54 am 
Offline

Joined: Mon Mar 19, 2012 12:04 am
Posts: 2
Hello, I am relatively new to Slick and have been working with it to see if I can start a basic game using it, but I have already gotten myself stuck. When working on making some classes for my game, I started working on a basic Actor class that could be inserted into the game world and move around and such. This class has an image associated with it, and the engine loops through all game Actors and has each one draw it's object onto the screen. Whenever I directly create Images in my Basic Game class, calling the draw(x,y) method for them successfully draws them onto the canvas. Unfortunately whenever I have the Actors draw their images, nothing appears.

I do know that the methods are being called properly, so it isn't a case of other code preventing the draw() method from running. I do not, however, know what Slick means when it outputs this to the console:
Code:
Sun Mar 18 17:08:59 PDT 2012 INFO:Offscreen Buffers FBO=true PBUFFER=true PBUFFERRT=false
Sun Mar 18 17:08:59 PDT 2012 DEBUG:Creating FBO 297x171

I imagine it has to do with image initialization, but despite my searching I haven't managed to figure out if it is the result of an error or incompatibility of some sort. This text is *not* output whenever I initialize my Images using the regular Image(name) constructor inside of my Basic Game class, but the text *does* appear whenever my image is initialized in my Actor constructor. Are there certain conditions for initialization that I am not meeting?

Any help is appreciated :D


Top
 Profile  
 
 Post subject: Re: Image loading issue?
PostPosted: Mon Mar 19, 2012 12:54 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
That text appears when you call Image.getGraphics. Once you ask for the Image graphics, you need to flush it to "disable" it before trying to render things to the screen.

For example:
Code:
Image myImage = new Image("blah.jpg");
Graphics g2 = myImage.getGraphics();
//... you can draw some stuff here ...//

//then flush/disable the graphics
g2.flush();


Image graphics are usually a little costly to create, so you should try to reuse them if possible (or not use them at all if it isn't necessary).

Note: If you are creating new images by a given size -- as in new Image(width, height) -- then keep your eyes open for the following new method (currently part of the Slick development branch on Bitbucket, will be pushed to the main release soon):
Code:
Image img = Image.createOffscreenImage(width, height);


It's more efficient and won't cause any memory leaking.


Top
 Profile  
 
 Post subject: Re: Image loading issue?
PostPosted: Tue Mar 20, 2012 5:58 pm 
Offline

Joined: Mon Mar 19, 2012 12:04 am
Posts: 2
Oooh okay, I was unaware that creating a Graphics had that kind of effect, thank you a lot for your help!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: Bing [Bot] and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group