What's a good way to dynamically set text/9patch for popups?

0 favourites
  • 4 posts
From the Asset Store
A whole set you need to create a gorgeous winter 2d game
  • I have a spritefont and 9patch object that I want to use for mouse-hover popups everywhere in the game. Since I will have many different pieces of text (some small, some long) I want to be able to resize the 9patch on-the-fly.

    spritefonts have a size, and wrap by word/char base on the width. I have a maxwidth and height for game resolution.

    I'm not sure about how to resize the spritefont based on string length. I assume I need to know the longest char width with is a "W"..but that might not be right, since I do use a couple of spacing data values.

    anyone know what I'm doing wrong?


  • You need to use Spritefont.TextWidth and Spritefont.TextHeight expressions. Set text to the spritefont, then resize the 9patch using those expressions.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • dop2000 I originally played around with those but didn't have much success. I think the main issue is I have to resize the spritefont object to accommodate the text first.. I think that is the first part that needs to happen.

  • okay, I think I have it... so I think I need to set (in the editor) the max size of the text object, left-top justify it and never change that in code.

    Then like you said, set the size of the p9 from the textWidth/Height

    The issue was I was trying to dynamically change the size of the text object.

    *also you need to pad the p9 so that it is a little bigger than the text W/H

    Thanks dop2000!

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)