Love2D ๋ชจ๋“ˆ ์•Œ์•„๋ณด๊ธฐ: love ์ด๋ฆ„ ๊ณต๊ฐ„๊ณผ ์ฝœ๋ฐฑ ํ•จ์ˆ˜

[love ์ด๋ฆ„ ๊ณต๊ฐ„]
Love2D ํ”„๋ ˆ์ž„์›Œํฌ๋Š” ๋ชจ๋“  ๋‚ด์žฅ ๋ชจ๋“ˆ๊ณผ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋“ค์„ 'love'๋ผ๊ณ  ๋ถ€๋ฅด๋Š” ์ด๋ฆ„ ๊ณต๊ฐ„ ์•„๋ž˜์— ๋ฐฐ์น˜ํ•œ๋‹ค. ์ด๋ฆ„ ๊ณต๊ฐ„์€ ํ…Œ์ด๋ธ”๋กœ ๊ตฌํ˜„๋˜์–ด ์žˆ์œผ๋ฉฐ ์‹คํ–‰ ์‹œ๊ฐ„ ์ค‘์—๋„ ์œ ์—ฐํ•˜๊ฒŒ ๋ณ€๊ฒฝํ•  ์ˆ˜ ์žˆ๋‹ค.

conf.lua๋ฅผ ๋ณ€๊ฒฝํ•˜์ง€ ์•Š์•˜๋‹ค๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์€ ๋ชจ๋“ˆ๋“ค์ด ๊ธฐ๋ณธ์ ์œผ๋กœ ๋กœ๋“œ๋˜์–ด ์žˆ๋‹ค.
audio
data
event
filesystem
font
graphics
image
joystick
keyboard
math
mouse
physics
sound
system
thread
timer
touch
video
window

์ด ์™ธ์— ๋‹ค๋ฅธ ๋ชจ๋“ˆ๋“ค์€ ์ง์ ‘ ๋ช…์‹œ์ ์œผ๋กœ require ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด์„œ ๋ชจ๋“ˆ์„ ๋ถˆ๋Ÿฌ์™€์•ผ ํ•œ๋‹ค.

๋˜, thread ๋ชจ๋“ˆ์„ ํ†ตํ•ด ์ƒ์„ฑ๋œ ์ƒˆ๋กœ์šด ์Šค๋ ˆ๋“œ๋Š” data, filesystem, thread ๋ชจ๋“ˆ์„ ์ œ์™ธํ•œ ๋‹ค๋ฅธ ๋ชจ๋“ˆ์„ ๋กœ๋“œํ•˜์ง€ ์•Š๋Š”๋‹ค. ์ด ๊ฒฝ์šฐ์—๋„ ์ง์ ‘ require ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•ด์•ผ ํ•œ๋‹ค.

[์ฝœ๋ฐฑ ํ•จ์ˆ˜]
๋ชจ๋“  ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋Š” ๋ฐ˜ํ™˜๊ฐ’์ด ์—†๋‹ค. (์˜ˆ์™ธ์ ์œผ๋กœ, love.run๊ณผ love.quit๋Š” ๋ฐ˜ํ™˜๊ฐ’์ด ์กด์žฌํ•œ๋‹ค.) ๋Œ€์‹ , ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ ์ด์œ ๋‚˜ ๊ด€๋ จ ๋ฐ์ดํ„ฐ๋ฅผ ์ธ์ž๋กœ ์ „๋‹ฌํ•˜๊ธฐ ๋•Œ๋ฌธ์— ๋งค๊ฐœ๋ณ€์ˆ˜์— ๋Œ€ํ•œ ์„ค๋ช…์„ ๋‹ฌ์•„๋‘์—ˆ๋‹ค. ๋งค๊ฐœ๋ณ€์ˆ˜๋Š” '(์ด๋ฆ„: ํƒ€์ž…, ...)'์˜ ํ˜•์‹์œผ๋กœ ํ‘œ๊ธฐํ•œ๋‹ค.

