[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] colorkey and time scale

azazel wrote:
- To get and set the colorkey of a surface I use the get_colorkey and set_colorkey methods, till now I've written the colorkey of every
image in a file, and after loading an image I set the colorkey read in
that file with set_colorkey. There is a way to set a default colorkey
for an image that don't force me to store it in another file?
several image formats can store the colorkey internally. the two best examples of this would be GIF and PNG. if these images have a colorkey set, then they will have their colorkey all setup when you load them.

another "popular" example is to just take the colorvalue in one of the image corners and assume that is the transparent color. the pygame examples like chimp and aliens have a 'magic' image loader function that can do this corner transparancy by passing "-1" as the colorkey. of course, again, if the image already has a colorkey, you won't need to pass anything extra to these load functions.

- I've noticed that some games use a time_scale variables to regulate
  the movement of the sprite in connection with the actual speed of the
  game. For example if I want to run my game with a framerate of 30fps
  and prev_tick - last_tick is time elapsed since last frame time_scale

  time_scale = (last_tick - prev_tick) / 30.0
there are two styles of speed control in games.

fixed step: the simpler one is to set a reasonable maximum framerate, and just slow the game down to make sure it runs at the correct speed. this is usually all you need for simpler games, you animate objects by saying 'move this many pixels per frame'.

variable step: the other more advanced (and flexible) method is to animate your objects by actual clock time. this is how most modern games operate, and the game can then run at any given "framerate". you now animate by saying 'move this many pixels per millisecond' (or any arbitrary time measurement). there can be some tricky issues associated with this type of game. for example, if you had an enemy fire a bullet randomly. this time based animation would cause more bullets to be fired on faster machines and less bullets to be fired on slower machines. you also have to adjust your "random chance" variables by how much time has passed.

that's a real rough breakdown of how timing can work. of course you can use anything and whatever in between. games like diablo2 used a fixed framerate for the game data internals (like causing damage), and a variable framerate for rendering the display.

pygame mailing list