Hey Folks,
Basically I have a problem rotating bitmap fonts, made out of individual sprites/slices, around a given pivot point. Right now when I rotate every letter rotates on it's own accord, as instead rotating the word around it's center.
Method Draw(text:String, x:Double, y:Double, Center:Byte = False, RightJustify:Byte = False, RoundX% = False, RoundY% = False, CentreVertically% = 0)
'By default the text is draw Left-Justified, but you can alter that with the Center and RightJustify params.
'Sometimes drawing characters at sub-pixel positions makes them look blurry, so
'if you want them to look crisp use the RoundX and RoundY params. However if you
'plan to move the text around on-screen smoothly, then you should not use those param.
'Ingore null strings.
If text="" Then Return
Local char:Int
Local scale_x:Float
Local scale_y:Float
HandleX=0
'Store the current scale.
GetScale(scale_x,scale_y)
'Justify.
If Center Then
Local halfwidth:Double = (StringWidth(text) / 2)
If ChangeHandle Then
HandleX:+halfwidth
Else
x:-halfwidth*scale_x
EndIf
EndIf
If RightJustify Then
If ChangeHandle Then
HandleX:+StringWidth(text)*scale_x
Else
x:-StringWidth(text)*scale_x
EndIf
EndIf
'Centre Vertically?
If CentreVertically Then
Local halfheight:Double = (StringHeight(TestString) / 2)
If ChangeHandle Then
HandleY:+halfheight
Else
y:-halfheight * scale_y
EndIf
EndIf
'Scale the font by the ScaleFactor.
scale_x :* ScaleFactor
scale_y :* ScaleFactor
'Loop and output each character.
Local a:Byte
For a = 0 To Len(text) -1
Local letter$ = Mid(text,a+1,1)
char = Asc(letter)
If char >= MAX_BITMAPFONT_STANDARD_CHARS Then char=FindChar(letter)
If char >= 0 Then
Local xpos:Double = xPos[char]
Local ypos:Double = yPos[char]
Local width:Double = width[char]
Local height:Double = height[char]
'Take into account any character offset.
Local x1:Double = x
Local y1:Double = y
If Not ChangeHandle Then
x1 :+ xOffset[char] * scale_x
y1 :+ yOffset[char] * scale_y
EndIf
Local w:Double = width * scalefactor
Local h:Double = height * scalefactor
'Local w:Double = width * TextureW * scalefactor 'For pre BMax 1.36
'Local h:Double = height * TextureH * scalefactor 'For pre BMax 1.36
'Shall we round the coords for a nice crisp image?
'Only round if the text is not scaled, otherwise the letters can sometimes draw at different Y coords and it looks bad.
If RoundX And scale_x=1 Then
x1 = ccRound(x1)
w = ccRound(w)
EndIf
If RoundY And scale_y=1 Then
y1 = ccRound(y1)
h = ccRound(h)
EndIf
'Prepare to move onto next character.
Local increment: Double = (xAdvance[char] + CharGap)
'Deal with the Handle.
If ChangeHandle Then
DrawSubImageRect(Image, x1-(HandleX-xOffset[char]*scalefactor), y1-(HandleY-yOffset[char]*scalefactor), w, h, xpos, ypos, width, height)
x1:+20*a
DrawSubImageRect(Image, x1, y1, w, h, xpos, ypos, width, height)
'Change the handle not the x coord.
HandleX :- increment*scalefactor
Else
'Draw normally.
DrawSubImageRect(Image, x1, y1, w, h, xpos, ypos, width, height)
'DrawImageRect(Image,x1,y1,w,h) 'For pre BMax 1.36
x :+ increment*scale_x
EndIf
EndIf
Next
End Method
I sadly can't post the full code as it's part of GreyAlien's Framework, which I paid for and I'm sure it would upset him.
Also I probably suck at trigonometry because I had several shots at it but failed to achieve the wanted effect.
Thanks!
|