Public Group

# Sprites: 'Blured' graphics after moving with 'float'...

This topic is 3080 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

hi,

I'm currently working on a multi-layer-background-system for my sidescroller-engine, and so far everything works fine except of that:

I want to support up to 10 individual background-layers (every layer is its own sprite), which should all be moving in a different speed than the level itself, set by a value:

float Scrollval;

The range of that value is between 1.0f (moving same speed as level) and 0.0f(no movement). The speed is calculeted that way:

float move_x = x * ScrollVal;

x equals to the movement of the level and the player. So, my problem now is:

- eigther if I move everything with integers (no matter if I define move_x as float), I have got a very little range of different move-speeds, as with my normal movement of 5 pixel per step, there are exactly 5 different values for the speed of the background (so it doesn't make any difference if I set the value 0.1f or 0.25f; it equals in the same move-speed).

- OR if I move my sprites with floats, I get a great range of different move-speeds (badly needed because only for my testing-stuff I already use 7 of my layers; which looks bad-ass when using the float-method), BUT my graphics look like that:

If you don't see in download it and zoom in. All my graphics are now (just sometimes) messed up, like they where filtered into a bad resolution. Is there any solution for that? I want my 10 backgrounds all to be able to move with different speeds, but without having to increase the speed of my player and without these ugly graphics.

##### Share on other sites
Um... how about converting the flats to integers only when the sprites are drawn?.

So you calculate everything with floats then for display:

x_on_screen = floor(x_in_game+0.5); // I guess you know this rounding thing.

Give it a try, I think you will like it ;)

##### Share on other sites
Ah yeah thats it I tried to simply convert the position into integer simply by writing (int) in fron of the float... oups :/

Thanks, I didn't know the floor-function so far. Now its working as I supposed it to do, except of one problem: My last layer with a 'ScrollVar' of 0.15 isn't moving when the player is moving left. Everything works fine when moving to the right and the layer is moving left, but the other way round it isn't working, only for that layer, the others are moving. Any problem in my code or something about the floor-function? I used it that way:

void CSprite::Move(float x, float y){    m_vPosition.x += floor(x);    m_vPosition.y += floor(y);}

"x" equals to 300.0f divided through the current framerate. whats the problem now?

##### Share on other sites
Quote:
 Original post by szecsx_on_screen = floor(x_in_game+0.5);

Just curious, if you change it to:

x_on_screen = int(x_in_game+0.5);

will it still work?

##### Share on other sites
It ain't working if I change it to "int(x)", that way I have the same problems like before.

In generell your solution seems not to work that correct the way I use it. For example there still is no difference between the values in the range between 0.8f and 0.99f, all these layers are moving the same speed. Maybe I use that function the wrong way? I use it when moving the sprite, maybe I should us it at another position in the code?

##### Share on other sites
Quote:
 Original post by The King2It ain't working if I change it to "int(x)", that way I have the same problems like before.

I meant int(x + 0.5f). It's the addition of 0.5 that gives the rounding, so I didn't understand why the floor() was needed. But I'm probably missing something...

##### Share on other sites
Quote:
 Original post by The King2It ain't working if I change it to "int(x)", that way I have the same problems like before.In generell your solution seems not to work that correct the way I use it. For example there still is no difference between the values in the range between 0.8f and 0.99f, all these layers are moving the same speed. Maybe I use that function the wrong way? I use it when moving the sprite, maybe I should us it at another position in the code?
I don't know what you are expecting.

if you separate the two values, it should work

SEPARATE!
So you mustn't use x = int(x+0.5)

the floor thing doesn't matter. Get over it! [grin]

##### Share on other sites
Oh, the 0.5 gives the rounding, hmm sry I somehow didn't get the point ... now I'm using the 0.5 and it works so far, except that it is a bit "shaking" and not that fluently, but I guess thats a problem that cannot be fixed without making the movespeed a minimum of 10 pixels. Its not that annoying anyway, you notice it a bit, and finally my problem is solved :) thanks for the support

##### Share on other sites
Quote:
 Original post by The King2Oh, the 0.5 gives the rounding, hmm sry I somehow didn't get the point ... now I'm using the 0.5 and it works so far, except that it is a bit "shaking" and not that fluently, but I guess thats a problem that cannot be fixed without making the movespeed a minimum of 10 pixels. Its not that annoying anyway, you notice it a bit, and finally my problem is solved :) thanks for the support
What do you mean by shaking? Shaking means the layer jumps back and forth in some cases. That shouldn't happen. If it happens, you have a bug so post code.

Or do you mean "popping"? It's normal thing, if the layer "pops" into its new position. I still don't know what you are expecting. That's rasterized display. Either get a vector display, or an infinite high resolution monitor.

##### Share on other sites
Well, it depends on the "ScrollVal". With some values I get the sprite moving fluently for 3 seconds and than "popping" a few pixels further. Some other values makes the sprites just "popping" from a position into the next, and it seems a bit like shaking. But yes, your right, I can't expect anything else, so far I'm glad it is working that good.

1. 1
2. 2
Rutin
16
3. 3
4. 4
5. 5

• 26
• 11
• 9
• 9
• 11
• ### Forum Statistics

• Total Topics
633702
• Total Posts
3013451
×