Jump to content
Czar

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×