Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Sprite blurry  (Read 9786 times)

0 Members and 2 Guests are viewing this topic.

Don Andy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sprite blurry
« on: June 06, 2008, 03:42:28 pm »
Since I'm working on a rather small pixel-scale, sharpness is very important, so I already set "SetSmooth" on false for the image.

However, when moving the thing around with
Code: [Select]
if (App.GetInput().IsKeyDown(sf::Key::Left)) spr_hero.SetLeft(spr_hero.GetLeft() - 100 * ElapsedTime);

It often gets blurry and stretched, depending on how it stops. I think this has something to do with the positioning using floats. I'm not sure how to fix it, though and would appreciate any help.

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Sprite blurry
« Reply #1 on: June 06, 2008, 04:15:25 pm »
Well ,I guess there is no such thing as help
(btw.. I noticed, that the edges of the screen are more blurry than the center °_o) you can try this out, by taking a random pixelmap and sho it.
(every pixel got a random lightness between 0 and 0xff)
I wonder why? (does SFML use some kind of render to texture to display all the stuff?? -> posteffects??) P.S. there where no Post effects activated in this testcase
greetz tgm

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite blurry
« Reply #2 on: June 06, 2008, 04:17:38 pm »
Quote
I think this has something to do with the positioning using floats

In this case, using integer coordinates should solve the problem.

Quote
(btw.. I noticed, that the edges of the screen are more blurry than the center °_o) you can try this out, by taking a random pixelmap and sho it.
(every pixel got a random lightness between 0 and 0xff)

What the hell are you talking about ? :lol:
Laurent Gomila - SFML developer

Don Andy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sprite blurry
« Reply #3 on: June 06, 2008, 04:55:12 pm »
Quote from: "Laurent"

In this case, using integer coordinates should solve the problem.


Uhm, yeah, that's the thing. I've gotten a bit rusty with C++ and wanted to get back into the whole thing with the help of SFML.

Do I need to rewrite the sprite class to use integers instead of floats?

It's probably something incredibly simple again <.<

quasius

  • Full Member
  • ***
  • Posts: 166
    • View Profile
Sprite blurry
« Reply #4 on: June 06, 2008, 07:25:34 pm »
Quote from: "Don Andy"
Quote from: "Laurent"

In this case, using integer coordinates should solve the problem.


Uhm, yeah, that's the thing. I've gotten a bit rusty with C++ and wanted to get back into the whole thing with the help of SFML.

Do I need to rewrite the sprite class to use integers instead of floats?

It's probably something incredibly simple again <.<


No.  You just need to cast any position data sent to the sprite class to ints.

Don Andy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sprite blurry
« Reply #5 on: June 06, 2008, 08:10:27 pm »
Sorry if I sound stupid or anything, but can anybody tell me what I'd need to do with
Code: [Select]

if (Window->GetInput().IsKeyDown(sf::Key::Left)) Sprite.SetLeft(Sprite.GetLeft() - 100 * Window->GetFrameTime());


to make it work with integers? I think I've pretty much tried every possible combination of typecasts, but this isn't quite working as I want it to >.<

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Sprite blurry
« Reply #6 on: June 06, 2008, 09:01:26 pm »
If you move your sprite (btw. isn't there a Move() function?) depending on the frametime, a constant movement is rather not propable.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

Don Andy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sprite blurry
« Reply #7 on: June 06, 2008, 09:24:53 pm »
Well, I did it like it was described in the tutorial :/
If there is a way to keep a constant framerate and use a technique of movement that does not stretch and blur my sprite I'd gladly take it.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite blurry
« Reply #8 on: June 07, 2008, 01:15:38 am »
Code: [Select]
Sprite.SetLeft(floor(...));
Sprite.SetTop(floor(...));
Laurent Gomila - SFML developer

Don Andy

  • Newbie
  • *
  • Posts: 5
    • View Profile
Sprite blurry
« Reply #9 on: June 07, 2008, 01:22:50 am »
Aah, thanks a bunch.

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Sprite blurry
« Reply #10 on: June 09, 2008, 07:40:53 pm »
Quote

What the hell are you talking about ? :lol:


öhm.. draw a sprite with some iregular high contrast pattern (1 px checkboard for example) and you'll notice some focal blur effect in the edges of the Renderwindow...

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite blurry
« Reply #11 on: June 10, 2008, 04:04:40 pm »
Quote from: "tgm"
öhm.. draw a sprite with some iregular high contrast pattern (1 px checkboard for example) and you'll notice some focal blur effect in the edges of the Renderwindow...

Do you have a perfect 1:1 pixel match between your window and your 2D world ? If not, the blur effect is not surprising.
Laurent Gomila - SFML developer

tgm

  • Jr. Member
  • **
  • Posts: 69
    • View Profile
Sprite blurry
« Reply #12 on: June 10, 2008, 05:21:11 pm »
yeah.. I think so..
simply using a normal rendering window, and drawing a 800x600 (for example) sprite without changing anything about scale etc..

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Sprite blurry
« Reply #13 on: June 11, 2008, 02:51:30 am »
Ok, I'll do some tests.
Laurent Gomila - SFML developer

 

anything