-
Notifications
You must be signed in to change notification settings - Fork 19
Open
Description
In trying to subclass MG::Sprite
I discovered that it is possible to subclass MG::Sprite
. However, the technique is not intuitive. In order to subclass MG::Sprite
you have to define a self.new
method instead of the typical initialize
method:
class Character < MG::Sprite
# this works, but is not like Ruby
def self.new(filename = "default.png")
puts "Executing Character.new"
instance = super
instance.attach_physics_box
instance.dynamic = false
instance.scale = 2
instance
end
# this is the approach that I would expect, but it does not get called
def initialize(filename = "default.png")
puts "Executing Character#initialize" # does not get called
super
attach_physics_box
self.dynamic = false
self.scale = 2
end
end
Metadata
Metadata
Assignees
Labels
No labels