Recent

Author Topic: Unable to display Animated Sprite in a virtual screen  (Read 2755 times)

JasonLugg

  • Jr. Member
  • **
  • Posts: 67
Unable to display Animated Sprite in a virtual screen
« on: October 19, 2018, 11:38:32 am »
Hi all and thx in advance.

I am able to load, create and display a IBGLTexture and set the frame size and manually animate it.

However, I would now like to create a sprite (as this is managed in a sprite engine rather than me managing them) but I am unable to get them to work:

Code: Pascal  [Select][+][-]
  1.     TmpText1:= BGLTexture('F:\Google Drive\CODE\MeoGeo2017\media\Ball1[016x032x032].png');
  2.     TmpText1.SetFrameSize(32,32);
  3.     TmpText1.SetFrame(1);
  4.           bSpr:= TBGLSprite.Create(TmpText1,0);
  5.           bSpr.Location:=PointF(100.0,100.0);
  6.     //bSpr.Texture.SetFrameSize(32,32);
  7.     //bSpr.Texture.SetFrame(1);
  8.     bSpr.FrameLoopStart:=1;
  9.     bSpr.FrameLoopEnd:=16;
  10.  

If I remove the SetFrameSize and SetFrame (1), I can display the full texture (series of frames). However, as soon as I add these lines, nothing is displayed?

in the ReDraw I have this:

Code: Pascal  [Select][+][-]
  1.   BGLVS.Sprites.OnTimer;
  2.   BGLVS.Sprites.OnDraw;    
  3.  

Am I doing something wrong?

JasonLugg

  • Jr. Member
  • **
  • Posts: 67
Re: Unable to display Animated Sprite in a virtual screen
« Reply #1 on: October 19, 2018, 11:41:34 am »
Do I have to manage the animation frames myself?

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Unable to display Animated Sprite in a virtual screen
« Reply #2 on: October 19, 2018, 05:50:42 pm »
Hello Jason,

The TBGLSprite already handles the frame via its property Frame. You just need to call once
Code: [Select]
TmpText1.SetFrameSize(32,32);to setup the frame size.

Then bSpr.Sprite := 1 to display the first sprite.

Does it fix the problem?

Note :
- in the redraw, you're supposed to call the OnDraw method. The OnTimer is suppoed to be called for example in an OnTimer event of a TTimer.
- you need to increment the Frame property in the OnTimer method of the sprite to animate it. The frame loops properties are there to wrap automatically when the Frame index gets out of bounds.


Regards
« Last Edit: October 19, 2018, 05:57:43 pm by circular »
Conscience is the debugger of the mind

JasonLugg

  • Jr. Member
  • **
  • Posts: 67
[FIXED] Re: Unable to display Animated Sprite in a virtual screen
« Reply #3 on: November 05, 2018, 06:02:56 pm »
FIXED  :D

circular

  • Hero Member
  • *****
  • Posts: 4196
    • Personal webpage
Re: Unable to display Animated Sprite in a virtual screen
« Reply #4 on: November 05, 2018, 09:07:11 pm »
Cool  :)
Conscience is the debugger of the mind

 

TinyPortal © 2005-2018