Hello Guest

Author Topic: Using 2d tool kit to build a speechbubble...  (Read 15849 times)

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Using 2d tool kit to build a speechbubble...
« on: April 16, 2015, 06:23:10 pm »
I am not sure but it seems like this is something it could do with how the fonts can be text meshes.   Wouldn't know where to start though.  I would love a speech bubble that looks like this (attached) it was created at this link here:

(its sort of an 8bit retro lo res speech bubble with a font to ultimately match)
The size of the bubble would be dynamic to match the text in it...

Here is how i created the bubble...

http://wigflip.com/ds/


I guess worst case scenario I would create one for all my text and just put it up as a sprite. *shrug*



unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #1 on: April 17, 2015, 09:16:32 am »
You can create the speech bubble using a sliced sprite, which you'd be able to resize correctly to match the bounds of the text. You'll need a script to get the EstimatedMeshBounds of the text and feed that to your sliced sprite.

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #2 on: April 17, 2015, 03:19:55 pm »
Excellent I will research sliced sprite and EstimatedMeshBounds thank you!

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #3 on: April 17, 2015, 03:53:12 pm »
okay does the source image matter?  I think mine is not correct as when it scales it goes very muddy.  The source image is attached here (I am thinking its the drop shadow causing the sliced sprite to not handle correctly)

i was scaling it both by scale and pixels to units.


codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #4 on: April 17, 2015, 04:11:03 pm »
Also to save time here is the code so far.  I have the sliced sprite, with the SpeechBubble script on it and a text mesh under it. (will get the exact font I want later) but for now ...it sort of works aside from the ugly borders mentioned earlier... and the text not being in the center (more it is centered on the left border of the speech bubble).  Image attached as well.


Code: [Select]
// Use this for initialization
tk2dTextMesh msh;
TextMesh y;
tk2dSlicedSprite spr;
void Start () {

msh = transform.Find ("TextMesh").GetComponent<tk2dTextMesh>();
if(!msh)
Debug.LogError ("Coulnd't get it!");
Bounds b = msh.GetEstimatedMeshBoundsForString(msh.text);
spr=  GetComponent<tk2dSlicedSprite>();

spr.ReshapeBounds(b.min, b.max);


}

// Update is called once per frame
void Update () {

}
}



codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #5 on: April 23, 2015, 10:33:20 pm »
Just was curious if i was on the right path for this?

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #6 on: April 23, 2015, 11:25:39 pm »
Yes it looks like you are, just the pivots are in the wrong places.

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #7 on: April 23, 2015, 11:33:46 pm »
realized the source image and the resulting image was not attached, so I couldn't show how the muddied texture looked.  I wanted to have it it expand like a block oval not a true oval.  So found the pivot and set that on the sprite to top left and then set the sliced sprite anchor point to lower center.  Attached is that is close.  So really just the border and how its too oval not a nice rectangle with round corners.  The code above does try to calculate the right size but it grows the sliced sprite funny.




« Last Edit: April 23, 2015, 11:41:06 pm by codejoy »

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #8 on: April 23, 2015, 11:41:32 pm »
Image attached.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #9 on: April 28, 2015, 03:22:36 pm »
Is it pixelated because the scale is inorrect? You should be able to track this down by seeing what changes. If you can tell me what changes I should be able to work out why.

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #10 on: April 28, 2015, 05:48:37 pm »
Really dumb question:  The scale in which context?  And what changes how?  Like when the bubble gets bigger to hold the text, see how that changes? 

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #11 on: April 29, 2015, 12:16:59 am »
The scale & dimensions on the sliced sprite.

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #12 on: April 29, 2015, 06:24:17 am »
Ahh okay, I think I follow ya.  If I run the game then my code thats on the sliced sprite:


Code: [Select]
public class SpeechBubble : MonoBehaviour {

// Use this for initialization
tk2dTextMesh msh;
TextMesh y;
tk2dSlicedSprite spr;
void Start () {

msh = transform.Find ("TextMesh").GetComponent<tk2dTextMesh>();
if(!msh)
Debug.LogError ("Coulnd't get it!");
Bounds b = msh.GetEstimatedMeshBoundsForString(msh.text);
spr=  GetComponent<tk2dSlicedSprite>();

spr.ReshapeBounds(b.min, b.max);


}
}

Changes the dimensions from 32x32 (Which is what it is if you were to just open the file in paint for example) to 356x92 with a scale of 1.  (looks like it scales with a bilinear not a point filter mode).  Though the sprites filter mode if i just click the PNG from unity (so in the inspector) is set to point.



So thats what makes it look whacked, sounds like it is my source image but if that is the case I am not sure how to have a source image that "Grows" correctly?





unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #13 on: April 29, 2015, 10:25:44 am »
The point is it shouldn't be scaling it up like that - it should just expand it when resized. Try resizing the sliced sprite in the editor to 356x92 and see what it looks like.

codejoy

  • 2D Toolkit
  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Using 2d tool kit to build a speechbubble...
« Reply #14 on: April 30, 2015, 06:14:17 am »
okay did that looked the same in the editor. screenshot is attached.