foxblock / penjin

Penjin game engine - C++, cross-platform, powerful, simple to use
http://projectinfinity.org.uk/doku.php?id=homebrew:engines:penjin
GNU Lesser General Public License v3.0
0 stars 1 forks source link

Image::GetPixel does not take sprite sheets / clipping areas into account #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Using Image::GetPixel(x,y) will return the pixel at x,y position of the loaded 
image, but when using the following function:
loadImageSheet(SDL_Surface *surface,CRuint xTiles,CRuint yTiles,CRuint 
skipTiles,CRuint numTiles)
Part of the image might be cut off due to clip area creation when skipTiles is 
non-zero (so it is still in memory, just not taken into account for drawing, 
etc.).
GetPixel then still returns the pixel of the whole image, not the part which 
has been loaded.

The same probably goes for the SetPixel functions and maybe others

Proposed solution: This is a tricky one, don't know whether it can be solved in 
Image altogether, probably needs correction from the outside as changes here 
could mess up other stuff.
The resulting image (minus the cut-off part) is not necessarily rectangular so 
making GetPixel check for an offset won't always work.

Original issue reported on code.google.com by foxbl...@gmail.com on 8 Nov 2010 at 7:03

GoogleCodeExporter commented 9 years ago
GetPixel also does behave strangely on sprite sheets as you cannot specify a 
frame to get the pixel from, but can actually get pixels from out of bounds 
(seen from a spritesheets pov where the image is actually just as big as one 
frame).
So another option would be to add a
GetPixel(int x, int y, int frameNo) function, which returns the pixel in frame 
#frameno.
But then I would opt for making the frameNo parameter option (with default 
value 0) and adding a function
GetPixelFromWholeImage(int x, int y) which gets a pixel from the whole image 
rather the frame (name subject to change).

The changes GetPixel function would still behave as usual on non-spritesheets 
as the default parameter for the frameNo is 0, which then refers to the whole 
image.

Original comment by foxbl...@gmail.com on 8 Nov 2010 at 8:54

GoogleCodeExporter commented 9 years ago
The only initial thought I have is that we could store xTiles and yTiles, the 
offset of each tile and we already have a tileSheet variable.
With this information the getPixel and setPixel functions could take into 
account the current tile that is accessible.
As mentioned an alternative function could provide full sheet access to pixels.

Original comment by pokeparadox@gmail.com on 9 Nov 2010 at 12:42