Skip to content

Quick Start: Creating Simple Textboxes

Jesse edited this page Jun 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 = 390, 48
local x, y = 5, 186
local text = "Hello World!"

-- Create the box with the text and dimensions
local dialogue = pdDialogueBox(text, width, height)
-- 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

Text can be formatted with the playdate's *simple* _markup_, though because of the way the text wrapping works _each_ _word_ _should_ _have_ _its_ _own_ _tags_!

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