Greetings,
I lost myself finding a way to optimize this "TextBubble" function.
It is written for a game im working on where people can chat and have a bubble popup.
As the title says, its a fully functional script, except its kinda slow if you have to render about 100 of these.
I have NO idea what todo.
For the source + bubblemapfont download: http://www.fantasaar.com/bubble.zip
fyi, here is a direct copy of the code:
I lost myself finding a way to optimize this "TextBubble" function.
It is written for a game im working on where people can chat and have a bubble popup.
As the title says, its a fully functional script, except its kinda slow if you have to render about 100 of these.
I have NO idea what todo.
For the source + bubblemapfont download: http://www.fantasaar.com/bubble.zip
fyi, here is a direct copy of the code:
SetGraphicsDriver GLMax2DDriver() Graphics 640,480,,,GRAPHICS_BACKBUFFER Global BubbleMap$="!~q#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊËÌÍÎÏÐÑÒÓÔÕÖרÙÚÛÜÝÞßàáâãäåæçèéêëìíîïðñòóôõö÷øùúûüýþÿ" Global BubbleCharW=7,BubbleCharH=10 Global BubbleLimitW=48 Global BubbleFont=LoadAnimImage("bubble.png",BubbleCharW,BubbleCharH,0,256) While Not KeyDown(KEY_ESCAPE) DrawBubble("Hey! My name is LeeMing :D. ThislineisbrokenupThislineisbrokenupThislineisbrokenupThislineisbrokenupThislineisbroken\n\nupThislineisbrokenup Some random text goes here: Welcome to the official Fantasaar gameserver!",320,240) Flip Wend End Function DrawBubble(text$,x,y) 'Local destPixmap:TPixmap = CreatePixmap(((BubbleLimitW+1)*BubbleCharW),240,PF_RGBA8888) 'destPixmap.Paste(BubbleFont.Lock(224,0,0), 32, 32) Local line$ Local l=0 Local newline 'Render top For p=1 To BubbleLimitW+2 If p=1 DrawImage(BubbleFont,((p-1)*BubbleCharW),(l*BubbleCharH),224) Else If p=BubbleLimitW+2 DrawImage(BubbleFont,((p-1)*BubbleCharW),(l*BubbleCharH),226) Else DrawImage(BubbleFont,((p-1)*BubbleCharW),(l*BubbleCharH),225) End If Next l:+1 While Len(text)>0 newline=False p=0 'Line start DrawImage(BubbleFont,(p*BubbleCharW),(l*BubbleCharH),227) For p=1 To BubbleLimitW 'on: newline? If Mid(text,p,2)="\n" line=Left(line,p) text=Right(text,Len(text)-(Len(line)+2)) p=0 newline=True Exit Else 'on: text If p < Len(text)+1 line=line+Mid(text,p,1) 'Finished? Else Exit End If End If Next 'Always except when new line If newline=False p=line.FindLast(" ") If p>-1 line=Left(line,p) p=0 End If text=Right(text,Len(text)-(Len(line)+1+p)) End If 'Render textline For p=1 To Len(line) DrawImage(BubbleFont,(p*BubbleCharW),(l*BubbleCharH),228) DrawImage(BubbleFont,(p*BubbleCharW),(l*BubbleCharH),Instr(BubbleMap,Mid(line,p,1))) Next 'Finish tender textline (spacing) For i=p To BubbleLimitW DrawImage(BubbleFont,(i*BubbleCharW),(l*BubbleCharH),228) Next 'Line stop DrawImage(BubbleFont,(i*BubbleCharW),(l*BubbleCharH),229) l:+1 line="" Wend 'Render bottom For p=1 To BubbleLimitW+2 If p=1 DrawImage(BubbleFont,((p-1)*BubbleCharW),(l*BubbleCharH),230) Else If p=BubbleLimitW+2 DrawImage(BubbleFont,((p-1)*BubbleCharW),(l*BubbleCharH),232) Else DrawImage(BubbleFont,((p-1)*BubbleCharW),(l*BubbleCharH),231) End If Next 'Talk arrow DrawImage(BubbleFont,((BubbleLimitW+1)*BubbleCharW)/2,((l+1)*BubbleCharH)-4,236) End Function