Slick Forums

Discuss the Slick 2D Library
It is currently Mon Apr 21, 2014 4:31 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Thu Oct 20, 2011 8:38 pm 
Offline
Oldbie
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
It's simple, I expected texture width as closest larger power of 2 value of image width and height.
Instead it returns ratio, this is from init where it is set:
Code:
   protected final void init() {
      if (inited) {
         return;
      }
      
      inited = true;
      if (texture != null) {
         width = texture.getImageWidth();
         height = texture.getImageHeight();
         textureOffsetX = 0;
         textureOffsetY = 0;
         textureWidth = texture.getWidth(); // WRONG, its' texture.getTextureWidth();
         textureHeight = texture.getHeight(); // WRONG, it's texture.getTextureHeight();
      }
      
      initImpl();
   
      centerX = width / 2;
      centerY = height / 2;
   }


So either above code in Image is incorrect or getWidth() and getHeight() from TextureImpl class:
Code:
    public float getWidth() {
        return widthRatio;
    }


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 20, 2011 9:28 pm 
Offline
Game Developer
User avatar

Joined: Thu Mar 03, 2011 6:22 pm
Posts: 534
This is not a bug, because it works as expected :) Just have a quick peak at the SpriteSheet class e.g. :) There you can see that it makes sense since it will be used for sub images... or I don't understand the bug :D

_________________
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 Oct 21, 2011 1:38 am 
Offline
Oldbie
User avatar

Joined: Fri Jul 20, 2007 9:25 am
Posts: 410
Location: Croatia
If its not a bug can someone explain the logic behind it? When you have a texture and you ask for width.. how can you expect to get width ratio? Don't get the logic there. Width and height of image (and thus textures) are so clearly defined, doesn't involve any ratios at all.

Also note that method Image.getTextureWidth() has same name as Texture.getTextureWidth() but they return different things... this must be a bug.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 02, 2011 11:54 pm 
Offline
User avatar

Joined: Mon Jun 20, 2011 4:28 pm
Posts: 71
at the very least it violates the principle of least astonishment...

Quote:
getWidth
float getWidth()
Get the width of the physical texture

Returns:
The width of physical texture


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 03, 2011 8:11 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
Not really a bug, but an annoying inconsistency. ShapeRenderer relies on Image.getTextureWidth/Height for the ratio, so that would need to be changed.

Ideally Texture.getImageWidth/Height should be replaced with more standardized naming:
- The width/height property should refer to the unmodified pixel width/height (e.g. 250x250)
- The textureWidth/textureHeight property should refer to the modified, power of two width/height (e.g. 256x256)
- A new property, e.g. widthRatio/heightRatio, should refer to the ratio (e.g. 0.9765625).


Top
 Profile  
 
PostPosted: Sat May 12, 2012 5:08 am 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
Added clearer documentation to Texture/Image regarding what values will be returned with these methods.

EDIT: Bah, on a different computer than usual and running into push errors... Will update tomorrow.
EDIT2: Pushed.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 0 guests


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