เริ่มต้นเรียนรู้ Love2d
ที่จริงผมอยากทำเกมเป็นของตัวเองมานานแล้ว นานมาก ๆ ๆ ได้ทดลองจับมาหลายอย่าง ตั้งแต่แรกสุดคือหัดเขียนโปรแกรมด้วยภาษา c แต่ด้วยความสามารถและกำลังใจที่มีไม่ถึงทำให้ผมต้องละทิ้งการเขียนโปรแกรมเหล่านั้นไป หลังจากนั้นผมก็ได้มีโอกาสจับเกมเอ็นจินอย่างเช่น rpg maker หลาย ๆ เวอร์ชัน แต่ด้วยความขี้เกียจทำให้ผมไปไม่ถึงไหนอีกเช่นเดิม
ในตอนนี้ผมได้กลับมาจับการทำเกมอีกครั้งเนื่องจากต้องการหาอะไรทำนอกเหนือไปจากเวลาที่แต่งนิยาย และที่ผมเลือกขึ้นมาใช้ก็คือ love2d
love2d เป็นเกมเอ็นจินที่เขียนขึ้นด้วยภาษา Lua ภาษาที่เรียบง่ายแต่ทรงประสิทธิภาพ ที่จริงแล้วผมเลือกภาษานี้ก็เพราะอะไร ๆ มันดูแล้วไม่สับสนเท่าภาษาอื่นแค่นั้นแหละ
เริ่มต้นการหัดเรียนรู้ love2d ด้วยการโหลดตัวเกมเอ็นจินมาติดตั้ง ผมเลือกโหลดแบบ binary portable โดยไม่ต้องติดตั้งลงเครื่องเพราะมีประสบการณ์ในการติดตั้ง love2d มาก่อนแล้ว สิ่งแรกที่ผมทำก็คือทำ shortcut สำหรับรัน love ผ่าน notepad++ ที่ผมใช้พัฒนาเกมด้วย love2d … กลายเป็นว่าคอมพิวเตอร์เครื่องที่ผมใช้ไม่มี notepad++ ผมต้องโหลดมาติดตั้งใหม่ดีที่ตัว notepad++ มีขนาดเล็กเลยไม่เสียเวลาเท่าไร
ผมใช้คำสั่ง Run ของ notepad++ เพื่อทำการรันเกมผ่าน notepad++ ได้เลยโดยไม่ต้องออกไปรันจากตัว shortcut ข้างนอก เมื่อเลือกคำสั่ง Run แล้วผมก็ใส่ค่าลงไปในช่องรันตามนี้ location-of-love.exe location-of-gamefolder ต้องระวังอย่าลืมช่องว่างระหว่างทั้งสองจุดด้วย ตัวอย่าง “c:/love2d/love.exe c:/mygame” ง่าย ๆ หลังจากนี้เราก็รันเกมที่เรากำลังเขียนจากใน notepad ++ ได้เลย
สิ่งแรกที่ผมทำหลังจากติดตั้ง shortcut นี้เรียบร้อยแล้วก็คือการสร้างตัวอย่างยอดนิยม Hello world โดยการสร้างไฟล์ main.lua ขึ้นมาในโฟลเดอร์เกม login-runner จากนั้นเขียนชุดคำสั่ง helloworld แล้วสั่งรัน
function love.draw() love.graphics.print("Hello World", 400, 300) end
นี่เป็นตัวอย่างจาก wiki ของ love2d.org โดยตรง โดยความหมายของมันก็คือวาดตัวหนังสือ Hello World ลงที่จุด 400 300 ของ หน้าต่าง ภาพที่ได้มาก็จะเป็นอย่างนี้

และผมก็ได้เห็นปัญหา ค่าปริยายของ love2d นั้นตั้งมาให้หน้าจอมีขนาดใหญ่กว่าหน้าเว็บผมมาก การที่จะเขียนบล็อกต่อไปเรื่อย ๆ จะทำให้ผมต้องเสียเวลาย่อขยายภาพประกอบหลายครั้ง ดังนั้นผมจึงต้องหาทางลดขนาดของหน้าจอให้เหมาสมสำหรับการเขียนบล็อกก่อน แล้วจากนี้ค่อยเพิ่มขนาดขึ้นมาใหม่ก็ยังไม่สาย
วิธีการก็คือสร้างไฟล์ conf.lua ขึ้นมาในโฟลเดอร์เกม แล้วใส่ค่าเหล่านี้ลงไป *(สำหรับเวอร์ชัน 0.9.1 เวอร์ชันอื่นที่แตกต่างอาจจะมีรูปแบบการตั้งค่าต่างกัน)
function love.conf(t) t.identity = nil -- The name of the save directory (string) t.version = "0.9.1" -- The LÖVE version this game was made for (string) t.console = false -- Attach a console (boolean, Windows only) t.window.title = "Login Runner" -- The window title (string) t.window.icon = nil -- Filepath to an image to use as the window's icon (string) t.window.width = 640 -- The window width (number) t.window.height = 360 -- The window height (number) t.window.borderless = false -- Remove all border visuals from the window (boolean) t.window.resizable = false -- Let the window be user-resizable (boolean) t.window.minwidth = 1 -- Minimum window width if the window is resizable (number) t.window.minheight = 1 -- Minimum window height if the window is resizable (number) t.window.fullscreen = false -- Enable fullscreen (boolean) t.window.fullscreentype = "normal" -- Standard fullscreen or desktop fullscreen mode (string) t.window.vsync = true -- Enable vertical sync (boolean) t.window.fsaa = 0 -- The number of samples to use with multi-sampled antialiasing (number) t.window.display = 1 -- Index of the monitor to show the window in (number) t.window.highdpi = false -- Enable high-dpi mode for the window on a Retina display (boolean). Added in 0.9.1 t.window.srgb = false -- Enable sRGB gamma correction when drawing to the screen (boolean). Added in 0.9.1 t.modules.audio = true -- Enable the audio module (boolean) t.modules.event = true -- Enable the event module (boolean) t.modules.graphics = true -- Enable the graphics module (boolean) t.modules.image = true -- Enable the image module (boolean) t.modules.joystick = true -- Enable the joystick module (boolean) t.modules.keyboard = true -- Enable the keyboard module (boolean) t.modules.math = true -- Enable the math module (boolean) t.modules.mouse = true -- Enable the mouse module (boolean) t.modules.physics = true -- Enable the physics module (boolean) t.modules.sound = true -- Enable the sound module (boolean) t.modules.system = true -- Enable the system module (boolean) t.modules.timer = true -- Enable the timer module (boolean) t.modules.window = true -- Enable the window module (boolean) end
ผมได้เปลี่ยน game tile เป็น Login Runner และปรับขนาดหน้าจอต่างเกมเป็น 640 * 360 (widescreen ขนาดเล็ก) จากนั้นทำการรันและพบว่าหน้าต่างเกมมีขนาดเล็กลงเหมาะสมกับการทำภาพประกอบบล็อกมากยิ่งขึ้น

รู้สึกว่าบล็อกนี้จะยาวไปแล้ว ผมคิดว่าขึ้นหน้าใหม่ดีกว่า วันนี้คงได้อะไรหลายอย่างอยู่เหมือนกัน