maxivast.blogg.se

Gideros sdk
Gideros sdk










gideros sdk
  1. GIDEROS SDK HOW TO
  2. GIDEROS SDK CODE

You can create of course a lot of classes like this, for every object you want. Try to add new balls and you will see them appearing on the screen and each ball can be picked up, dragged etc. You can see it is much clearer this way and we only need to create new Ball objects and you will have new ball with all the methods and all. add field for background and all balls to stageĪnd that’s it. ball2.png and ball3.png are just different balls - try using your own images Ball.new will create objects that we defines in a here we create new ball instances,we pass texture name as argument SoundBounce = Sound.new("snd/bounce.mp3") load sound that will be played when we press on ball Local field = Bitmap.new(Texture.new("gfx/field.png",true)) global direction variable,rotate counterclockwise -3 you can apply some settings to your entire applicationĪpplication:setScaleMode("letterbox") -proper "full screen" scaling for most devices Now create a, it will be much shorter and you will see how easy is to create new balls: Gideros will automatically load and run this file when you run the program. we don't need to check if the ball is moved? not sure why this is here, maybe once we start moving ball If self:hitTestPoint(event.x, event.y) then it is not actually mouse,it means no multi touch function scale ball - executed every mouse press Self:setRotation(self:getRotation()+self.direction) function rotating ball - executed every frame Self:addEventListener(Event.MOUSE_MOVE, self.moveBall,self) Self:addEventListener(Event.MOUSE_UP, self.fallDown,self) Self:addEventListener(Event.MOUSE_DOWN, self.changeBallDirection,self) Self:addEventListener(Event.ENTER_FRAME, self.rotateBall,self) Self:setPosition(math.random(0, 270),math.random(0, 430)) -put ball on random position on screen Local bitmap = Bitmap.new(Texture.new(texture,true)) init will run every time we create new Ball object (Ball.new)įunction Ball:init (texture) -we will pass texture name This self word is use everywhere so it can be quite confusing for beginners. I understand that we access class variables and class methods with self word but I am not so sure why we need to pass another self to self:addEventListener function (if you know let me know in comments, I am still learning).

GIDEROS SDK CODE

The code is pretty much copy/paste from or previous ball example except that we access variables and methods with self (it is also used instead of word ball).

gideros sdk

Now lets take the code from previous tutorial and turn it into what we learned today.

gideros sdk

In above example we put all the code in a but we could take all the (class,methods.) code (line 1-18) and put it in a file and the rest we would leave in a. NewPlayer = Player.new() -create new Player instanceĪnotherPlayer = Player.new() -another Player instanceĪs you can see, in the and it looks similar to OO in other languages. 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.

GIDEROS SDK HOW TO

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.












Gideros sdk