Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Animated Tile objects don't retain scale during animation. #241

Open
133794m3r opened this issue Sep 6, 2020 · 7 comments
Open

Animated Tile objects don't retain scale during animation. #241

133794m3r opened this issue Sep 6, 2020 · 7 comments

Comments

@133794m3r
Copy link
Contributor

When using Tiled's Animation system the scale of any object is lost upon the tile switching to it's next animation frame. I believe this bit of code is the issue.

j.batch:set(j.id, t.quad, j.x, j.y, j.r, tile.sx, tile.sy, 0, j.oy)

local t = self.tiles[tonumber(tile.animation[tile.frame].tileid) + self.tilesets[tile.tileset].firstgid]

Since for a tile image based object the tile.sx is going to be the normal 1 or -1 without the additional scaling factor that was calculated when indexing over it in setObjectSpriteBatches(layer)

local sx = object.width / tile.width

The issue seems to be that the instance's information is being overwritten when the tile is updated and it's not taking into account the sx that was calculated based upon the size of the tile itself.

@133794m3r
Copy link
Contributor Author

I'm thinking about trying to take on this fix. Are the objects in the tile instances actual references to the batched object? As in do I still have access to the properties of the original object when accessing it as a tileInstance?

If so then I think the fix should be relatively simple(and I can write it myself) but I wanted to be sure before I go down a rabbit hole that'll lead me to no where.

@karai17
Copy link
Owner

karai17 commented Oct 3, 2020 via email

@133794m3r
Copy link
Contributor Author

133794m3r commented Oct 3, 2020

OK thanks, I'll fix this bug with the update function when objects are set to utilize a tile that has an animation. After I confirm it's working I'll create a PR and reference this issue. I'll try to keep the amount of changed lines to a minimum. As I think that's the only major thing left before I can create my game.
I just cloned the latest master and will start work on a new branch as I try to see if my fix'll work.

P.S.
Thanks again for all of the work you've already put into this library as I know there's 0% chance that I'd ever be able to finish my own project without yours.

@karai17
Copy link
Owner

karai17 commented Oct 4, 2020 via email

@133794m3r
Copy link
Contributor Author

It's scaled in the tiled map currently and it's always an integer scale. Plus I have the whole world scaled with nearest filter. I made sure to make everything an integer scale.

I have the thing working but it's going to add ~16b(assuming that LuaJit uses Doubles for it's floating point numbers) of memory per object that uses a tile image. I know there has to be some way to access the properties of a batched instance as you have the ID to set it, but I've yet to dig into the Love2D codebase to figure out how as that seems like a waste of good memory to add 2 more properties to the tile instance table.

If I can't find a way to fix it w/o adding the 2 properties then I'll leave it be as it's not a ton of memory but still it feels inefficient having to lug around all that extra metadata for each tile instance. If I can't find a way to fix it the other way by tomorrow then I'll leave it be and submit the PR as is(it's still just on my local repo in a branch)

@karai17
Copy link
Owner

karai17 commented Oct 5, 2020 via email

133794m3r added a commit to 133794m3r/Simple-Tiled-Implementation that referenced this issue Oct 7, 2020
…ove2d

sprite batch but for now this will fix it. I am wasting another 16 bytes of
data per object/tile overall. I think that I might be able to do something
like batch[id].sx and batch[id].sy to get th metadata but that's up for
a later release once I am done with this one as I am not going to fix something
that is currently already working.

Fixes issue karai17#241
@133794m3r
Copy link
Contributor Author

OK I created the pull request after pushing my code upstream. The fix(if you want to call my paltry change) a true fix does work. I verified it manually by having 3 objects all using the same tile image as their base and then setting their scale to be different amounts. All were integer one was 1x, one 2x, and one 3x. Then I watched the animations play out to verify that they all stayed their correct sizes.

I'll try to continue to dig through the code-base for any other items.
Also the line about the offset for the y position was removed because for some reason upon sprite-update the sprites would all move up 1 tile's height which makes me think that somehow they were rendered in the correct position all along. That was also manually verified by watching for sprite movements from the same visual representation in Tiled(not pixel offsets obviously).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants