Created
March 16, 2017 18:10
-
-
Save michaliskambi/f79eeaeec9e8768e6885a6bb3b15f6fd to your computer and use it in GitHub Desktop.
Play animation from an image sequence (like a GIF animation) using Castle Game Engine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uses SysUtils, | |
CastleControls, CastleWindow, CastleTimeUtils, CastleUIControls, | |
CastleGLImages, CastleVideos; | |
type | |
TMap = class(TUIControlSizeable) | |
private | |
Video: TGLVideo2D; | |
AnimationTime: TFloatTime; | |
public | |
procedure GLContextOpen; override; | |
procedure GLContextClose; override; | |
procedure Render; override; | |
procedure Update(const SecondsPassed: Single; | |
var HandleInput: boolean); override; | |
end; | |
procedure TMap.GLContextOpen; | |
begin | |
inherited; | |
Video := TGLVideo2D.Create('giphy4.gif', true); | |
{ Adjust FPS if you like. | |
Alternatively, you could scale the time passage by scaling added SecondsPassed | |
in the Update method. } | |
//Video.FramesPerSecond := 4; | |
Video.TimeLoop := true; | |
end; | |
procedure TMap.GLContextClose; | |
begin | |
FreeAndNil(Video); | |
inherited; | |
end; | |
procedure TMap.Render; | |
begin | |
inherited; | |
{ display 1st animation } | |
Video.GLImageFromTime(AnimationTime).Draw(10, 10); | |
{ display 2nd animation, alwats 1 second later, just because we can } | |
Video.GLImageFromTime(AnimationTime + 1).Draw(400, 10); | |
end; | |
procedure TMap.Update(const SecondsPassed: Single; | |
var HandleInput: boolean); | |
begin | |
inherited; | |
AnimationTime += SecondsPassed; | |
end; | |
var | |
Map: TMap; | |
Window: TCastleWindowCustom; | |
begin | |
LoadAnimatedGifs := true; | |
Window := TCastleWindowCustom.Create(Application); | |
Window.Controls.InsertFront(TCastleSimpleBackground.Create(Application)); | |
Map := TMap.Create(Application); | |
Map.FullSize := true; // capture mouse clicks from the entire window | |
Window.Controls.InsertFront(Map); | |
Window.OpenAndRun; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment