Is Kivy suitable for creating 2D games? (about: loading and blitting bitmaps)

2,756 views
Skip to first unread message

Santiago Romero

unread,
Mar 14, 2013, 1:46:47 PM3/14/13
to kivy-...@googlegroups.com

[ Sorry if this question is very basic / already covered in the docs ... ]

After a quick reading of the basic tutorial, I haven't seen the way of loading png images from a spritesheet and BLIT THEM to a given position in the screen, like it can be done in pygame. I know Kivy uses OpenGL... like other frameworks that allow blitting sprites as "textured cubes"...

I wanted to create a simple first test of loading a bitmap from a PNG file and move it around the screen either using keyboard or "touchs"... (I'd add frame animation later).

Is that possible with Kivy? Could anybody provide a simple working example on how to move an image in an empty canvas?

Thanks.

Ben Rousch

unread,
Mar 14, 2013, 1:53:16 PM3/14/13
to kivy-...@googlegroups.com
The Kivy Pictures Demo might be what you're looking for
https://github.com/kivy/kivy/tree/master/examples/demo/pictures
> --
> You received this message because you are subscribed to the Google Groups
> "Kivy users support" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to kivy-users+...@googlegroups.com.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>



--
Ben Rousch
bro...@gmail.com
http://clusterbleep.net/

Akshay Arora

unread,
Mar 14, 2013, 2:40:20 PM3/14/13
to kivy-...@googlegroups.com
search for

1) Atlas <-your sprite sheet equivalent
2) look at tyhe kivy contest entries and winners
3) tex-coords example by tshirtman
4) I don't know if this is relevant or can be used but by default the Image widget supports gif's and images in a .zip. Just point it to a animated gif and .zip and the rest is taken care of internally.

Best Regards

MintyAnt

unread,
Mar 14, 2013, 9:43:51 PM3/14/13
to kivy-...@googlegroups.com
I puked up a down and dirty "game" during an hour jam with Kivy.

"Zombie" blocks moved from the left side of the screen to the right, spawning in random places every second.

You could click the mouse and build a wall to keep them from reaching the right side. But each time one hit the wall, the wall would go away.

Worked out pretty nicley, I just couldnt figure out how to "delete" a widget in time. I never did actually...

The only kivy tutorial, the Pong one, basically proves that games work just fine via kivy.

Good luck!

B. Jack

unread,
Mar 14, 2013, 10:41:06 PM3/14/13
to Kivy Users

On Thursday, March 14, 2013 1:46:47 PM UTC-4, Santiago Romero wrote:

[ Sorry if this question is very basic / already covered in the docs ... ]

After a quick reading of the basic tutorial, I haven't seen the way of loading png images from a spritesheet and BLIT THEM to a given position in the screen, like it can be done in pygame. I know Kivy uses OpenGL... like other frameworks that allow blitting sprites as "textured cubes"...

I wanted to create a simple first test of loading a bitmap from a PNG file and move it around the screen either using keyboard or "touchs"... (I'd add frame animation later).

Is that possible with Kivy? Could anybody provide a simple working example on how to move an image in an empty canvas?

Thanks.


Hmm.  Actually Kivy's internal Atlas already does much of what you describe in a spritesheet.
The Atlas is just a larger bitmap kept in graphics memory VRAM which is stored into from any
images you load (including Kivy's own images for the GUI theme) which is any image format
Kivy/PyGame can read (PNG, JPG, etc).  They are blitted to the screen in VRAM.  Kivy is 2D so
it doesn't use cubes but it does generate 2D textured rectangles in OpenGLES (which just have
their Z's all flattened to 0 by design).

Your example of moving around an Image in response to touch events would acutually be a
fairly trivial use case in Kivy.

I'm not sure if the Atlas functionality can be used explicity to manage additional VRAM (or system
RAM perhaps) Atlases as an implementation of spritesheets.

skeezix

unread,
Mar 15, 2013, 4:49:04 PM3/15/13
to Kivy Users
On Thu, 14 Mar 2013, B. Jack wrote:

# After a quick reading of the basic tutorial, I haven't seen the way of loading png images from a spritesheet and BLIT THEM to a given position in the screen,
# like it can be done in pygame. I know Kivy uses OpenGL... like other frameworks that allow blitting sprites as "textured cubes"...

You can specify the source coordinates within a texture and thus
use one image to create many different blittable blocks.

Sorry, I'm super busy right now, but I did it without too much
difficulty awhile back. In essence, you can create Textures that are
virtual rectangles against another Texture or Image or whatever. I used a
Canvas and Rectangles to do the drawing, with each Rectangle having a
texture in it. (So not using 1000 widgets flying around, but instead using
a Canvas and dropping a thousand Rectangles onto it, and then for each
scene graph change,m just move one of the rectangles around by changing
its coordinates and canvas.ask_updating(), something like that..)

jeff

--
If everyone would put barbecue sauce on their food, there would be no war.

Santiago Romero

unread,
Mar 17, 2013, 2:32:48 PM3/17/13
to kivy-...@googlegroups.com

Thanks for all the answers given.

I'll check it all and see if I can make it work :)

Reply all
Reply to author
Forward
0 new messages