Pin a sprite to the center of a text object

0 favourites
  • 4 posts
From the Asset Store
Wall Pin Board is a hyper causal game developed for fun and inspired by YouTube video whose link is given in description
  • Seriously. I've tried everything. In my opinion, as an example, both of these methods should work.

    "TextWidth

    TextHeight

    Return the size of the actual text content within the text object's rectangle."

    returns something ludicrous

    "len(x) - return length of the string x"

    returns 0

    this guy

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I've used variables, trim, len(text.text) 0.5*(text.width), textbox.textwidth...

  • Text objects have their origin set to top left by default, but you can set the hotspot to center in it's properties. That way you'd just have to set the sprite at text.x, text.y

    But without changing the origin you should be able to set the object to x: text.x+(text.width/2) y: text.y+(text.height/2) this will put the sprite in the middle of the textobject. if you center the text it will also be in the center of the text.

  • Thanks, that's a good idea. I'll change it in properties, but as I posted in the .capx example, 0.5*text.width does not work. If you could post an example with it working, I'd be very impressed.

    EDIT:

    Here's the problem though - if I want to dynamically change that text, and I set the object to pin to the center of the text, it will pin to the center of the text & the whitespace, regardless of whether I use the "trim" function.

    Example - the center of this string:

    "string1                                       "

                            is here

    Now, let's say I want to change the WIDTH of the text like this

    Set Width(Text.TextWidth) will delete entire strings. Sometimes, it will take a phrase like "I went shopping" and return "I   "

    As far as I can tell, the trim function does not do anything, and the set Width = Text.TextWidth deletes part of my string.

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