Hey all. Recently coded this up just to see if I could. Well I could, so here ya go:
Code:
procedure mw2Cycle(Canvas:TCanvas;s:string;PosX,PosY,TimePerChar:Integer;bgCol:TColor;Font:TFont);
var
i,j:integer;
om:integer;
output,r:string;
label
m;
begin
canvas.Font:=Font;
if s='' then s:='Lol why so blank?';
r:='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 !"£$%^&*()-_=+{[}]:;@''~#?/>.<,|\¬`¦ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜøØ׃áíóúñѪº¿®½¼¡«»ÁÂÀ©¢¥ãäðÐÌÓßÔÒõÕµþÞÞÚÛÙýݯ´±=¾¶§¸¨·¹³²°†‡•…‰™';
output:=' ';
om:=1;
m:
i:=1;
while (i<TimePerChar) Do
begin
Application.ProcessMessages;
Randomize;
j:=RandomRange(1,Length(r));
output[om]:=r[j];
With Canvas do begin
Brush.Color:=bgCol;
fillrect(cliprect);
Bru******yle:=bsClear;
TextOut(PosX,PosY,output);
end;
inc(i);
end;
output[om]:=s[om];
With Canvas do begin
Brush.Color:=bgCol;
fillrect(cliprect);
Bru******yle:=bsClear;
TextOut(PosX,PosY,output);
end;
if Length(s)<>Length(output) then
begin
output[om]:=s[om];
output:=output+' ';
Inc(om);
goto m;
end;
end;
Example call:
mw2Cycle(Image1.Canvas,'Modern Warfare 2',0,0,200,clBlack,f);
(Where "f" is a TFont which has already been created).
The above gives the effect seen in text when you, for example, complete a challenge in-game, with the cycling text.
Now, this is a "big" version which can be cut down easily (ie. You could just pass the Canvas and string, hardcoding the rest in the procedure).
Okay, explaining time (for anyone who wishes to convert this to another language for example).
Basic idea behind this:
- Have input / output / constant strings
- The final output = input
- In between, however, the output will contain random characters, selected from our constant string
- Once the time has run out for the first character (eg. 2 seconds), we set it to the correct value (from the input), and move on to the next one. Repeat until output=input
"r" is out Constant String variable, which is used for holding our random characters. It contains all the characters we could need (A-Z,a-z,0-9,"Regular" Symbols), and many, many other ASCII characters. These extra characters may never be used by someone using the procedure, however they look good as they shoot past
We start by giving output (a string variable) a value of a space. This gives us a base to work from as we'll be referencing the characters like output[i]. If output was left blank this would cause problems.
Next we do our loop for the first character. The loop is repeated until the time is complete (eg. 2 seconds). We select a random character from "r", and set output's first character to this. We then print this character. For the whole 2 seconds we do this over and over again. Once the time is up, we set the character to its correct value, and print it.
Next we check if length of output=length of input. If it is, we're done. Otherwise we add a space to output, and go back to the label m (think of a jne in asm). Just below m is our loop. The loop is done again, this time for the next character. This paragraph is repeated until length of output = length of input. Once it is, we're done.
So yeah, that's basically it. I've attached a demo .exe to show what this does when the procedure is called, allowing you to change the font/colours/speed. Don't dream of setting speed to like...90 or you'll be sitting there for days (Someone learned this the hard way )
Coders: Note that in this demo the speed (timePerChar) entered by the user is multiplied by 100 before use. Default is 2, so the procedure's "default" would be 200. The credits is called with a value of 100.
If you don't understand anything here or need help, feel free to ask. I don't bite...usually
I know this isn't exactly CoD development, but there isn't a Delphi section, and this would be more appreciated by people in the CoD programming section than those in "Other Programming" in my opinion, so I've posted it here for CoD people to see Sorry if I'm wrong.
Virus Scans for the Demo:
VirusTotal: 0/39 (0%)
VirScan.org: Scanners did not find malware!
Screenshot here.
Enjoy!
- 0rbit