2D Toolkit Forum
2D Toolkit => Support => Topic started by: Neeko on April 06, 2014, 11:38:39 pm
-
This is probably a real noob question, but humor as we all have to learn sometime!
I have a sprite collection setup like so
(http://chattypics.com/files/preacherCollecitonSettingPNG_776ia1l9si.png)
Each sprite frame in the sprite sheet is 26x24, thought the sprite themselves are only 18x24.
However, I'm noticing when running the game, that certain pixels in the sprite seem to be shifting, or getting lost, and sections changing shape. Take a look at this example (taken from the game window in Unity), specifically the eyes
(http://chattypics.com/files/pixels_f2wwbxwdlj.gif)
This is what it should look like (taken from my image editor)
(http://chattypics.com/files/pixelsProper_0m0pt5o7jj.gif)
I'm using a tk2dCamera with a native resolution of 1920x1080 with a wildcard override of pixel perfect, center.
I don't know if this is something specific to 2D Toolkit, maybe how it scales the sprites or something? Perhaps I have my sprites setup wrong? I really don't know why this is happening, so any insight would be helpful. Thanks!
-
I must of missed this post when I was first searching, but this sounds related to my issue as well.
http://2dtoolkit.com/forum/index.php?topic=1033.0
I think having my pixels per meter so high (I'm not even sure where 100 came from originally), I'm unable to set them to pixel perfect, instead the scale is set to 1, 1, 1, which may be scaling the sprite down.
Looks like I need to mess with my sprites size, scale and determine the native resolution I want to target, though there doesn't seem to be a hard rule on what's best.
-
100 is fine, and it should be pixel perfect when displayed with the camera set to 100 pixels per meter.. You should make sure the sprite position is always pixel perfect, and your sprite is snapped to a pixel position (i.e. the position is always a multiple of 0.01 if using 100 pixels per meter).
-
You should make sure the sprite position is always pixel perfect, and your sprite is snapped to a pixel position (i.e. the position is always a multiple of 0.01 if using 100 pixels per meter).
So do you literally mean I should be modifying my gameobject's position like so, after movement translation?
// Psuedocode
gameObject.transform.position *= 0.01f
I fear this will have undesirable effects, specifically with collision. Or am I misunderstanding you?
-
If you're using physics then yes you will have issues - the way to get pixel perfect results like that is to keep the sprite image separate, and mirror the position, snapping to the closest pixel. Most games ignore this though - it depends on how far you want to go with this.
-
Okay thanks. I think I'm nitpicking at this point and the effect is so small and would be barely noticeable (if at all) during actual gameplay.
-
FYI Niko, I'm in a similar situation. I just make sure the camera is properly snapped - couldn't care less about the objects themselves. Looks fine.
-
Would you mind sharing how you snap the camera?
-
If your camera is 100 pixels per meter, you want to make sure the camera position is a multiple of 0.01. Basically do something like this
position.x = Mathf.Round(position.x * pixelsPerMeter) / pixelsPerMeter;
and likewise for y and z.
-
Ah okay, I wasn't dividing. That certainly snaps the camera into place, but I was still seeing the same behavior with my original sprite. However, I've actually completely replaced the sprite in the original post with a different design, and I haven't noticed any pixel distortion with the new sprites.
Thanks again!