Pin a sprite to the center of a text object

Get help using Construct 2

Post » Fri Dec 20, 2013 8:37 pm

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 guyClocksTNW2013-12-20 20:39:56
B
9
S
2
G
2
Posts: 47
Reputation: 1,822

Post » Fri Dec 20, 2013 8:38 pm

I've used variables, trim, len(text.text) 0.5*(text.width), textbox.textwidth...
B
9
S
2
G
2
Posts: 47
Reputation: 1,822

Post » Fri Dec 20, 2013 8:46 pm

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.
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

Post » Sat Dec 21, 2013 12:08 am

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.ClocksTNW2013-12-21 01:03:55
B
9
S
2
G
2
Posts: 47
Reputation: 1,822


Return to How do I....?

Who is online

Users browsing this forum: No registered users and 35 guests