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. ์ด๋ฒคํธ๋ ์ค๋ ๋ ๊ฐ์ ๊ณต์ ๋์ง ์๋๋ค.
๋๊ธ 1