Slick Forums

Discuss the Slick 2D Library
It is currently Wed Nov 20, 2019 12:32 pm

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: Graphical glitch
PostPosted: Sat Dec 29, 2012 9:16 am 
Offline

Joined: Sat Dec 29, 2012 8:44 am
Posts: 4
I'm making a 2D top-down omnidirectional shooter, so my (placeholder) player image can rotate in any direction (via Image.setRotation()) based on controller joystick position. Here's what's going wrong:

Image

At certain angles, random pixels are visible along the edges of the image. I figured they were part of another image I was using, so I tried rounding/casting the coordinates (floats) of the image to int before rendering, but that didn't work. Also tried rounding the angle of rotation, without success.

The raw image:
Image

The image above just shows it being rotated against a white background.

Code:
// init
Image player = new Image(...);
Image background = new Image(...); // just a white image

// render
g.drawImage(background, 0-cameraX, 0-cameraY);
g.drawImage(player, Math.round(x-cameraX-player.getWidth()/2), Math.round(y-cameraY-player.getHeight()/2));
// player.draw(Math.round(x-player.getWidth()/2), Math.round(y-player.getHeight()/2)); // same result

// update
player.setRotation(... controller joystick angle);

That's literally all I'm doing. It seems really straightforward but I just can't get it to render properly. I am quite new to Slick and 2D rendering, so please tell me if I've missed something really obvious. :| Thanks in advance.


Top
 Profile  
 
 Post subject: Re: Graphical glitch
PostPosted: Sat Dec 29, 2012 3:37 pm 
Offline
Regular
User avatar

Joined: Sun Feb 06, 2011 11:59 pm
Posts: 107
Location: USA
I think your problem is described in passing on this thread, though it is technically about zooming: http://www.java-gaming.org/topics/bleed ... #msg237162

The most important line:

Quote:
This problem may also manifest itself if you're loading non-power-of-two textures with Slick/SlickUtil. In that case, Slick pads the extra dimensions (to make it power of two) with transparent black pixels. Therefore bleeding on the bottom/right edges may occur using GL_LINEAR, even if the scale is unchanged.


Try remastering your sprite to 64x64 and see if that helps.

_________________
"When you break the big laws, you do not get freedom; you do not even get anarchy. You get the small laws."
-GK Chesterton


Top
 Profile  
 
 Post subject: Re: Graphical glitch
PostPosted: Sat Dec 29, 2012 7:39 pm 
Offline
Slick Zombie

Joined: Sat Jan 27, 2007 7:10 pm
Posts: 1482
It may be due to using non-power-of two textures. For better performance you should pack your textures into a power-of-two sprite sheet, instead of using a single texture per sprite. ;)

It may also be because of linear sampling. This is a common problem for 2D OpenGL games -- see here for details.

Common solutions for the problem:
- Use Image.FILTER_NEAREST when creating your images
- Pad your sprite sheets with 1-2px transparent white pixels
- Cast coordinates to an int before rendering


Top
 Profile  
 
 Post subject: Re: Graphical glitch
PostPosted: Sun Dec 30, 2012 1:45 am 
Offline
Regular

Joined: Wed Dec 09, 2009 6:56 pm
Posts: 135
The simplest solution is add a 1 pixel margin around your sprite consisting of transparent pixels. This phenomenon only appears to occur if you rotate a sprite.


Top
 Profile  
 
 Post subject: Re: Graphical glitch
PostPosted: Mon Dec 31, 2012 2:36 am 
Offline

Joined: Sat Dec 29, 2012 8:44 am
Posts: 4
Making the image 64x64 fixed it. Thanks so much for all the help - I'll keep everything you guys said in mind.

To detract a little from the original problem, I originally used oddly-sized sprites so I could create collision boxes based on image dimensions. Now that I'm going to use a sprite sheet with fixed-size tiles, I need a different way to handle collision, so I was thinking of 1. setting dimensions of individual sprite collision boxes with constants, or 2. using bitmasks for per-pixel collision. Is 2. overly complicated, and worth the performance overhead?


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

All times are UTC


Who is online

Users browsing this forum: MSN [Bot] and 231 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:  
cron
Powered by phpBB® Forum Software © phpBB Group