Friday, 15 June 2012

python - How to create a simple event consisting of Event Id and a mathematic operation? -


I am slowly trying to learn Pagam and Python and I have tried to create a simple Sprishet animation. I am quite convinced that I am not doing it right, but I am still learning how the classes really work and even further. So far, I have a major press that is returning true and the return of a release is incorrect . True then activates the cycle of animation.

  is done, while == incorrect: for event in pygame.event.get (): if event.type == pygame .KEYDOWN: if event.key == pygame.K_RIGHT : X_speed = walk_speed dir = 1 cycle = true if event.key == pygame.K_LEFT: x_speed = 0 - walk_speed dir = 0 cycle = true if event.type == pygame .keyup: if event.key == pygame.K_RIGHT : X_speed = 0dir = 1 cycle = wrong if event.key == pygame.K_LEFT: x_speed = 0dir = 0 circle = wrong cycle == true: this + = 1 if it & gt; 6: it = 0 pygame.time.set_timer (this, 100) elifcycle == incorrect: this = 1 pygame.time.set_timer (this, 0) it = 1 ennis.speed = x_speed if it & gt; 6: it = 0 if dir == 1: ennis.sprite = walking_right [it] if dir == 0: ennis.sprite = walking_left [it] ennis.update ()   

I It's a terrible, dirty, it may be the fundamental way to know, but it works and I understand it! Okay, it almost works.

At present, the event ID is sent to pygame.time.set_timer () this variable, which throws up a value error , it is saying that the ID should be between NoAvent (0) and Renewal (32) . So, the way I see it, that is, I need to create an event that increases by 1, and resets it from 0 when it is greater than 6.

Thanks any help!

There is no need to use events for the animation, such a use can be blinking stars .

How the pygame event queue works:

The operating system sends your keyboard and mouse press in the queue when you go to pygame.event.get () When you call it, it receives the event before the queue, then you can check the type of: key, and its related buttons.

What sets_mimar, this sets the repeating event of your choice. If we set the timer in 1 second, with Event ID of 12, we get an event in every second will do. We can take some action, for example a sound play, it has not actually been used in animation.

How an animated phantom is written:

Instead of your Boolean values, you must have a state: STANDING and walking . There should be an updated method of sprite, where you move the phantom, and change its surface. Every call should be assigned to the next surface to update. For some types of delays, you can use the clock, which will return the number of MS since the last call. In this way, you can store the result of the clock up to a few high values, when you change the phantom.

No comments:

Post a Comment