[Help] Techniques for scaling

General discussion about LÖVE, Lua, game development, puns, and unicorns.
glass2d
Prole
Posts: 14
Joined: Thu Apr 18, 2024 11:40 pm

Re: [Help] Techniques for scaling

Post by glass2d »

Thanks! Rounding the physics body x and y then setting the x and y to the rounded values improved the snapping issue I was noticing as the player moves along the diagonal, as shown in the gif. However, I'm still noticing some snapping occurring as the player moves in relation to the background. Specifically, it seems that the fountain asset is jittering or snapping back and forth as the player moves horizontally. Do you have any suggestions for how I could address this problem and prevent the snapping effect?
Attachments
rounded_physics_body.gif
rounded_physics_body.gif (3.43 MiB) Viewed 386 times
User avatar
_JM_
Prole
Posts: 17
Joined: Thu Mar 30, 2023 9:06 pm
Contact:

Re: [Help] Techniques for scaling

Post by _JM_ »

Try change the player's max_speed field.
I tried change from 150 to 136 and the jittering appears to be gone.
glass2d
Prole
Posts: 14
Joined: Thu Apr 18, 2024 11:40 pm

Re: [Help] Techniques for scaling

Post by glass2d »

It seems like the solution of lowering the max speed to <= 135 resolves the issue for now. However, I'm curious about the underlying cause of this problem. Understanding why it's happening would help me develop a more generalizable solution for similar issues in the future. Can anyone provide an explanation for why this snapping phenomenon is occurring? It seems like it has to do with different objects not being drawn or positioned at integer pixel values?
User avatar
pgimeno
Party member
Posts: 3574
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Help] Techniques for scaling

Post by pgimeno »

I wanted to have a look at the issue, but RL is keeping me quite busy these days. Could you please indicate what kind of movement you want?

Specifically, my understanding is that you have a virtual resolution of 480x270 which is the underlying resolution, and you zoom it e.g. by 4 to get 1920x1080 in a 1920x1080 screen. Do you want the map/character to move pixel by pixel with the 1920x1080 resolution (i.e. in screen pixels) or do you want it to move with the 480x270 resolution (i.e. in increments of 4 screen pixels)?
glass2d
Prole
Posts: 14
Joined: Thu Apr 18, 2024 11:40 pm

Re: [Help] Techniques for scaling

Post by glass2d »

pgimeno wrote: Thu May 09, 2024 12:36 pm I wanted to have a look at the issue, but RL is keeping me quite busy these days. Could you please indicate what kind of movement you want?

Specifically, my understanding is that you have a virtual resolution of 480x270 which is the underlying resolution, and you zoom it e.g. by 4 to get 1920x1080 in a 1920x1080 screen. Do you want the map/character to move pixel by pixel with the 1920x1080 resolution (i.e. in screen pixels) or do you want it to move with the 480x270 resolution (i.e. in increments of 4 screen pixels)?
I'm wondering if there's anything unconventional about my current approach, and if there are more traditional methods for creating a top-down pixel game that I should explore.

Assuming my current approach is generally acceptable, I think I'm interested in the concept of pixel-perfect motion. From what I gather, this involves moving the character in increments of 1 screen pixel, irrespective of the underlying virtual resolution. For instance, in a 1920x1080 resolution, the character moves by 1 pixel, and in a 480x270 resolution, it also moves by 1 pixel. This means that each movement corresponds to 1/4 of a pixel in the virtual 480x270 resolution when viewed at 1920x1080. This method appears to promise smoother movement across different screen resolutions. However, I'm uncertain if there are any significant drawbacks associated with this approach.
User avatar
pgimeno
Party member
Posts: 3574
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Help] Techniques for scaling

Post by pgimeno »

OK, try this and see whether it helps:

Code: Select all

function PlayerCamera:update(dt)
    local camX = Player.x
    local camY = Player.y
    local mapW = Map.width * Map.tilewidth
    local mapH = Map.height * Map.tileheight
    camX, camY = self:setBorders(camX, camY, mapW, mapH)
    camX = math.floor(camX*self.scale + 0.5) / self.scale  -- *** add this
    camY = math.floor(camY*self.scale + 0.5) / self.scale  -- *** add this
    self:lockPosition(camX, camY)
    self.x, self.y = self:position()
end
glass2d
Prole
Posts: 14
Joined: Thu Apr 18, 2024 11:40 pm

Re: [Help] Techniques for scaling

Post by glass2d »

pgimeno wrote: Thu May 09, 2024 6:31 pm OK, try this and see whether it helps:

Code: Select all

function PlayerCamera:update(dt)
    local camX = Player.x
    local camY = Player.y
    local mapW = Map.width * Map.tilewidth
    local mapH = Map.height * Map.tileheight
    camX, camY = self:setBorders(camX, camY, mapW, mapH)
    camX = math.floor(camX*self.scale + 0.5) / self.scale  -- *** add this
    camY = math.floor(camY*self.scale + 0.5) / self.scale  -- *** add this
    self:lockPosition(camX, camY)
    self.x, self.y = self:position()
end
I tried this but it didn't seem to have much of an affect. Will you elaborate on the idea behind this?
User avatar
pgimeno
Party member
Posts: 3574
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Help] Techniques for scaling

Post by pgimeno »

The idea is to round to screen pixels. It works for me, besides the obvious problems inherent to not using an integer scale, which cause image deformation.
glass2d
Prole
Posts: 14
Joined: Thu Apr 18, 2024 11:40 pm

Re: [Help] Techniques for scaling

Post by glass2d »

When you say it "works for you" did you add this with no other rounding (Such as the player's physics body)
User avatar
pgimeno
Party member
Posts: 3574
Joined: Sun Oct 18, 2015 2:58 pm

Re: [Help] Techniques for scaling

Post by pgimeno »

glass2d wrote: Sat May 11, 2024 2:29 am When you say it "works for you" did you add this with no other rounding (Such as the player's physics body)
That's right. The character seems to jitter due to rounding problems and animation problems, but these are unrelated to the movement.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 3 guests