Categories
Love2D and Lua

2D World Coordinate (x-axis, y-axis)

The 2D coordinate system that we use in video games is a relatively straightforward one. Everything is measured in pixels from the top left corner. Nearly all of the drawing commands that we do will be expressed in these coordinates.

The top left corner, (0,0) origin with width and height has a value of zero, zero. The x-axis value (positive) increase moving the left to the right direction. The y-axis value increase moving top to bottom direction.

Categories
Love2D and Lua

Structure of Love2d

love.load()

 love.load to do one-time setup of your game

love.update(dt)

 love.update which is used to manage your game’s state frame-to-frame. Much like a game loop

love.draw()

 love.draw() which is used to render the game state onto the screen.

Example

Draw a rectangle and it continues to expand in height and width

-- Load some default values for our rectangle.
function love.load()
    x, y, w, h = 20, 20, 60, 20
end
 
-- Increase the size of the rectangle every frame.
function love.update(dt)
    w = w + 1
    h = h + 1
end
 
-- Draw a coloured rectangle.
function love.draw()
    -- In versions prior to 11.0, color component values are (0, 102, 102)
    love.graphics.setColor(0, 0.4, 0.4)
    love.graphics.rectangle("fill", x, y, w, h)
end
Categories
Love2D and Lua

Running a Love2D game from Visual Studio Code.

From a folder that contains a main.lua file.

On the VSC’s project folder has the main.lua file, and the Pixelbyte’s Love2D extension support installed. To run the main.lua file just press ALT + L (default keybinding) to run the Love2D game.

Categories
Love2D and Lua

Setup Pixelbyte’s Love2D Extension for Visual Code (Windows)

https://marketplace.visualstudio.com/items?itemName=pixelbyte-studios.pixelbyte-love2d

Keybindings (Default – ALT + L)

  • Run Love2D on the current project folder:
  • NOTE: YOU CAN CHANGE THESE KEYS IN File->Preferences->Settings
Win: {"key": "Alt+L,", "command":"pixelbyte.love2d.run"}

Path of the love.exe program (Default)

  • Set the path to the Love2D executable:
  • Change these in File->Preferences->Settings
"pixelbyte.love2d.path" : "C:\Program Files\Love\love.exe"
Categories
Love2D and Lua

Download and fresh install Love2D version 11.3

Love2D come with battery include (Lua application). So no need to download and install Lua.

https://love2d.org/wiki/Getting_Started