Post: 3DS: How to display text in LövePotion
03-25-2016, 04:29 AM #1
Hydrogen
Super Mod
(adsbygoogle = window.adsbygoogle || []).push({});
3DS: How to display text in LövePotion
[/B]

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:

    

-- 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.

    -- How to draw text


This opens the function that draws to the screen.

    function love.draw()


This sets the focus to the top screen.

    love.graphics.setScreen("top")


This displays the given text in the given coordinates.

    love.graphics.print("Top screen.", 0, 0)


This sets the focus to the bottom screen.

    love.graphics.setScreen("bottom")


This displays the given text in the given coordinates.

    love.graphics.print("Bottom screen.", 0, 0)


This closes the function.

    end


Understanding love.graphics.print:

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

You must login or register to view this content.


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”.

You must login or register to view this content.


Know that you’re visually restricted to the resolution of the screen, 400×240 for the top and 320×240 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.

You must login or register to view this content.


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

1st: You must login or register to view this content.

2nd: You must login or register to view this content.

3rd: You must login or register to view this content.


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.


Source: You must login or register to view this content.

Cheers, Hydrogen Hi

Copyright © 2024, NextGenUpdate.
All Rights Reserved.

Gray NextGenUpdate Logo