Author Topic: Only rendering N characters in a Label?  (Read 6838 times)

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Only rendering N characters in a Label?
« on: April 15, 2014, 09:04:57 PM »
Hi,

Is there a way to tell a UILabel to only render a certain number of characters? I'm wanting to set up a typewriter effect for cut-scene text which is right justified, and slowly growing the text parameter just doesn't cut it.

Even with left justified text it would be ideal to just be able to just render N characters so you don't get weird pops when a word wraps.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #1 on: April 16, 2014, 10:32:45 AM »
Weird pops? Not sure what you mean. TypeWriterEffect script wraps everything beforehand.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #2 on: April 16, 2014, 05:36:13 PM »
I'm referring to when you keep adding characters to a UILabel and the last word wraps when it goes past the right hand border of the label.

The problem with the TypeWriterEffect script when it comes to right justified text is that the text grows out from the right hand side rather than having each character revealed in-place, which would be preferable in my case.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #3 on: April 17, 2014, 11:02:54 AM »
The typewriter effect pre-wraps everything before typing, so no, it doesn't behave like you're describing. In NGUI 2 it used to. In NGUI 3 it doesn't. What version are you using?

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #4 on: April 17, 2014, 05:09:33 PM »
I just grabbed the one from the examples folder after reimporting NGUI 3.5.7.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #5 on: April 18, 2014, 04:05:19 PM »
Then I don't understand what you mean. The current typewriter effect wraps everything first, and only then continues to print text. Make sure the label isn't set to "shrink to fit" btw.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #6 on: April 18, 2014, 07:00:37 PM »
So if you create a right aligned label and add the typewriter effect, do the characters scroll in from the right side of the label toward the left side of the label, or do the characters appear "in place" rather than scrolling in?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #7 on: April 19, 2014, 05:42:28 PM »
They get added to the right side, extending the already printed text toward the left.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #8 on: April 20, 2014, 03:41:23 PM »
Ok, so that is what I'm experiencing also. What I want though is for the text of a right justified label to start appearing from the left, which is why I asked in the first place whether it was possible to get a label to draw N characters so I could manually increment the number of characters it draws to make the text appear.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #9 on: April 20, 2014, 05:18:39 PM »
That's custom behaviour. You will need to write a custom script for that.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #10 on: April 20, 2014, 06:22:51 PM »
So I initially ask "Is there a way to tell a UILabel to only render a certain number of characters?", which I think is a pretty straight forward question, and it takes 6 days to get to the point where you're telling me that I need to write a custom script for it.

Lesson learnt... I should have just looked into it myself instead of wasting time asking a question.

Any way, thanks for replying at least.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #11 on: April 29, 2014, 09:03:41 PM »
Hi,

Even if I try restricting the drawing of characters in UILabel.OnFill, it doesn't help... the characters still grow out from the right side of the label.

Can you please give me an example of how you would do a right justified typewriter effect which starts drawing characters from the left side and grows toward the right?

ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #12 on: April 30, 2014, 04:13:26 AM »
I think it would help immensely if you posted some code so we can at least see what your problem is. Or a picture at the very least.

Wumpee

  • Jr. Member
  • **
  • Thank You
  • -Given: 3
  • -Receive: 0
  • Posts: 53
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #13 on: April 30, 2014, 04:32:24 AM »
I think it would help immensely if you posted some code so we can at least see what your problem is. Or a picture at the very least.

Based on ArenMook's last reply, I think he understands the issue.

There is no code to post in relation to this issue... it's related to the TypewriterEffect example that comes with NGUI and the fact that it doesn't handle right justified text the way I would expect - our designer also commented that he thinks the text would look better if it came in the same way that left justified text does.

To be more clear - Left justified labels with a TypewriterEffect script attached start drawing characters from the left, and move across the screen to the right one character at a time. Right justified labels grow from the right side of the label toward the left side of the label.

e.g.
|         ABCD| will draw / reveal as follows, one character at a time:

|            A|
|           AB|
|          ABC|
|         ABCD|


It would be ideal if it revealed the label like so instead (i.e. revealing the characters "in place", instead of growing them in from the right side of the label)

|         A   |
|         AB  |
|         ABC |
|         ABCD|


ENAY

  • Full Member
  • ***
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 248
    • View Profile
Re: Only rendering N characters in a Label?
« Reply #14 on: April 30, 2014, 04:43:32 AM »
I think I see what you are saying now, you want the text to pop out as it does now, as if it were left assigned, except you want the full length of the word to be right aligned when it has finished?
Well what I would do is keep the UILabel left aligned, but adjust its transform in the X direction to the right side. First position the UILabel at the right side of where you want it and then use the UILabels 'printedSize' and subtract that from that position. In other words, you make a script which moves the UILabel according to the words text size.

I am still not 100% sure if that is what you are trying to achieve, but I hope this helps.