Skip to content

Quick Start: Creating Simple Textboxes

Pizza Dev edited this page May 6, 2023 · 3 revisions

It's always best to start by using the simple and static pdDialogue class. This class allows you to display dialogue boxes without any trouble.

Here's an example on how to say Hello World using pdDialogue:

import "CoreLibs/object"
import "CoreLibs/graphics"
import "pdDialogue"

pdDialogue.say("Hello, World!") 

function playdate.update()
    playdate.graphics.clear(playdate.graphics.kColorWhite)
    pdDialogue.update()
end

If you want more control over the properties of your text box, then use this code to achieve the same:

import "CoreLibs/object"
import "CoreLibs/graphics"
local gfx <const> = playdate.graphics

local width, height, padding = 390, 48, 4
local x, y = 5, 186
local text = "Hello World!"

-- Create the box with the text and dimensions
local dialogue = pdDialogueBox(text, width, height, padding)
-- Add input handlers from the helper function
playdate.inputHandlers.push(dialogue:getInputHandlers())
-- Override the function to pop the handlers When the box closes
function dialogue:onClose()
    playdate.inputHandlers.pop()
end
dialogue:enable()

function playdate.update()
	gfx.clear(gfx.kColorWhite)
	-- You only want to update the box when it's enabled
	if dialogue.enabled then
		dialogue:update()
		dialogue:draw(x, y)
	end
end

Check out our Examples to see further ways to use this library.

If you want to know about the detailed functionality of this library, then check out this Wiki-Page.

Clone this wiki locally