Text Right Alignment

Hi,

I’m trying to align some text to the right but failing miserably. I know I could just tweak the x,y center positions but I have a feeling that will fall apart on different sized screens because the font size will change. Here’s absolutely everything I’ve tried so far:

--# Main
displayMode(FULLSCREEN)

-- Use this function to perform your initial setup
function setup()

end

-- This function gets called once every frame
function draw()
    -- This sets a dark background color 
    background(0, 0, 0, 255)
    fill(243, 9, 9, 255)
    local x = WIDTH * 0.5
    local y = HEIGHT * 0.9
    local lineHt = 30
    --
    textMode(CENTER)
    textAlign(RIGHT)
    text("I can has\
right alignment?", x, y)
    y = y - lineHt
    text("plz?", x, y)
    y = y - lineHt
    textAlign(CENTER)
    text("I can has\
right alignment?", x, y)
    y = y - lineHt
    text("plz?", x, y)
    y = y - lineHt
    textAlign(LEFT)
    text("I can has\
right alignment?", x, y)
    y = y - lineHt
    text("plz?", x, y)
    
    textMode(CORNER)
    y = y - lineHt
    textAlign(RIGHT)
    text("I can has\
right alignment?", x, y)
    y = y - lineHt
    text("plz?", x, y)
    y = y - lineHt
    textAlign(CENTER)
    text("I can has\
right alignment?", x, y)
    y = y - lineHt
    text("plz?", x, y)
    y = y - lineHt
    textAlign(LEFT)
    text("I can has\
right alignment?", x, y)
    y = y - lineHt
    text("plz?", x, y)
    
end

I hope it’s just that I don’t know how to properly embed a newline in a string cos that would be kinda funny.

This is a little confusing and may need to be changed in an update. In order to use text alignment you must set textWrapWidth to something other than 0. Setting textWrapWidth gives Codea an upper bound on the wrapping so that it knows to allow wrapping.

Try textWrapWidth(2000) at the start — you won’t hit the limit, but your
newlines will be respected.

I do this by measuring the text using textSize and then offsetting it.

Ok thanks Simeon. And Andrew I’ll keep your technique in mind in case I find I need to be more specific about line heights than simply creating newlines, because again the different font sizes for different resolutions might become an issues. Cheers!