Slick Forums

Discuss the Slick 2D Library
It is currently Wed May 22, 2013 1:09 am

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: Thu Jul 21, 2011 6:29 am 
Offline

Joined: Thu Jul 21, 2011 6:01 am
Posts: 4
I've been having some problems getting a color at a specific pixel and am starting to believe there may be a bug. The image I'm using (bg1.png) is a transparent PNG with a solid black rectangle in the middle. It's original dimensions are 1440x900, but I'm scaling it to 800x500 to fit in my window. When I click on the image, it consistently prints "Color(1.0, 1.0, 1.0, 0.0)", no matter where I click. Here are some snippets:

Init:
Code:
public void init( GameContainer container ) throws SlickException
   {
      container.getGraphics().setBackground( Color.magenta );
      input = container.getInput();
      
      // Set up the first scene
      background = (new Image( "assets/bg1.png" )).getScaledCopy( 800, 500 );
   }


Render:
Code:
public void render( GameContainer container, Graphics g )
         throws SlickException
   {
      background.draw( 0f, 0f );
   }


Update:
Code:
public void update( GameContainer container, int delta )
         throws SlickException
   {
      
      if( input.isMousePressed( Input.MOUSE_LEFT_BUTTON ) )
      {
         int x = input.getAbsoluteMouseX();
         int y = input.getAbsoluteMouseY();
         Color c = background.getColor( x, y );
         
         // Test it out
         System.out.println( c );
      }

   }


I think this is a bug with scaled images. I tested this without scaling the image, and it worked just fine.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2011 7:42 am 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Yes well, I'mt not sure is this is really a bug... getscaledCopy, really just gives you a copy with new width and height do draw (for the vertex stuff). And getColor just tries to take it from the normal pixelData of the image (It's really big tho, my netbook could not handle such a big picture...)

So I'm not sure if this is really a bug or you need to calculate the scale for the mouse position yourself to make it work.

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2011 3:06 pm 
Offline

Joined: Thu Jul 21, 2011 6:01 am
Posts: 4
Sorry about that. I guess that would definitely be the problem. I should have looked at the code more before I posted. Should I delete this post, or is there a way to close it?

Edit: Off topic, but how can I contribute code to Slick? I wanted to use BigImage, but it didn't have the functionality I wanted built in. I'm thinking of just editing it, but who should I send the patch to?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 21, 2011 6:46 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Nobody I guess11 you can post in the Bigs/RFE sub-forum an key might add it.

And leave it open, it harms no one xD

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2011 10:54 pm 
Offline
Site Admin
User avatar

Joined: Thu Jan 01, 1970 12:00 am
Posts: 3143
Post a patch here and I'll add it as soon as I get time. Obviously I don't have the time I used to (mostly due to my current projects) but I'll still be supporting/fixing/patching where I can.

Kev


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 22, 2011 11:29 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
Oh well then I have something for you in the future, which will surely make some people happy^^

_________________
Current Projects:
Image Mr. Hat I
Image Vegan Vs. Zombies
Projects:
RadicalFish Engine - Build on top of Slick2D, Ideas, Bugs? Open an Issue ticket!


Top
 Profile  
 
PostPosted: Sat May 12, 2012 9:31 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1469
Since the backing texture is not resampled, scaled copies won't work with getCopy. If you need to get the pixel data from a resampled image, copy the data to a new (resampled/resized) texture and sample that.

I'll put this in the resolved forum for now.


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

All times are UTC


Who is online

Users browsing this forum: No registered users 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