Exposing Image.anim_index or is there a better soluiton?

16 views
Skip to first unread message

Rylan Grayston

unread,
Nov 20, 2017, 5:01:52 PM11/20/17
to Kivy users support
Iv written a video game, and its working great but I used the open CV window library.  Id like to move to using Kivy so that I can achieve higher frame rates, and more portability but Iv run into a problem.

The Kivy Image widget allows animation using gif and zipped images and this is pleasantly easy. However I need to be able to control the anim_index directly.

I have many situations that I use finer control in ( using openCV) some examples( with pseudo Kivy code that Id like to work)  are:

-starting the playback at the half way point. >>> Image.anim_index =  int( len(Image.textures) /2 )
-playing the frames in reverse upon a key press. >>> Image.anim_index -= 1
-jumping +- 4 frames to create a jitter effect on a character. >>> Image.anim_index = frameCount + random.randrange(0,4)
-stopping playback on a list of specific frames  >>> if image.anim_index == nextFrameMarkedAsStill: anim_delay = -1
-implementing frame droping such that a wider rage of play back speeds are possible >>> Image.anim_index += 3
-checking which frame is currently being displayed and looking up Meta data that I have saved for that specific frame. 
-lining up to animated textures perfectly the textures I choose end up on the screen at the same time. 

The way my game works now (using openCV) all image data is loaded in to ram and then every frame I use the CPU to blit many images together before sending the final image to the GPU / screen.
Its my understanding that when one has multiple Kivy Image widgets each with multipul textrues, those textures are all pre loaded into GPU memory, and warped on to a rectangle(each texture takes its turn) in the GPU.
The GPU rasters the various rectangles to come up with pixel values for the screen.
There for instead of bitting images together before sending them to the GPU, I can let the GPU put all the images together by organizing the rectangles and there textures.
And this will likely achieve higher frame rates than bitting an image together with the CPU.

Is my understanding of the way Kivy uses the GPU to do display a multi textured Image widget correct?

I would really like the anim_index to be exposed, and iv found one other person who wanted this as well here https://github.com/kivy/kivy/issues/2848
Perhaps ill make a new issue of this.
Others in that isue thread suggest that if you want fine grain control do the work yourself.
How dose one go about making there own array of textures held in GPU memory and then at 30 fps choose which textures to wrap on to rectangles on the GPU, using kivy.( and how do I delete them as well)

Perhaps the easiest thing would be to modify the Kivy source code to expose anim_index ?

Thanks in advance!




Reply all
Reply to author
Forward
0 new messages