Recent

Author Topic: TTimer frame rendering  (Read 3212 times)

osman.schltz

  • New Member
  • *
  • Posts: 45
TTimer frame rendering
« on: September 23, 2017, 02:42:14 pm »
Hi everyone, I started making my own game engine which is makes objects and animations with pictures. I used TTimer to load pictures frame by frame. I set interval to 1 for fast loading animation. But it loads slowly :( Like I set the interval to 1000. Any help? Thanks in advance!  :)
« Last Edit: September 23, 2017, 06:04:08 pm by osman.schltz »
Windows 8.1
Linux Ubuntu 14.04 LTS

Thaddy

  • Hero Member
  • *****
  • Posts: 14201
  • Probably until I exterminate Putin.
Re: TTimer frame rendering
« Reply #1 on: September 23, 2017, 02:49:04 pm »
Loading frame by frame is not a good idea. Buffer them...
Specialize a type, not a var.

osman.schltz

  • New Member
  • *
  • Posts: 45
Re: TTimer frame rendering
« Reply #2 on: September 23, 2017, 02:54:08 pm »
Loading frame by frame is not a good idea. Buffer them...
Hi, Thaddy! Thanks! How can I do this?
Windows 8.1
Linux Ubuntu 14.04 LTS

osman.schltz

  • New Member
  • *
  • Posts: 45
Re: TTimer frame rendering
« Reply #3 on: September 23, 2017, 05:27:30 pm »
Please help :(
Windows 8.1
Linux Ubuntu 14.04 LTS

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: TTimer frame rendering
« Reply #4 on: September 23, 2017, 05:43:51 pm »
Store your pictures into memory first, before you are activating/running the timer.

For example you can load pictures into a bitmap and when the tiemr fires, then draw them to your display-surface.

There are simply too many variables that depend on your current implementation.

Have you looked at the projects that where posted in the graphics contest thread ? There might be some techniques in there that could give you some more insight on the subject of graphics animation.
« Last Edit: September 23, 2017, 05:45:25 pm by molly »

osman.schltz

  • New Member
  • *
  • Posts: 45
Re: TTimer frame rendering
« Reply #5 on: September 23, 2017, 06:03:56 pm »
Store your pictures into memory first, before you are activating/running the timer.

For example you can load pictures into a bitmap and when the tiemr fires, then draw them to your display-surface.

There are simply too many variables that depend on your current implementation.

Have you looked at the projects that where posted in the graphics contest thread ? There might be some techniques in there that could give you some more insight on the subject of graphics animation.
Thank you molly for your answer! I will try it  :)
Windows 8.1
Linux Ubuntu 14.04 LTS

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: TTimer frame rendering
« Reply #6 on: September 23, 2017, 06:06:35 pm »
Animation normally means just 1 picture file, or if it's larger animation, then .avi or other video format. Calculate coordinates based on how big the inside pattern is, and with TCanvas use CopyRect to draw that part. So if pattern was 50x50 and picture 200x200, it means there are 4 animation frames on each row that are 50 pixels apart.

Some example: http://games.ucla.edu/resource/wp-content/uploads/2011/02/sprite0_strip8.png

eric

  • Sr. Member
  • ****
  • Posts: 267
Re: TTimer frame rendering
« Reply #7 on: September 23, 2017, 07:38:06 pm »
also remember that TTimer is not at all accurate for small times, and any time setting below about 30ms will still take about 30ms.

Fungus

  • Sr. Member
  • ****
  • Posts: 353
Re: TTimer frame rendering
« Reply #8 on: September 23, 2017, 08:27:06 pm »
Have you considered using OpenGL or something like that?

Depending on the type of game engine, you could use buffer swapping where you have 2 "buffers" which are bitmaps with equal size to the window being drawn. You then use a background thread to draw a frame into buffer 1 and when done you flag buffer 1 as clean (meaning it is ready to be drawn to the screen) and buffer 2 as dirty (meaning it is not ready to be drawn to screen). While buffer 1 is being drawed to screen by your main thread, your background thread starts to build the next frame in the dirty buffer 2 and when done, buffer 2 is marked as clean and buffer 1 as dirty and so on. Whenever a buffer changes from dirty to clean, your background thread sends a message to the main thread which then draws the buffer to screen. This may seem cumbersome, but it is fast and it will prevent flickering.

molly

  • Hero Member
  • *****
  • Posts: 2330
Re: TTimer frame rendering
« Reply #9 on: September 23, 2017, 08:57:45 pm »
also remember that TTimer is not at all accurate for small times, and any time setting below about 30ms will still take about 30ms.

TFPTimer seems to do a better job then:

Code: [Select]
interval  iterations  millisecs
30        167         5016
15        334         5014
5         1002        5014
1         5015        5016

 

TinyPortal © 2005-2018