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

destroy method doesn't really destroy GameObjects #56

Closed
samueller opened this issue Sep 7, 2012 · 3 comments
Closed

destroy method doesn't really destroy GameObjects #56

samueller opened this issue Sep 7, 2012 · 3 comments

Comments

@samueller
Copy link

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.

@ippa
Copy link
Owner

ippa commented Sep 7, 2012

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.

@samueller
Copy link
Author

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

@ippa
Copy link
Owner

ippa commented Sep 7, 2012

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 bdf09dc .. thanks for reporting!

Install a fixed gem with "gem install chingu --pre"

@ippa ippa closed this as completed Sep 7, 2012
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