|
| 1 | +# Objects |
| 2 | + |
| 3 | +Objects are used to create graphics, texts, or buttons. |
| 4 | + |
| 5 | +## LfSprite |
| 6 | + |
| 7 | +The ``LfSprite`` class is used to create a sprite, with a image or graphic. |
| 8 | + |
| 9 | +```haxe |
| 10 | +// import the LfSprite class |
| 11 | +import leafy.objects.LfSprite; |
| 12 | +
|
| 13 | +// create a sprite in your state |
| 14 | +var sprite:LfSprite = new LfSprite(100, 100); |
| 15 | +
|
| 16 | +/* |
| 17 | + Create a graphic |
| 18 | + The ``createGraphic`` function takes 3 parameters, the width, height and the color of the graphic. |
| 19 | +*/ |
| 20 | +sprite.createGraphic(200, 200, [255, 0, 0]); |
| 21 | +
|
| 22 | +// Load an image |
| 23 | +sprite.loadImage("GAME_PATH/image.png"); |
| 24 | +
|
| 25 | +// add the sprite to the state |
| 26 | +addObject(sprite); |
| 27 | +``` |
| 28 | + |
| 29 | +-------- |
| 30 | + |
| 31 | +## LfText |
| 32 | + |
| 33 | +The ``LfText`` class is used to create a sprite, with a text. |
| 34 | + |
| 35 | +```haxe |
| 36 | +// import the LfText class |
| 37 | +import leafy.objects.LfText; |
| 38 | +
|
| 39 | +// create a text in your state |
| 40 | +var text:LfText = new LfText(100, 100, "Hello World!", 32, "GAME_PATH/FONT.ttf"); |
| 41 | +
|
| 42 | +// add the text to the state |
| 43 | +addObject(text); |
| 44 | +``` |
| 45 | + |
| 46 | +-------- |
| 47 | + |
| 48 | +## LfButton |
| 49 | + |
| 50 | +The ``LfButton`` class is used to create a button, with a image or graphic. |
| 51 | + |
| 52 | +```haxe |
| 53 | +// import the LfButton class |
| 54 | +import leafy.objects.LfButton; |
| 55 | +
|
| 56 | +// create a button in your state. |
| 57 | +var button:LfButton = new LfButton(100, 100, function():Void { |
| 58 | + // do something |
| 59 | +}); |
| 60 | +
|
| 61 | +/* |
| 62 | + Create a graphic |
| 63 | + The ``createGraphic`` function takes 3 parameters, the width, height and the color of the graphic. |
| 64 | +*/ |
| 65 | +sprite.createGraphic(200, 200, [255, 0, 0]); |
| 66 | +
|
| 67 | +// Load an image |
| 68 | +sprite.loadImage("GAME_PATH/image.png"); |
| 69 | +
|
| 70 | +// add the button to the state |
| 71 | +addObject(button); |
| 72 | +``` |
| 73 | + |
| 74 | +-------- |
| 75 | + |
| 76 | +See [``LfSprite``](https://github.com/Slushi-Github/leafyEngine/blob/main/leafy/objects/LfSprite.hx) |
| 77 | + |
| 78 | +See [``LfText``](https://github.com/Slushi-Github/leafyEngine/blob/main/leafy/objects/LfText.hx) |
| 79 | + |
| 80 | +See [``LfButton``](https://github.com/Slushi-Github/leafyEngine/blob/main/leafy/objects/LfButton.hx) |
0 commit comments