![]() Print("Player Walking - health:", self.health) this is a Walk method of a Player class ![]() do the initialization of Player instance,we set custom variables init() function is called automatically when we create(instantiate) new Player Player = Core.class(Sprite) - we create our own player class, inherited from the Gideros Sprite core class Keyword self is the equivalent of the this pointer in C++ and it is a reference to the table which is created as part of the Class.new() command. We can inherit from Sprite, EventDispatcher and so on. We use the Core.class function to create our own classes through inheritance. Then we put these classes into their own files and Gideros will load them automatically. It is through the inheritance that we can “emulate” the classes just like in other languages – they will have variables, methods etc. In Lua, each object can define its own behavior through metatables so in a way we emulate OO programming and classes in Lua.Ĭreating instances is easy through a new function: local sprite = Sprite.new() It has roots from prototype-based languages. ![]() I will not go into details about Lua language but in short, Lua does not support classes the way that languages like C++, Java and ActionScript do. ![]() How to avoid this and make it more universal, more reusable? Classes & Instances Even the functions are written in a way that they call “ball” methods directly. In previous example if we wanted to add more balls we would have to add several lines of code for every ball we add – like creating new bitmap, setting new position, anchor etc. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |