Hey there,
I'm working on a game with gideros + SH/LH/CH and my project is getting bigger and bigger. As always while learning new frameworks/languages I need some refactoring during development
![:) :)](http://forum.gideros.rocks/resources/emoji/smile.png)
Right now I'm about changing the way of loading user defined classes from a level but I'm not sure what's the best practice because my code is getting unclear:
Let's say you have a level loaded with a player and a enemy:
game.lua
...
self.loader = LevelHelperLoader:initWithContentOfFile("level" .. self.currentLevel .. ".plhs");
...
self.player = Player.new(self);
self.enemy = Enemy.new(self);
... |
player.lua
Player = gideros.class(Sprite);
function Player:init(game)
end
function Player:myFunc()
print("myFunc() called");
end |
enemy.lua
Enemy = gideros.class(Sprite);
function Enemy:init(game)
end
function Enemy:dead()
print("enemy dead");
end |
The problem is, that my Player class is not associated with the class in the level file. Then i tried to set all properties from the sprite of the levelfile in the init method but that looks (and sounds to me) very wrong
![:D :D](http://forum.gideros.rocks/resources/emoji/lol.png)
(and doesn't work for animation either)
Player = gideros.class(Sprite);
function Player:init(game)
-- Extend instance with player instance
self.sprite = game.loader:spriteWithUniqueName("player")
for key, value in pairs (self.sprite) do
self[key] = value
end
end |
I know there's a custom class in the LHSprite class but I have no ideas how to use this in a good OOP way. Any ideas?
Thanks in advance from a newbie
Comments
http://www.levelhelper.org/phpBB3/viewtopic.php?f=14&t=3074
Does that help?