Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/itzkiwisky/object.lua
A simple lua lib to create objects (Inspired by haxeflixel)
https://github.com/itzkiwisky/object.lua
Last synced: 15 days ago
JSON representation
A simple lua lib to create objects (Inspired by haxeflixel)
- Host: GitHub
- URL: https://github.com/itzkiwisky/object.lua
- Owner: itzKiwiSky
- License: other
- Created: 2023-09-08T18:38:35.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2023-09-08T21:16:51.000Z (over 1 year ago)
- Last Synced: 2024-11-08T18:12:45.837Z (2 months ago)
- Language: Lua
- Homepage:
- Size: 10.7 KB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Object.lua
Object.lua is a simple library to create objects
## Creating an object
To create a object, you can call the constructor
```lua
object.new(_x, _y)
```
The `x` and `y` parameters are optional.here a simple example
```lua
function love.load()
object = require 'object'player = object.new() -- create a new Object
player:loadGraphic("resources/images/player.png") -- load the image to object
endfunction love.draw()
player:draw() -- draw the object
end
```Object.lua also support animation with spritesheet and a map file.
```lua
function love.load()
object = require 'object'player = object.new() -- create a new object
player:loadSparrow("resources/images/player") -- load the spritesheet and the map file (it need be with the same name example : player.png, player.json) [check the resources files to see the player]
player:registerAnimation("walk_down", {1, 2, 1, 3}) -- setup the animation based on quad indexes
player:registerAnimation("walk_up", {7, 8, 7, 9})
player:registerAnimation("walk_dir", {4, 5, 4, 6})
player:setAnimation("walk_dir", 5, true)
endfunction love.draw()
player:draw()
endfunction love.update(elapsed)
player:update(elapsed)
end
```you can also control how the object will be displayed with some variables.
```lua
function love.load()
object = require 'object'player = object.new() -- create a new Object
player:loadGraphic("resources/images/player.png") -- load the image to object-- set the object position --
player.x = love.graphics.getWidth()
player.y = love.graphics.getHeight()-- or you can get the easy way --
player:centerScreen()-- and also center the origin point --
player:centerOrigin()-- and flip it horizontally or vertically --
player:flipX(true) -- now the object is flipped on X
player:flipY(false) -- and here the object is on normal direction
end
```Object.lua also have built-in functions to hitboxes, so you don't need to setup any hitbox.
When you create a object a hitbox is automatically created.
```lua
object:updateHitbox()
```## List of functions
| Constructor |
|---|
| new() || Function | Description |
|---|---|
| loadGraphic(_imagePath) | Load a image to the object |
| loadSparrow(_path) | Load a spritesheet and a map file allowing animations() |
| registerAnimation(_animationName, _quadIndexes) | Register a new animation based on indexes |
| setAnimation(_animationName) | set and play the animation |
| centerScreen() | center the object position on the center of the screen |
| centerOrigin() | center the origin point of the object to the center |
| updateHitbox() | update the hitbox size and position |
| flipX(_enable) | enable or disable the horizontal flip |
| flipY(_enable) | enable or disable the vertical flip |
| draw() | draw the object |
| update(dt) | update the object if has animations |## list of variables
```lua
object.x
object.
object.sizeX
object.sizeY
object.angle
object.originX
object.originY
object.hitbox.x
object.hitbox.y
object.hitbox.w
object.hitbox.h
object.animation.frame
object.animation.currentAnimation
object.animation.frameRate
object.animation.speed
object.animation.animationsPlaying
```# Credits
### [HaxeFlixel (Inspiration)](https://haxeflixel.com)
### [Haxeflixel Tutorial Player](https://haxeflixel.com/documentation/sprites-and-animation/)
### [Json Library - Actboy168](https://github.com/actboy168/json.lua)