Kivy and performance

1,189 views
Skip to first unread message

and...@zoho.com

unread,
Sep 19, 2013, 3:13:47 AM9/19/13
to kivy-...@googlegroups.com
hello,
i want to create an android game with pygame and python and use some of the buttons and some interfaces from kivy.

now i wonder if it would be a big tradeof in terms of apk size and size in general and if it would cost performance if i go this way.

Akshay Arora

unread,
Sep 19, 2013, 3:38:20 AM9/19/13
to kivy-...@googlegroups.com
You would have to try and find out, the performance critical parts of kivy are written in cython so technically it shouldn't be a issue.



--
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.

ZenCODE

unread,
Sep 19, 2013, 4:00:56 AM9/19/13
to kivy-...@googlegroups.com
Might put your mind at ease if you read through this.


Cheers

Ian Foote

unread,
Sep 19, 2013, 7:05:42 AM9/19/13
to kivy-...@googlegroups.com
You can also use pyjnius
(http://pyjnius.readthedocs.org/en/latest/index.html) to call native
java libraries, which can be useful for performance critical code. Kivy
has usually been sufficient for my needs without this though.

Regards,
Ian F

Gabriel Pettier

unread,
Sep 19, 2013, 7:06:09 AM9/19/13
to kivy-...@googlegroups.com
I think performances is not much of an issue, but why do the game part
in pygame and not with kivy itself as well? I feel most of your hurdle
would be to combine the very different logic of both framework playing
together (would probably need to blit to a texture displayed by kivy).
Kivy has powerful drawing mechanism, and I'm not seeing what you would
gain by using pygame instead.

and...@zoho.com

unread,
Sep 20, 2013, 3:24:26 AM9/20/13
to kivy-...@googlegroups.com
Yet i understand pygame a bit but i have no idea how to do the same with kivy the only knowledge i could extract from the snippets was how to create buttons.

Is there a snippet where a list of images is drawn to the screen or a background is drawn pygame is there quite direct in its commands.

Alexander Taylor

unread,
Sep 20, 2013, 8:01:44 AM9/20/13
to kivy-...@googlegroups.com
Kivy tends to work on a slightly different level to pygame - in pygame you're looking more directly at the lower level operations of how graphics stuff is blitted, moved around etc., whereas kivy's widget operations are (I'd say) a higher level interface.

If you haven't already, I suggest looking at kivy's pong tutorial (http://kivy.org/docs/tutorials/pong.html), which is a good introduction to making a simple game with kivy, including how you think about things differently to pygame.

For your particular question, you could draw an image with an Image widget (http://kivy.org/docs/api-kivy.uix.image.html), and could arrange/position such images (along with other widgets) with the different kinds of Layout (http://kivy.org/docs/api-kivy.uix.layout.html). The exact choice would depend on what you want to do, but there is documentation on all the different layouts and the results you can get from them. For instance, a very simple example of just creating a fullscreen image would be:

    from kivy.app import App
    from kivy.uix.floatlayout import FloatLayout
    from kivy.uix.image import Image

    class ExampleApp(App):
        def build(self):
        
            fl = FloatLayout()
            im = Image(source='some_image.png',
                    allow_stretch=True,
                    keep_ratio=False,
                    mipmap=True,
                    size_hint=(1,1),
                    )
            fl.add_widget(im)
            return fl
    
    if __name__ == "__main__":
            ExampleApp().run()

You could then add more widgets to fl, and they would be drawn on top.

Sam Brotherton

unread,
Sep 20, 2013, 1:43:44 PM9/20/13
to kivy-...@googlegroups.com
If you're trying to build a game, you'll probably want to use Kivy's lower level resources rather than Image and Widget. Kivy actually has a really nice graphics library that's essentially a thin layer over openGL. It's super fast but you still get the awesomeness of Kivy's event-based model.

Here's an example of some graphics code I wrote as part of a plotting library: https://github.com/sbrother/bruin-event-analysis/blob/master/kivy_plotter/plot.py#L173. In this case, self.series is an instruction group, which lets you add arbitrary graphics primitives to a group, and then add and remove that group at will. It's a super powerful construct that makes it easy to write pretty and totally resolution independent UIs. My code is a little bit messy, but it should help you out if you're interested in Kivy graphics.

Sam
Reply all
Reply to author
Forward
0 new messages