By jlnr (dev)
Date 2009-05-07 10:43
One thing I wonder, is it possible that Array#each will die because you are deleting objects in its iteration block, or is there a protection? Not that it happened while playing, but I'm curious because I remember having this problem. Oh, and you can shoot while dead ;)
The game states & transitions are very clean, I think I'm going to link this from the end of the tutorial. State management is really underdocumented right now :)
By benko
Date 2009-05-07 17:49
@jlnr
You were right about both bugs. I totally forgot that the array "shifts" its elements when you do a delete and that messes the array.each loop. Now the code for updating the sprite lists looks like this:
# Updates all the sprites in the collection
def update
@sprites.each_value do |list|
list.each {|x| x.update}
list.reject!{|x| x.die?} # delete all doomed sprites
end
end
I think it should work now properly, since the sprites don't delete themselves from their own sprite lists until the full sprite list (ie array) has been looped. And now you cannot kill bad guys while you're dead ;)
PS: Thanks a lot for your hard work with Gosu, it's really an amazing lib!
Loading...