Jump to content

combining a Game Canvas and Form?


Recommended Posts

I would like to have a canvas with all the benefits of a game canvas surrounded by HTML elements like, buttons, panels etc.

 

I making a strategy game which requires lots of buttons, information reports etc so using standard buttons, memo, panel etc would make much easier than remaking them for a canvas.

 

At the moment I am trying to use a paintbox as an option but it is less than ideal as it doesn't have the benefits afforded by TW3GameView etc. I miss things like the last frame time & frame rate.

 

Is it possible to combine a Game Canvas with a form? And if so how?

 

If paintbox is the best solution then what is the best way to ensure it is redrawn often? At the moment I use paintbox1.invalidate after it has finished drawing everything.

Link to post
Share on other sites
  • 2 months later...

There are many ways to do this. You could use a timer to update it, or create a recursive TW3Dispatch.requestAnimationFrame () loop.

You could also use more classical approaches, rendering to an off-screen bitmap and then attaching that to the background of any visual control. You can even do this "live" via the TW3BackgroundGraphicContext (SmartCL.Graphics.pas), which works great if you define a css-canvas as it's called.
You can fin more info on that here: https://stackoverflow.com/questions/3397334/use-canvas-as-a-css-background

The most friendly is obviously to use the Paintbox, which resolves to a <canvas> tag in the DOM, coupled with a requestAnimationFrame loop.

For demanding stuff, use a TThread background worker to deal with the graphics, and just ship the pre-rendered graphics back to the main application via postmessage() with a binary attachment.

You may also find the unit "SmartCL.Legacy.pas" interesting since that gives you TBitmap and TCanvas as close as we could to Delphi.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...