Predefined text positions

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
nibl
Regular
Posts: 36
Joined: Sun Feb 14, 2010 2:59 am
Projects: Lit - Literacy Teaching Game
Contact:

Predefined text positions

#1 Post by nibl »

I need to freely place text anywhere on the screen. How can I define positions and use them for text like I do for images? e.g.

Code: Select all

$ mypos1 = Position(xpos=0.1, xanchor=0.1, ypos=0.1, yanchor=0.1)

"Hello world" at mypos1
I know I can use:

Code: Select all

$ ui.at(Position(xpos=0.2, xanchor=0.2, ypos=0.2, yanchor=0.2))
$ ui.text("Hello world")
but that makes the script less readable when the statements pile up.

I also read that Position is deprecated in favour of ATL, but can't find any simple example of how to position text anywhere on the screen.

Thanks.

Asphodel
Regular
Posts: 28
Joined: Sat Jan 17, 2009 1:40 am
Contact:

Re: Predefined text positions

#2 Post by Asphodel »

Beware, untested code.

Have you tried something like this?:

Code: Select all

$ mypos1 = Position(xpos=0.1, xanchor=0.1, ypos=0.1, yanchor=0.1)
$ mypos2 = Position(xpos=0.2, xanchor=0.2, ypos=0.2, yanchor=0.2)
python:
  def textat(text, pos):
    ui.at(pos)
    ui.text(text)

$ textat("Hello", mypos1)
$ textat("World", mypos2)

Colo
Newbie
Posts: 21
Joined: Sat Mar 06, 2010 8:42 am
Projects: Some Testgames ^^
Location: Germany
Contact:

Re: Predefined text positions

#3 Post by Colo »

Code: Select all

  def textat(text, pos):
    ui.at(pos)
    ui.text(text)
He does not want to use the ui code. I can understand his Problems with it, because it just pops up and does not take slow cps into account...
Real stregth is to show weakness.

chronoluminaire
Eileen-Class Veteran
Posts: 1153
Joined: Mon Jul 07, 2003 4:57 pm
Completed: Elven Relations, Cloud Fairy, When I Rule The World
Tumblr: alextfish
Skype: alextfish
Location: Cambridge, UK
Contact:

Re: Predefined text positions

#4 Post by chronoluminaire »

You probably want the ParameterizedText function.

That page has examples such as:

Code: Select all

init:
    image text1 = renpy.ParameterizedText(ypos=0.25)

show text "centered."
show text1 "1/4 of the way down the screen."
Note that you can also provide an "at clause" to the "show text" command just like you would when showing an image:

Code: Select all

init:
    $ topleft = Position(xpos=0.0, xanchor='left', ypos=0.0, yanchor='top')
show text "This is in the\ntop corner" at topleft
There's probably also a way to do this with ATL, but I don't understand ATL yet.
I released 3 VNs, many moons ago: Elven Relations (IntRenAiMo 2007), When I Rule The World (NaNoRenO 2005), and Cloud Fairy (the Cute Light & Fluffy Project, 2009).
More recently I designed the board game Steam Works (published in 2015), available from a local gaming store near you!

number473
Regular
Posts: 195
Joined: Tue Dec 15, 2009 4:20 am
Projects: The Duke's Daughter
Location: Cape Town
Contact:

Re: Predefined text positions

#5 Post by number473 »

chronoluminaire wrote:

Code: Select all

init:
    $ topleft = Position(xpos=0.0, xanchor='left', ypos=0.0, yanchor='top')
show text "This is in the\ntop corner" at topleft
There's probably also a way to do this with ATL, but I don't understand ATL yet.
If you wanted to use ATL here I think you would want something like this (untested):

Code: Select all

init:
    transform topleft:
        xalign = 0.0, yalign = 0.0

show text "This is in the\ntop corner" at topleft

## If you wanted to do it without using a transform
show text "This is in the\ntop corner":
    xalign = 0.0, yalign = 0.0
Mental weather report: Cloudy with a possibility of brain storms.

nibl
Regular
Posts: 36
Joined: Sun Feb 14, 2010 2:59 am
Projects: Lit - Literacy Teaching Game
Contact:

Re: Predefined text positions

#6 Post by nibl »

Many Thanks, ParameterizedText() works best of all solutions so far.

The problem with UI functions is that I need pauses in between showing texts and UI always clears its previous text. Or is there a way to stop that? The only way I found was using layers, which just adds complexity.

My goal is to make the code easily readable and editable by a non-programmer. I probably was not clear enough on that in my initial question.

chronoluminaire wrote:

Code: Select all

init:
    $ topleft = Position(xpos=0.0, xanchor='left', ypos=0.0, yanchor='top')
show text "This is in the\ntop corner" at topleft
If I use the default show text function together with Position(), how do I set a created style?
(Created with style.create)

duanemoody
Regular
Posts: 100
Joined: Fri Oct 02, 2009 2:32 pm
Projects: American Jurassic
Organization: Pier 7 Media
Location: Arizona
Contact:

Re: Predefined text positions

#7 Post by duanemoody »

All of this is nifty, but how do I center text inside dialogue (i.e. define a paragraph as horizontally centered text)? The examples I've found in this forum don't work for me.

Post Reply

Who is online

Users browsing this forum: Google [Bot], Ocelot