Align Charakter animations with different size

  • #1, by stothewSaturday, 22. September 2018, 12:18 A year ago
    Hi!

    I have a problem with Character alignment. To get the right textposition while talking i cut the talking animation direcly over the head of the character. On the other animations i have some "blank space" over the head because some animations need more space e.g. "grap over head". Now when my Char talks he gets jumpy. (Guess it´s caused by different "basesize" for scaling")

    so how can i align different animations with different "image size" to scale the same?
    i tried to move the talks down in vis editor so all have the exact same "animation center" but with no luck.

    Any Ideas are welcome smile

    Thanks!

    Forum Fan

    125 Posts


  • #2, by afrlmeSaturday, 22. September 2018, 13:27 A year ago
    I believe it automatically displays texts above the canvas itself. You could force the texts with Lua script, but ideally you should have created all of the animations for the same character with the same canvas size & aligned them in the image files rather than the editor - less messing about later on.

    Imperator

    6812 Posts

  • #3, by stothewSaturday, 22. September 2018, 13:36 A year ago
    yes thats what i did. (all same size) but for talk the text would be too high. so i cut the "blank space" over the head. (but need the space in other animations)

    OK, i see i had to recalculate the text pos for talk.... is there any way to get the "normal calculated" value and add something? because if i use
    local owner = text:getLink(VTextOwner)
    local pos = owner:getPoint(VCharacterPosition)
        pos.y = pos.y + 30
        text:setValue(VTextPosition, pos)
        return true
    1
    2
    3
    4
    5
    6

    i override it and i had to detect edges and sacle ect again.. would be mutch easier to get the "nomal calculated" value / Engine based text pos and add the gap

    thanks!

    Forum Fan

    125 Posts

  • #4, by afrlmeSaturday, 22. September 2018, 14:07 A year ago
    According to Simon's Lua docs page there is a function to return the text position value for the specified character.

    local pos = getCharacterTextPosition(Characters["example"])

    I think it's used like that, however offsetting is not very accurate because you are not taking into account the scale of the character. x/y offset of say 30 pixels on a character that is scaled at 100% will end up placing the text too high on a character with a lower scale value or too low on a character that is scaled over 100%. You would also need to calculate the offset difference based on the offset value at 100% to the actual current scale value - fun no?

    If I'm being honest, it's much easier to just force all texts into bounding boxes. Less hassle & it looks neater, but each to their own.

    Imperator

    6812 Posts

  • #5, by stothewSaturday, 22. September 2018, 18:02 A year ago
    Yeah, got it!

    I´m not "Luatasic" but with the help of an older thread here it is working for me.
    may it becomes handy to somebody else, too:

    function adaptedTextPosition(text)

    local owner = text:getLink(VTextOwner)

    if text.Owner:getId().tableId == eCharacters then
        local pos = graphics.getCharacterTextPosition(game.CurrentCharacter)
        local char_current_scale = game.CurrentCharacter.CharacterSize
        local txt = text.CurrentText
        local dim = graphics.fontDimension(txt)
        local count = 0
        txt = graphics.performLinebreaks(txt)
        for _ in pairs(txt) do count = count + 1 end
        local gap = 20
        pos.y = pos.y - (dim.y*count) + gap*(char_current_scale/100)
        text.Position = pos
        return true
      end
     return false
    end

     
    registerHookFunction("setTextPosition", "adaptedTextPosition")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22

    Thanks as always AFRLme!

    Forum Fan

    125 Posts

  • #6, by afrlmeSaturday, 22. September 2018, 18:06 A year ago
    Nice one! wink

    P.S: I'm not really following what your script is doing. Fair few lines & math is not my strong suit either, but at least you seem to have figured out whatever it is that you needed to do.

    Imperator

    6812 Posts

  • #7, by stothewSaturday, 22. September 2018, 18:31 A year ago
    it recalculate the textposition y value of the currect Character based on the original one. it works with the automatic linebreak and charakter scaling. now i can have all character images the same canvas size, beause i can position the text freely.

    Forum Fan

    125 Posts

  • #8, by sebastianSunday, 23. September 2018, 01:10 A year ago
    do i get this right: graphics.performLinebreaks(string) will count the lines, but not make actual linebreaks in a text? Or will it save each line into a table field (which of course lets you count through it)?

    Thread Captain

    2336 Posts

  • #9, by stothewSunday, 23. September 2018, 01:35 A year ago
    It split the string into a table with single lines, which i count in the loop, yes u got this right smile 

    Forum Fan

    125 Posts

  • #10, by stothewSunday, 23. September 2018, 14:13 A year ago
    I updated the script because it also overrides the X value for textpos. now it calcs the Y & X values. (good enough for me)

    function adaptedTextPosition(text)

    local owner = text:getLink(VTextOwner)

    if text.Owner:getId().tableId == eCharacters and owner:getName() == 'Exalmpe' then
        -- edit me
        local gap = 15 --move text pos Y
        local spacing = 0 --min space to corners
        local maxdim = 200
        -------
        local pos = graphics.getCharacterTextPosition(game.CurrentCharacter)
        local char_current_scale = game.CurrentCharacter.CharacterSize
        local txt = text.CurrentText
        local dim = graphics.fontDimension(txt)
        local count = 0
        txt = graphics.performLinebreaks(txt)
        for _ in pairs(txt) do count = count + 1 end
        pos.y = pos.y - (dim.y*count) + gap*(char_current_scale/100)
        local resx = game.CurrentScene.Sprite:getSize().x
        if dim.x >; maxdim then
        dim.x = maxdim
        end
        local realposleft = pos.x - (dim.x/2)
        local realposright = pos.x + (dim.x/2)
        if realposleft  resx then
        pos.x = resx - dim.x/2 - spacing
        end
        text.Position = pos
        return true
      end
     return false

    end
     
    registerHookFunction("setTextPosition", "adaptedTextPosition")
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36

    @sebastian
    Also works on scrollable screens wink

    would be nice to get "FontLineWidth" insted of "maxdim" but i didn´t figure that out.

    Hope it helps smile

    Forum Fan

    125 Posts

  • #11, by afrlmeSunday, 23. September 2018, 14:22 A year ago
    The script has a few typos generated by the forum cms, you need to edit your post & save it again - always seems to fix those errors. or you could use pastebin or something.

    Imperator

    6812 Posts

Write post