
Originally Posted by
SilverWarior
I often wondered how powerful TMS Webcore can be for game development.
Would you be willing to tel how you managed to make these? Like what components did you use? How do you manage the game loop etc?
Yes, of course.
With TMS Web Core, you program normally in Pascal. The ASM block is used to integrate JavaScript directly into the Pascal code.
I use the JavaScript method requestanimationframe(). requestAnimationFrame calls the animation function before each refresh of the browser window and creates smooth transitions from one frame to the next.
This is one of the few places where you have to lend a little help with JavaScript.
Code:
asm
requestAnimationFrame($mod.PascalProc);
end
A Pascal procedure is passed. This is again written in regular Pascal and renders the game.
The shooter still used a timer, which is why it stutters. Requestanimationframe(), as used in Santagame, is much better. By passing the call time, the usual time methods are used to avoid constant speed and stuttering.
TWebPaintbox and TWebHTMLDiv are essentially used here.
Code:
Procedure PascalProc(time:double);
var
starttime:TDatetime;
deltatime:integer;
begin
starttime:=now;
deltatime:=MilliSecondOf(starttime-frmmain.lasttime);
if frmMain.gamerunning then
begin
...
if not frmMain.gameover and not frmMain.gamefinished then
frmmain.updategame(deltatime);
frmmain.rendergame(deltatime);
...
end;
frmmain.lasttime:=starttime;
if not frmMain.exitlevel then
asm
requestAnimationFrame($mod.PascalProc);
end
else
asm
location.reload();;
end;
end;
Bookmarks