Thursday, December 5, 2013

kivy - alternative to Pygame

 

I looked at pyglet two years ago in October of 2011.    Since that time, I haven't gone back to it.  I've been focused on Pygame Subset for Android.  As far as I know, Pyglet doesn't work on Android phones.  I also like the Pygame documentation more than the Pyglet documentation.

Another library, kivy, does work on Android.  It should also work on iOS.  I haven't tried it myself on either Android or iOS.  My son and I have used it on Linux and it does work great on Linux.

My son was able to build a pong game from the tutorial in one session.  Kivy has a lot of potential and I want to go back to it.

The reason I'm still using Pygame for my lessons is that my son is still getting used to object oriented programming.  With Pygame, the program is can be made more easily with one long block of code.  He can then go back to change the program components into functions or classes.

With kivy, he has to immediately start using classes.

Here's the basic "Hello, World" in Kivy.




While this is actually shorter than a Hello World program in pygame, it does require class instantiation, which is a bit difficult to understand for a young teenager.

The kivy documentation is also considerably weaker than the pygame documentation.  Since kivy is a younger project, I've also experienced more problems with getting the libraries to work all the time on my Linux system.  For example, when I updated Ubuntu 12.04 to the beta NVIDIA Driver, 325, kivy stopped working.  However, pygame was still working.  This may be due to an error with the NVIDIA driver GL implementation and have nothing to do with Kivy.  However, it does show that with less people using Kivy, more things can go wrong.

The advantages I can see for kivy are:

  • multi-touch support.  This is huge.  Pygame only supports a single point.  Although there are some hacks to use the joystick module to detect multiple inputs, it's not that clean a solution.  Getting multi-touch support is a major draw.
  • iPhone, iPad support.  It doesn't look easy to do and I've never done it.  There are some apps on the Apple Store.  So, it's possible to get it to work.  I'm sure it will get easier as the platform matures.
  • GPU acceleration.  The fancy OpenGL ES 2 support makes it easier to do cool 3D effects
  • Android and iPhone support is provided by the core maintainers.  For Pygame, we need to rely on the separate pygame subset for android project (which probably won't support multi-touch since the key developer wants to keep the feature set similar to what is on the base pygame library.)
  • The development community around adding features to the platform seems to be more active than the pygame development community.
The downsides for the purpose of teaching:
  • Pygame documentation is better
  • More people use Pygame and there are more examples of Pygame code
  • The larger pygame community means that most problems have already been solved by other people.  Much more answers on stackoverflow
  • Kivy uses the KV Design language in a separate file.  It gets a bit like JavaScript where you have multiple languages for one application.  There's upsides and downsides to this approach.  The main downside is that there's a slightly steeper learning curve for the kids.
Despite the shortcomings, I'm most likely going to revisit kivy in my curriculum after my son gets through his 2D Maze games.    This assumes that I don't start on django.



8 comments:

  1. Kivy is very hard to understand and painful to implement for games. It adds a layer of abstraction to python/pygame/pgs4a that sucks all of the 'fun' out of programming. Of course your son got pong working quickly -- there is a tutorial showing him the code.

    Ask him to take a game he has written with Pgs4a and write it in Kivy. Better yet: try it yourself.

    Pyglet is an animation library. You can easily animate sprites in pygame and Pgs4a without it. Kivy is something else entirely. Comparing the two is absurd.

    ReplyDelete
    Replies
    1. Lol my apologies. I was confusing Pyganim and Pyglet. Comparing Kivy and Pyganim is NOT absurd. Although, Torturing a beginning programmer with Kivy is.

      Delete
    2. Thanks for taking the time to write this comment. Appreciate the help as I know very little about Kivy and am not much of a programmer. It's good to know that pygame is a good choice for teaching kids. Let me know if you have other suggestions. Pyglet seemed similar to pygame when I looked at it.

      Delete
  2. This comment has been removed by the author.

    ReplyDelete
  3. Hi Craig, your efforts with python, games and kivy are commendable. I am a beginner on this, but a little more serious about the teaching, so hope to have a proper curriculum etc. in the next few months. For now i just have a website, where i will be happy to post any child-friendly (meaning not too difficult) game samples you may have developed using kivy.
    http://www.pythongamer.in/

    ReplyDelete
    Replies
    1. Hi, I'm still focused on Pygame, both for the 14 year old boy and the 9 year old girl. IMO, it is easier for the kids to grasp Pygame because you can ease into object oriented programming. For Kivy, you need to jump right in. You can see my early philosophy here: https://www.youtube.com/watch?v=re2oDDaNbTM

      I have many code examples on GitHub. These are designed for a 12 to 13 year old student. I have a 9 year old girl going through the Group I lessons with good progress. The 14 year old boy is now doing OOP, recursion, and file I/O, which goes beyond the code examples I list below.

      https://github.com/codetricity/pychildren

      Delete
  4. Thoughtful blog post . I am thankful for the information ! Does someone know if my company might be able to get a sample AgentMapIt Real Estate Agent Referral Form form to edit ?

    ReplyDelete
  5. I’m really impressed with your blog article, such great & useful knowledge you mentioned here
    mobile game developers

    ReplyDelete