Jump to content

View more

Image of the Day

#indiedev  #indiegame #screenshotsaturday https://t.co/IwVbswGrhe
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

PyGame, Cocos2d or PyGlet?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
5 replies to this topic

#1 Eamonn Rea   Members   


Posted 11 July 2013 - 02:35 PM

Yes, I switch from language to language, but I want to learn a lot of languages. This isn't a bad thing, is it? I think it keeps me interested in programming(and has done for the past 3 and a half years!). Not that programming is boring, but I think you know what I mean :)


Anyway, the reason I've made this thread is because I want to know what Python library to use, explain to you what my issues are with them all and hopefully you can help me make the right choice.


Actually, before I say what my problems are, don't just get angry and say "LOL N00B! Use C++! Python is for N00BZ!", because that isn't true(first of all), and a few awesome programs that I've seen have been made in Python. And there's PyWeek, and I know there's a pure Python 3D MMO that's like $20 or something. That says something! I believe Python is a great language, simplistic and really good to use for game programming. I know CoderDojo, and I go there. They teach GameMaker, AppInventor and HTML/CSS/JavaScript. I already know how to use these(and I am against stuff like GameMaker, Scratch, AppInventor etc because I don't think it's right to use it. You should code a game, not have software do 80% if the work. This is just my opinion though and maybe you feel the same) and know Python. They are planning on teaching C/C++/Ruby soon, but that's beside the point. They have Raspberry Pi's to teach Python, and the Pi's come built in with PyGame. So they teach kids to code in Python. Point: Python is great for kids, and PyGame seems good. Now that that's out of the way, on to the point!






PyGame is probably the most popular 2D game development for Python. If you google Python Game Development, PyGame is the first result(as of my posting this). It's one of my favourite game libraries for any language, but it's not my favourite Python game library. Here are the pro's and con's:



• Simple to use

• Powerful

• Support for PyOpenGL

• Based on the very powerful SDL library for C/C++

• Designed for game development



• Based on SDL, which is a C/C++ library so it doesn't feel as "Python"-e as Pyglet

• Not many guides

• The docs are alright

• Doesn't have support for loading TMX(Tiled) maps

• Designed for 2D games(but does offer support for 3D if needed)


My problems:

• Can't figure out how to have smooth player movement(1)

• Can't figure out how to have delta time(2)

• Can't figure out how to check if a key is held down(3)



Problem 1:

I cant figure out how to have smooth player movement and how to tell if a key is held down! Maybe I've been spoiled with LÖVE, but when I check for a key press and add 10 to the players X position, it jumps 10 pixels and doesn't transition there.


Problem 2:

I can't figure out how to have delta time in my game! Does PyGame handle this? Can I store it in a variable called DT or does PyGame do this for me?


Problem 3:

I can't find out how to check if a key is being held down. Event name or something?








Cocos2d is one of the few Python Game libraries, other then for PyGame. It's based on PyGlet, which is my personal favourite Python Library in general. It's designed for games, but there are a few problems and a few upsides:



• Supports TMX maps

• More "Python"ish

• Designed for game development

• Powerful

• Based on PyGlet

• Active(Updated less then a year ago)

• Has support for smooth player movement( Cocos.Sprite.Transition method )



• The docs are SO BAD.

• Lack of guides

• Confusing(Uses Nodes, which make no sense to me!!!), probably due to lack of tutorials or guides in general

• Locked to 2D games(unlike PyGlet and PyGame)


My Problems:

• Cannot find an understandable guide(1)

• Cannot find Delta Time(2)



• Can I use PyGlet alongside it?



Problem 1:

Cocos2d is a fabulous framework... from examples I've looked at and from what I've heard people say. The fact that it has smooth player movement overjoys me. The problem I'm having is finding a good tutorial. Even a book would be awesome at this point(and I hate reading books to learn programming, but when I have to I have to :P )! I think I saw a paid tutorial for like $35 somewhere, but I wouldn't pay to learn it, I'd rather learn C++ and use that with SDL or something!


