fertiq.blogg.se

Quick sprites
Quick sprites




quick sprites
  1. #QUICK SPRITES HOW TO#
  2. #QUICK SPRITES FULL#

That means we can have it always being dirty. Note that as we mentioned before, the chimp is always either moving or spinning. So to prevent this, for now, let’s keep both of them always dirty after an update. That is because we’re going to make the rendering be dependent on their dirty flag (that is, they will only be updated if they have dirty = 1). Now, if we’re going to keep the source as it is, the sprites would disappear immediately after first appearing. Voila, Fist and Chimp are now DirtySprite Of course, DirtySprite is a subclass of Sprite, so this change would have no effect for now: #!python The dirt Using DirtySpriteįirst things first, we’re going to use the DirtySprite class for both sprites. The fist follows the cursor movement, if there was any, and on a click event, it is lowered by a few pixels for a second, to simulate a hit. The chimp is always undergoing a change, either in its position (running around) or its angle (spinning when punched). There are two sprites used in this game: The chimp and the fist. Its original source code is available under examples/chimp.py in the Pygame distribution. Writing this game is described in Pete Shinners’ Line By Line Chimp tutorial, in case you need to wrap your head around basic Pygame principles. The game comprises of an image of a chimp that’s quickly floating from right to left, and a fist image representing the user’s mouse cursor trying to punch it. Pummel The ChimpĪs a simple basic game, we are going to use chimp.py, an extremely basic game based on the infamous “Win $$$” banner ads of the 1990s.

#QUICK SPRITES FULL#

The full source code for the tutorial, as well as a diff for each step, are all available to browse in the dirty_chimp project on GitHub. In this short tutorial, I will show you a very basic use case for DirtySprite and how I implemented it in an existing game source. By using these two instead of the regular Sprite and Group classes, you can keep track on what parts of the screen need a refresh and what don’t, and in turn, your game renders in a smarter and more efficient way. You can imagine that drawing things on the screen is one of the heavier tasks, and that’s where the DirtySprite and LayeredDirty classes come in. In fact, whenever I read the source code for a game I’m surprised by how many tasks get done on each iteration, that is, dozens of times per second.

#QUICK SPRITES HOW TO#

Knowing how to use Pygame’s various sprite classes is essential to getting good and efficient results when working on Pygame games.Įvery computer game is made out of a loop that’s constantly re-validating the input and the game data and refreshing the display accordingly.






Quick sprites