Closed samueller closed 12 years ago
Calling destroy on a gameobject removes it from chingus internal list of game objects... and leaves it to be garbage collected. If won't be garbage collected if you have another reference to the game object in question though.
hmm... I can set the object to be destroyed to nil, but the input on the object still works. How do I take off input controls? For example:
require 'chingu'
class Game < Chingu::Window
def initialize
super
@alien = Alien.create
@alien.input = {space: :fire}
self.input = {r: :remove_alien}
end
def remove_alien
@alien.destroy if @alien
puts 'destroyed'
@alien = nil
end
end
class Alien < Chingu::GameObject
def fire
puts 'still here'
end
end
Game.new.show
You're right. Game object wasn't removed from chingus internal list of input receivers when destroyed. While @game_object.input = works I never use it much.. I think it's better to keep the input-dispatching in main window or game state.
Fixed in https://github.com/ippa/chingu/commit/bdf09dc60f7eb7d6ffa134a2012a48e7248127e6 .. thanks for reporting!
Install a fixed gem with "gem install chingu --pre"
How do I remove a GameObject from memory? If I create a space game and shoot an alien, I want that alien completely destroyed. So I do an alien.destroy. But his update method is still being called 60 times/second.