Advertising (This ad goes away for registered users. You can Login or Register)

[3DS] [LovePotion] [Tutorial] How to display text

Post here your guides, tips, how-to, etc...
Locked
Daffy
Posts: 2
Joined: Thu Dec 31, 2015 7:26 am

[3DS] [LovePotion] [Tutorial] How to display text

Post by Daffy »

Index

• Introduction
• Raw Code
• Code Explanation
• Understanding love.graphics.print
• Conclusion


Introduction

This tutorial will teach you how to display text using LövePotion. To do so, you will need:

• Any text editor.
• A way to launch 3DS homebrew.
• LövePotion set and ready to go.

Raw Code

Code: Select all

-- How to draw text
function love.draw()
	love.graphics.setScreen("top")
	love.graphics.print("Top screen.", 0, 0)
	love.graphics.setScreen("bottom")
	love.graphics.print("Bottom screen.", 0, 0)
end
Code Explanation

What you see below is a comment. Comments are ignored by LövePotion and are left there for various purposes, such as leaving personal notes. To leave a comment, two hyphens must be together before your text. This is required for every line of comment that is in your code.

Code: Select all

-- How to draw text
This opens the function that draws to the screen.

Code: Select all

function love.draw()
This sets the focus to the top screen.

Code: Select all

love.graphics.setScreen("top")
This displays the given text in the given coordinates.

Code: Select all

love.graphics.print("Top screen.", 0, 0)
This sets the focus to the bottom screen.

Code: Select all

love.graphics.setScreen("bottom")
This displays the given text in the given coordinates.

Code: Select all

love.graphics.print("Bottom screen.", 0, 0)
This closes the function.

Code: Select all

end
Understanding love.graphics.print

To draw text on the screens, it is important that you first understand how love.graphics.print works.

Image

The image above is the same resolution as the top screen of the 3DS. (X, Y) is where the text will be drawn. If I tell LövePotion love.graphics.print("Text", 10, 20 ), LövePotion will draw whatever is inside the quotes, in this case "Text", on the (X, Y) coordinates that I gave it, here being (10, 20). Starting from (0, 0), LövePotion will move 10 pixels to the right, 20 pixels down, and will finally draw "Text".

Image

Know that you're visually restricted to the resolution of the screen, 400x240 for the top and 320x240 for the bottom. If you use values greater or smaller than that of the resolution, part of the text may show cut off, or may not show at all. Here is an example where X is -15 and Y is 20.

Image

To display text on the bottom screen, you can follow the same guide for the top screen, keeping in mind the resolution.

Image

Image

Image

Conclusion

Open up any text editor and type what is in the Raw Code section of this tutorial. You are free to experiment and change things to your liking. Once everything is done, save it as main.lua instead of whateverthetextwouldnormallybe.txt, and place it in a directory where LövePotion can read it.

Boot LövePotion and that's that for now.
Advertising
tardisidiot
Posts: 90
Joined: Sat Apr 28, 2012 7:20 am

Re: [3DS] [LovePotion] [Tutorial] How to display text

Post by tardisidiot »

How would I go about loading games that have been created using Love into this player?
Advertising
Locked

Return to “Tutorials”