Page 1 of 1

text madness

Posted: Wed Jun 08, 2022 8:53 am
by Seth144k
so i was working on an rpg prototype and decided hey, lets interact with this object! so the basic idea is that I want the object (the square at the end of the thing) to display some text which i got working. the problem is when I want to change that text. I did a circular query around the player and it doesnt seem to do anything. I want the player to lose all control of the player and then diffrent text to appear, and then regain control, and if you walk away then the text should go away. please help as i find making text very difficult in love2d

Re: text madness

Posted: Wed Jun 08, 2022 11:24 am
by ReFreezed
It's a bit unclear what you want. What text should be displayed? I'm assuming we're talking about the code in interactable.lua. Do you want each 'interactable' object to display different a text? You could add a text field to 'self' in interactable:load() and draw the text with love.graphics.print(self.text) in interactable:draw().

Code: Select all

function interactable:load()
    self.text = "foobar" -- You can use different texts for different interactables.
    -- ...
end

function interactable:draw()
    -- ...
    love.graphics.print(self.text)
    -- ...
end
The interactable's text could also be an argument for the interactable:load() function.

Code: Select all

function interactable:load(text)
    self.text = text
    -- ...
end

Re: text madness

Posted: Wed Jun 08, 2022 1:45 pm
by Andlac028
Something like this?
main.love
(50.22 KiB) Downloaded 63 times
If you reach that object, you can not move, and the keypresses are used to display next message. When all messages were displayed, control is gained to player again.

Basically I added texts and textsShown to interactable:load, then handled text draw in interactable:draw and added interactable:keypressed which is called in new love.keypressed which switches texts (see attached code)