Love2D 11.5๋ฅผ ๊ธฐ์ค€์œผ๋กœ ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋“ค์ด ์‚ฌ์šฉ๋˜๊ณ  ์žˆ๋‹ค.
love.conf (t: table)
love.directorydropped (path: string)
love.displayrotated (index: number, orientation: DisplayOrientation)
love.draw ()
love.errorhandler (msg: string)
love.filedropped (file: DroppedFile)
love.focus (focus: boolean)
love.gamepadaxis (joystick: Joystick, axis: GamepadAxis, value: number)
love.gamepadpressed (joystick: Joystick, button: GamepadButton)
love.gamepadreleased (joystick: Joystick, button: GamepadButton)
love.joystickadded (joystick: Joystick)
love.joystickaxis (joystick: Joystick, axis: number, value: number)
love.joystickhat (joystick: Joystick, hat: number, direction: JoystickHat)
love.joystickpressed (joystick: Joystick, button: number)
love.joystickreleased (joystick: Joystick, button: number)
love.joystickremoved (joystick: Joystick)
love.keypressed (key: KeyConstant, scancode: Scancode, isrepeat: boolean)
love.keyreleased (key: KeyConstant, scancode: Scancode)
love.load (arg: table, unfilteredArg: table)
love.lowmemory ()
love.mousefocus (focus: boolean)
love.mousemoved (x: number, y: number, dx: number, dy: number, istouch: boolean)
love.mousepressed (x: number, y: number, button: number, istouch: boolean, presses: number)
love.mousereleased (x: number, y: number, button: number, istouch: boolean, presses: number)
love.quit ()
love.resize (w: number, h: number)
love.run ()
love.textedited (text: string, start: number, length: number)
love.textinput (text: string)
love.threaderror (thread: Thread, errorstr: string)
love.touchmoved (id: light userdata, x: number, y: number, dx: number, dy: number, presses: number)
love.touchpressed (id: light userdata, x: number, y: number, dx: number, dy: number, presses: number)
love.touchreleased (id: light userdata, x: number, y: number, dx: number, dy: number, presses: number)
love.update (dt: number)
love.visible (visible: boolean)
love.wheelmoved (x: number, y: number)

[์ปค์Šคํ…€ ์ฝœ๋ฐฑ ํ•จ์ˆ˜]
์ฝœ๋ฐฑ ํ•จ์ˆ˜๋Š” 'love.handlers'์— ์ด๋ฆ„์„ ๋“ฑ๋กํ•˜๋ฉด ์ƒˆ๋กœ ์ถ”๊ฐ€ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋งŒ์•ฝ, 'onGameCrashed'๋ผ๋Š” ์ด๋ฒคํŠธ๋ฅผ ๋“ฑ๋กํ•˜๊ณ ์ž ํ•œ๋‹ค๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™์ด ํ•˜๋ฉด ๋œ๋‹ค.
love.handlers['onGameCrashed'] = function () end

love.event.quit๋Š” love.quit์™€ ๊ฐ™์ง€ ์•Š๋‹ค. ํŠน์ • ์ด๋ฒคํŠธ๋ฅผ ๋ฐœ์ƒ์‹œํ‚ฌ๋ ค๋ฉด ์ง์ ‘ love.event.push ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด์„œ ์ด๋ฒคํŠธ์˜ ์ด๋ฆ„๊ณผ ์ธ์ž๋ฅผ ์ „๋‹ฌํ•˜์—ฌ์•ผ ํ•œ๋‹ค.

[์ž์ฃผ ์“ฐ์ด๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜]
love.conf (t: table)
t๋Š” ์„ค์ •๊ฐ’์„ ์ €์žฅํ•  ํ…Œ์ด๋ธ”์ด๋‹ค.

์‚ฌ์‹ค ์œ„ํ‚ค ๋ถ„๋ฅ˜์— ๋”ฐ๋ฅด์ž๋ฉด love.conf ํ•จ์ˆ˜๋„ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋กœ ์ทจ๊ธ‰๋œ๋‹ค. ์™œ๋ƒํ•˜๋ฉด, ๋‹ค๋ฅธ ํ•จ์ˆ˜์— ์˜ํ•ด ๋ถˆ๋ ค์ง€๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.

love.draw ()
ํ™”๋ฉด์„ ๊ฐฑ์‹ ํ•˜๋Š”๋ฐ ์‚ฌ์šฉ๋˜๋Š” ํ•จ์ˆ˜์ด๋‹ค. ๋‹จ๋…์œผ๋กœ ํ˜ธ์ถœํ•˜์ง€ ์•Š๊ณ , love.run์˜ ์ œ์–ด๋ฅผ ๋ฐ›๋Š”๋‹ค.

love.errorhandler (msg: string)
msg๋Š” ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•œ ์›์ธ์ด๋‹ค.

error ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๊ฑฐ๋‚˜, ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ด ์ฝœ๋ฐฑ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋œ๋‹ค.

love.keypressed (key: KeyConstant, scancode: Scancode, isrepeat: boolean)
key๋Š” ์ž…๋ ฅ๋œ ํ‚ค๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. scancode๋Š” ์ข€ ๋” ์ €์ˆ˜์ค€์˜ ์ œ์–ด๋ฅผ ์œ„ํ•ด ์ง์ ‘ ์Šค์บ” ์ฝ”๋“œ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. isrepeat๋Š” ํ‚ค๊ฐ€ ๋ฐ˜๋ณต๋˜๊ณ  ์žˆ๋Š”์ง€๋ฅผ ์•Œ๋ฆฐ๋‹ค. ์ด๋Š” ์‹œ์Šคํ…œ์˜ ์„ค์ •์— ๋”ฐ๋ผ ๋™์ž‘์ด ๋‹ค๋ฅผ ์ˆ˜๋„ ์žˆ๋‹ค.

