Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat | DONATE
Create object class from text in a var — Gideros Forum

Create object class from text in a var

MarklogoMarklogo Member
edited December 2014 in Game & application design
Hello everyone. I am starting with this framework and have a question conducting a parser for Tiled.
There a way to create an object from a text in a variable or something
for example:
--Moneda.lua--
Moneda = Core.class(Sprite)
 
function Moneda:init()
self:setX(100)
self:setY(100)
self:addChild(Bitmap.new(Texture.new("Images/moneda.png")))
end
 
--Estrella.lua--
Estrella = Core.class(Sprite)
 
function Estrella:init()
self:setX(100)
self:setY(100)
self:addChild(Bitmap.new(Texture.new("Images/estrella.png")))
end
 
--Main.lua--
local a="Moneda"
local b="Estrella"
stage:addChild(a.new())
stage:addChild(b.new())
Thanks for your time and sorry if I did not express the question correctly.
I do not drive very well with the English.

Comments

  • edited December 2014
    @Marklogo, Maybe you need implement something like this:
    MyTiled = Core.class(Sprite)
     
    function MyTiled:init(params)
    	self:setX(params.x)
    	self:setY(params.y)
    	self:addChild(Bitmap.new(Texture.new(params.name,true)))
    end
     
     
    --Main.lua--
    local a="Images/moneda.png"
    local b="Images/estrella.png"
     
    stage:addChild(MyTiled.new({x=100,y=200,name = a}))
    stage:addChild(MyTiled.new({x=300,y=500,name = b}))
    Coming soon
  • aha, but if the logic of each object is different?
    They are two different objects, and create one or another depending on the value of a variable without using the if statement.
  • Yeah that's what I wanted.
    Thank you very much
    +1 -1 (+1 / -0 )Share on Facebook
Sign In or Register to comment.