Problem 2:

Delta time is something I can't seem to find in any of these libraries!



Question 1:

Knowing that Cocos2d is built on PyGlet, that made me question whether or not it's possible to use Cocos2d along with it.








PyGlet is by far my favourite library for Python... even if it wasn't designed for games, I saw someone make a simple Minecraft clone is PygGlet. It was pretty inspiring in my opinion! Despite it being my favourite, I still have a few things to say about it:



• Simple to use

• Powerful

• Has support for 3D(Possibly using PyOpenGL, but I'm not sure. I know it uses OpenGL either way)

• Very good tutorials & Reference guides -- In fact it's the best that I've seen!

• Good for any type of application

• Very "Python"ish



• Not designed for game development


My Problems

• Cannot figure out how to use Delta Time(1)

• Cannot figure out how to use smooth player movement(2)



Problem 1:

I assume since I'm having this problem will every library I've mentioned that the libraries handle it for me.


Problem 2:

Smooth player movement still remains a mystery! I can check if a key is held down, but (as like in PyGame) the player jumps there and doesn't transition there.






I know, a long topic, but hopefully I provided all the information needed for you to give me an informative answer. I've been told I don't give enough information, so maybe this is enough!


So yeah! Thanks! Any help is appreciated!!

#2 shadowisadog   Members   


Posted 11 July 2013 - 05:41 PM

In PyGame here is a way to handle the timestep issue. That may be overcomplicated though. You could read this and implement something yourself.


Here is something that might help you understand the smooth movement issue. Here is another helpful explanation.

Edited by shadowisadog, 11 July 2013 - 05:43 PM.

#3 Eamonn Rea   Members   


Posted 11 July 2013 - 05:55 PM

Thanks! I'll look into both of them! I looked into them briefly and I'm sure they'll be a big help! Thank you! :)

#4 permian_lizard   Members   


Posted 12 July 2013 - 09:17 AM

Thanks for the post -Pyglet is also my firm favourite here. Unfortunately its been very quiet since its last 2012 release.


As for your pros/cons another point might be python 3 support. Pyglet's last release began the process but its still an early alpha -Im not sure about pygame.

#5 Kylotan   Moderators   


Posted 12 July 2013 - 09:50 AM

Problem 1: others have answered this - most systems won't handle transitions automatically. You have to change the value yourself over time, or find someone else's code to do it for you.


Problem 2: you can calculate delta time yourself by calling pygame.time.get_ticks each frame. Cache the value of the previous call and check the difference each time. In pyglet, you choose how often you want an update function to get called, which means you will know the delta time value in advance. Here's the way to schedule an update - http://www.pyglet.org/doc/programming_guide/calling_functions_periodically.html


Problem 3: in Pygame, it's http://www.pygame.org/docs/ref/key.html#pygame.key.get_pressed and in pyglet it's http://www.pyglet.org/doc/programming_guide/keyboard_events.html#remembering-key-state

#6 KnolanCross   Members   


Posted 12 July 2013 - 11:02 AM

On your third problem you are probably having trouble with the pressed/down concept.


Most frameworks will give you two different functions to access the keyboard:


1) Button pressed: this will be set ONCE when the key is pressed and will only be set again when the user releases the key and presses it again.

2) Button is down: this will be set from the time the button press a key untill the moment it releases it.


If you are using the first implementation type, you probably need to set some value telling you that the key is pressed and check this value every frame, you also will need to find a function that tells you when the button is released.


If you check the pygame documentation (which I found really good to be honest), you will find several examples of implementations with they keyboard interface (they use the 2nd method I described above). Here is a link for the examples:



And here is a link for the full documentation:



On the time, use the Clock object, call the get_time() to get the dt and call the tick() at the end of your loop to update it

Link for the clock documentation:


Edited by KnolanCross, 12 July 2013 - 11:03 AM.

Currently working on a scene editor for ORX (http://orx-project.org), using kivy (http://kivy.org).

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.