Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Inheritance from multiple classes — Gideros Forum

Inheritance from multiple classes

marcelojuniormarcelojunior Member
edited October 2012 in General questions
Sorry for my english.

I need to extend from multiple classes.
I've created a classe named animate (animate = Core.class())
And i have to extend these in other classes like: mesh = Core.class(Mesh, animate).
This is to use the animate methods.

Thanks. (:

Comments

  • marcelojuniormarcelojunior Member
    edited October 2012
    i will, for now, implementing all the methods in all classes :/
  • asakharovasakharov Member
    Accepted Answer
    As far as I know, Gideros not support multiple inheritance.
    Use aggregation instead of inheritance or try this http://www.lua.org/pil/16.3.html
  • ar2rsawseenar2rsawseen Maintainer
    Accepted Answer
    Would it help you if animate class was already inheriting from Mesh?
    as:
    animate = Core.class(Mesh)
    mesh = Core.class(animate)
  • asakharov: I tried to use this example, but without success.

    ar2rsawseen: up would work, but the classes that going to extend the animate are: sprite, mesh and bitmap, then it would not work.

    :/
  • Mash and Bitmaps - inherits from Sprite.
    So, maybe you just want a Sprite interface to implement the animation?
    If so, then you can write:
    Animation = Core.class()
     
    function Animation:init(spriteObject)
      self.Object = spriteObject
      ...
    end
     
    funtion Animation:MakeWonderfulEffect()
      --operations with self.Object as a Sprite object
      .....
    end
     
    .......
     
    local test1 = Mesh.new(...)
    local test2 = Bitmap.new(...)
    local test3 = Sprite.new(...)
    loca animation1 = Animation.new(test1)
    loca animation2 = Animation.new(test2)
    loca animation3 = Animation.new(test3)
     
    animation1:MakeWonderfulEffect()
    animation2:MakeWonderfulEffect()
    animation3:MakeWonderfulEffect()
  • Yah, I really liked this example \o/

    I abstracted some gideros classes/methods to make more easy to use.
    Example:
    mesh = Core.class(Mesh)
    -- some methods to abstract Mesh class
     
    local background = mesh.new()
    background:addVertice(0, 0) -- addVertice() make the relation with the Mesh directly
    background:addVertice(0, 100)
    background:addVertice(100, 100)
    background:addVertice(0, 0)
    With your example, i will implement the animation, transformation etc.. classes, for Bitmap, Sprite, Shape, Mesh, and methods like addVertice for example can be used in Shape or Mesh classes, its amazing \o/

    thanks asakharov and ar2rsawseen for Help.
Sign In or Register to comment.