ํ‚ค๊ฐ€ ์ž…๋ ฅ๋  ๋•Œ, ์ด ์ฝœ๋ฐฑ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋œ๋‹ค.

love.load (arg: table, unfilteredArg: table)
arg๋Š” ํ”„๋กœ๊ทธ๋žจ ์‹คํ–‰ ์‹œ ๊ฐ™์ด ์ „๋‹ฌ๋œ ๋ช…๋ น ์ค„ ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋‹ด๊ณ  ์žˆ๋‹ค, untilteredArg๋Š” arg์™€ ๋น„์Šทํ•˜์ง€๋งŒ ํ•„ํ„ฐ๋ง๋˜์ง€ ์•Š์€(๊ฒŒ์ž„ ์‹คํ–‰ ์‹œ ์˜ต์…˜ ์ง€์ • ๋“ฑ) ๋งค๊ฐœ๋ณ€์ˆ˜๋ฅผ ๋‹ด๊ณ  ์žˆ๋‹ค.

love.run ์ฝœ๋ฐฑ ํ•จ์ˆ˜์— ์˜ํ•ด์„œ ๊ฒŒ์ž„ ์‹คํ–‰ ์‹œ ์ตœ์ดˆ๋กœ ๋‹จ ํ•œ๋ฒˆ๋งŒ ์‹คํ–‰๋œ๋‹ค. ๋Œ€๋ถ€๋ถ„์˜ ์ฝ”๋“œ๋Š” ์—ฌ๊ธฐ์„œ ์ดˆ๊ธฐํ™”ํ•˜๋Š” ๊ฒƒ์ด ์ข‹๋‹ค.

love.mousemoved (x: number, y: number, dx: number, dy: number, istouch: boolean)
x์™€ y๋Š” ํ˜„์žฌ ๋งˆ์šฐ์Šค์˜ ์ขŒํ‘œ๋ฅผ 0๋ถ€ํ„ฐ love.graphics.getWidth()-1, love.graphics.getHeight()-1 ์‚ฌ์ด์˜ ๊ฐ’์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. dx์™€ dy๋Š” ์ด์ „ ์ž…๋ ฅ๊ณผ ๋น„๊ตํ•˜์—ฌ ์ƒ๋Œ€์ ์ธ ์ขŒํ‘œ๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค. istouch๋Š” ํ„ฐ์น˜์Šคํฌ๋ฆฐ์˜ ํ„ฐ์น˜์ธ์ง€ ์•„๋‹Œ์ง€๋ฅผ ๋‚˜ํƒ€๋‚ธ๋‹ค.

๋งˆ์šฐ์Šค ์ž…๋ ฅ์„ ์‚ฌ์šฉํ•  ๋•Œ, ์•„๋ž˜์˜ mousepressed ์ฝœ๋ฐฑ ํ•จ์ˆ˜์™€ ํ•จ๊ป˜ ์‚ฌ์šฉํ•˜๊ธฐ ์ข‹์€ ํ•จ์ˆ˜์ด๋‹ค.

love.mousepressed (x: number, y: number, button: number, istouch: boolean, presses: number)
button์€ ์ž…๋ ฅ๋œ ๋งˆ์šฐ์Šค์˜ ๋ฒ„ํŠผ์„ 1=์™ผ์ชฝ, 2=์˜ค๋ฅธ์ชฝ, 3=ํœ  ํด๋ฆญ ์œผ๋กœ ๋‚˜ํƒ€๋‚ธ๋‹ค. presses๋Š” ๋ช‡๋ฒˆ์„ ์—ฐ์†ํ•ด์„œ ๋ˆ„๋ฅด๋Š”์ง€๋ฅผ ์•Œ๋ ค์ฃผ๊ณ  ์ด๋Š” ์งง์€ ์‹œ๊ฐ„ ์ดํ›„ ์ดˆ๊ธฐํ™”๋˜๋ฉฐ ์‹œ๊ฐ„ ๋‚ด๋กœ ๊ณ„์† ์—ฐ์† ์ž…๋ ฅํ•˜๋ฉด ๊ฐ’์ด ์ฆ๊ฐ€ํ•œ๋‹ค.

