Problem with drawing moving sprites.
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Problem with drawing moving sprites.
I'm doing an endless runner kind of thing, but with Wizards and Goblins and shoot em' up elements. I'm quite new to Lua and trying to get the hang of it. The goblins comes swarming from the right to the left in 400px per second. I'v noticed that they shift back a little whenever they move. it looks like they take 3 steps forward and one back each frame, which is really weird.
This intensifies whenever there are higher entity counts on screen (32~ entities). Have anyone else had this problem? I'm not sure how to solve it. I'm uploading the .love files so you guys can see what I mean.
EDIT:
Move with WASD and shoot with spacebar!
EDIT 2:
This seems only to happen when shooting bullets, I adjusted the spawner to spawn in the interval of 0.01 which spawns enough goblins to always update and render 136 objects.
EDIT 3:
If I remove the check inside bullet that sets the alive status to false ( causing it to not get removed from a table ) then the problem disapears. I think it is how I remove objects from the game ... is it a bad idea to call table.remove?
This intensifies whenever there are higher entity counts on screen (32~ entities). Have anyone else had this problem? I'm not sure how to solve it. I'm uploading the .love files so you guys can see what I mean.
EDIT:
Move with WASD and shoot with spacebar!
EDIT 2:
This seems only to happen when shooting bullets, I adjusted the spawner to spawn in the interval of 0.01 which spawns enough goblins to always update and render 136 objects.
EDIT 3:
If I remove the check inside bullet that sets the alive status to false ( causing it to not get removed from a table ) then the problem disapears. I think it is how I remove objects from the game ... is it a bad idea to call table.remove?
- Attachments
-
- Dungeon Pew Pew.love
- (8.45 KiB) Downloaded 221 times
Last edited by Moonkis on Fri Feb 21, 2014 11:53 pm, edited 5 times in total.
Re: Problem with drawing moving sprites.
Incorrect game packaging
It should be a .zip, not .rar.
It should be a .zip, not .rar.
Re: Problem with drawing moving sprites.
Fixed it! Try download it againDoctory wrote:Incorrect game packaging
It should be a .zip, not .rar.
Re: Problem with drawing moving sprites.
Take out all the files from Dungeon Pew Pew folder and put it in the zip.Moonkis wrote:Fixed it! Try download it againDoctory wrote:Incorrect game packaging
It should be a .zip, not .rar.
Re: Problem with drawing moving sprites.
I haven't looked at it yet, but I'd be willing to put money on the fact that it's your drawings. How they're made to quads or whatever. That's probably it.
*(On a side note, if that's not the problem, don't expect any money)
*(On a side note, if that's not the problem, don't expect any money)
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Problem with drawing moving sprites.
I think so too, hopefully someone could explain what I'm doing wrong!
I updated the .love file! HOPEFULLY this is correct!
Thanks in advance!
I updated the .love file! HOPEFULLY this is correct!
Thanks in advance!
Re: Problem with drawing moving sprites.
Yes, it works now. I see no problem what so ever here, it may be your computer.
Re: Problem with drawing moving sprites.
Have you tried spamming bullets (Holding spacebar)? Its then the problem arises. I "kind" of fixed this, by basically move the table.remove(...) into it's own loop which runs after the update-loop.Doctory wrote:Yes, it works now. I see no problem what so ever here, it may be your computer.
Is table.remove a bad idea to call WHEN iterating over the loop itself?
I'v basically isolated the problem to this piece of code (in EntityManager.update(dt))
Code: Select all
for i, e in pairs(EntityManager.objects) do
if e.update then
e:update(dt)
if e:isAlive() == false then
table.remove(EntityManager.objects, i)
end
end
end
Re: Problem with drawing moving sprites.
It depends on how you're iterating. If you have a loop that starts at the end and iterates until the beginning adding -1 each time, it's harmless. Now if you have a normal for-loop, you're really messing it up. Here's what I mean:
What happens here is the original Fruits[2] (lemon) is not even touched in the first iteration. Here's how the table would look during this:
To fix this problem, iterate like this:
Code: Select all
Fruits = {
{ Color = { 255, 0, 0, 255 }, Taste = 'Great!', Size = 64 }, -- Apple
{ Color = { 255, 255, 0, 255 }, Taste = 'Awful', Size = 32 }, -- Lemon
{ Color = { 255, 0, 255, 255 }, Taste = 'Great!', Size = 2 } }, -- Grape
}
function FruitLoop( Table ) -- Yes, intentional pun here. :)
for a = 1, #Table do
local Fruit = Table[a]
if Fruit.Taste = 'Great!' then
table.remove( Table, a )
end
end
end
Code: Select all
a = 1
#Fruits = 3
Fruits[1] has a taste of 'Great!' so it's removed. Now the table is
Fruits = {
{ Color = { 255, 255, 0, 255 }, Taste = 'Awful', Size = 32 }, -- Lemon, 1st index
{ Color = { 255, 0, 255, 255 }, Taste = 'Great!', Size = 2 } }, -- Grape, 2nd index
}
a = 2 (Accessing Grape)
#Fruits = 2
Notices that Grape tastes great too, and removes it.
Code: Select all
function FruitLoop( Table ) -- Yes, intentional pun here. :)
for a = #Table, 1, -1 do -- Starts accessing at 3. Goes until 1, removing 1 from the index each time.
local Fruit = Table[a]
if Fruit.Taste = 'Great!' then
table.remove( Table, a )
end
end
end
GitHub | MLib - Math and shape intersections library | Walt - Animation library | Brady - Camera library with parallax scrolling | Vim-love-docs - Help files and syntax coloring for Vim
Re: Problem with drawing moving sprites.
Why isn't Fruit[2] touched here? Shouldn't it? Also I'm using a generic loop (think what it's called)davisdude wrote:It depends on how you're iterating. If you have a loop that starts at the end and iterates until the beginning adding -1 each time, it's harmless. Now if you have a normal for-loop, you're really messing it up. Here's what I mean:What happens here is the original Fruits[2] (lemon) is not even touched in the first iteration. Here's how the table would look during this:Code: Select all
Fruits = { { Color = { 255, 0, 0, 255 }, Taste = 'Great!', Size = 64 }, -- Apple { Color = { 255, 255, 0, 255 }, Taste = 'Awful', Size = 32 }, -- Lemon { Color = { 255, 0, 255, 255 }, Taste = 'Great!', Size = 2 } }, -- Grape } function FruitLoop( Table ) -- Yes, intentional pun here. :) for a = 1, #Table do local Fruit = Table[a] if Fruit.Taste = 'Great!' then table.remove( Table, a ) end end end
To fix this problem, iterate like this:Code: Select all
a = 1 #Fruits = 3 Fruits[1] has a taste of 'Great!' so it's removed. Now the table is Fruits = { { Color = { 255, 255, 0, 255 }, Taste = 'Awful', Size = 32 }, -- Lemon, 1st index { Color = { 255, 0, 255, 255 }, Taste = 'Great!', Size = 2 } }, -- Grape, 2nd index } a = 2 (Accessing Grape) #Fruits = 2 Notices that Grape tastes great too, and removes it.
Code: Select all
function FruitLoop( Table ) -- Yes, intentional pun here. :) for a = #Table, 1, -1 do -- Starts accessing at 3. Goes until 1, removing 1 from the index each time. local Fruit = Table[a] if Fruit.Taste = 'Great!' then table.remove( Table, a ) end end end
Code: Select all
for i, v in pairs(table) do
-- code
end
Oh, is it because that a = 1 then we remove an item, the table is resized, which means lemon is now at index 1, and we move onto index 2, thus "skipping" lemon?
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 4 guests