love.quit ()
๋ฐ˜ํ™˜๊ฐ’์ด true์ผ ๊ฒฝ์šฐ, ๊ฒŒ์ž„ ์ข…๋ฃŒ๋ฅผ ์ค‘๋‹จํ•˜๊ณ  ๊ทธ ์ด์™ธ์— ๊ฐ’์€ ๊ฒŒ์ž„์„ ๊ทธ๋Œ€๋กœ ์ข…๋ฃŒ์‹œํ‚จ๋‹ค.

์ด ์ฝœ๋ฐฑ ํ•จ์ˆ˜๋Š” ๊ฒŒ์ž„ ์ข…๋ฃŒ ์ง์ „์— ์‹คํ–‰๋˜์–ด์•ผ ํ•˜๋Š” ๋ฃจํ‹ด์„ ์ž‘์„ฑํ•  ๋•Œ ์œ ์šฉํ•˜๋‹ค.

love.update (dt: number)
dt๋Š” ๋งˆ์ง€๋ง‰์œผ๋กœ update๊ฐ€ ํ˜ธ์ถœ๋œ ์ดํ›„ ์ง€๋‚œ ์‹œ๊ฐ„์„ ๋‚˜ํƒ€๋‚ธ๋‹ค.

๊ฒŒ์ž„์˜ ์—…๋ฐ์ดํŠธ ์ฃผ๊ธฐ๋ฅผ ์•Œ๋ฆฌ๋Š” ์ฝœ๋ฐฑ ํ•จ์ˆ˜์ด๋‹ค. ๊ฒŒ์ž„์ด ์ž‘๋™ํ•˜๋ ค๋ฉด ์—†์–ด์„œ๋Š” ์•ˆ๋  ์ค‘์š”ํ•œ ์ฝœ๋ฐฑ ํ•จ์ˆ˜์ด์ง€๋งŒ, ๋ฐ˜๋“œ์‹œ ๊ฒŒ์ž„์˜ ๋ฐ์ดํ„ฐ ๊ฐฑ์‹ ์ด update ํ•จ์ˆ˜ ๋‚ด์—์„œ๋งŒ ์ผ์–ด๋‚˜์•ผ ํ•  ํ•„์š”๋Š” ์—†๋‹ค.


[์ด๋ฒคํŠธ ์‚ฌ์šฉ ์‹œ ์ฃผ์˜์ ]
1. ์ด๋ฒคํŠธ๋Š” ๋ฐ˜๋“œ์‹œ ์ œ์–ด๊ฐ€ love.run์œผ๋กœ ๋Œ์•„์™€์•ผ๋งŒ ์‹คํ–‰๋œ๋‹ค. ๋‹ค์Œ๊ณผ ๊ฐ™์€ ์ฝ”๋“œ๋Š” ๊ทธ ์ž๋ฆฌ์—์„œ ์ฆ‰์‹œ ์ข…๋ฃŒํ•˜์ง€ ์•Š์œผ๋ฉฐ, ์˜ค๋ฅ˜๋ฅผ ์ผ์œผํ‚จ๋‹ค. ๊ฒŒ์ž„์„ ์ข…๋ฃŒ์‹œํ‚ค๋Š” ๊ฒƒ์€ love.run ํ•จ์ˆ˜๊ฐ€ ๋๋‚  ๋•Œ์ด๋‹ค.
function love.load () local f = nil; if not f then love.event.quit() end f(); end
2. ์ฝœ๋ฐฑ ํ•จ์ˆ˜์™€ ์ด๋ฒคํŠธ๋Š” ๋‹ค๋ฅด๋‹ค. ์ •ํ™•ํžˆ๋Š” ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•˜๋ฉด ์ฝœ๋ฐฑ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋˜๋Š”๋ฐ ์ฝœ๋ฐฑ ํ•จ์ˆ˜๊ฐ€ ํ˜ธ์ถœ๋œ๋‹ค๊ณ  ๋ฐ˜๋“œ์‹œ ์ด๋ฒคํŠธ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์€ ์•„๋‹ˆ๋‹ค. ์•„๋ž˜๋Š” ๊ฐ€๋Šฅํ•œ ์ด๋ฒคํŠธ๋“ค์˜ ๋ชฉ๋ก์ด๋‹ค.
directorydropped
displayrotated
errorhandler
filedropped
focus
gamepadaxis
gamepadpressed
gamepadreleased
joystickadded
joystickaxis
joystickhat
joystickpressed
joystickreleased
joystickremoved
keypressed
keyreleased
lowmemory
mousefocus
mousemoved
mousepressed
mousereleased
quit
resize
textedited
textinput
threaderror
touchmoved
touchpressed
touchreleased
visible
wheelmoved
3. ์ด๋ฒคํŠธ๋Š” ์Šค๋ ˆ๋“œ ๊ฐ„์— ๊ณต์œ ๋˜์ง€ ์•Š๋Š”๋‹ค.