Instant Pygame for Python Game Development How-to by Idris Ivan
Author:Idris, Ivan [Idris, Ivan]
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 0101-01-01T00:00:00+00:00
Pausing the game: Sometimes we need to pause the execution of a game, as in our case in order to be able to hear a sound. We can do this with the following code snippet:pygame.time.delay(TIMEOUT * 1000)
The delay is specified in milliseconds, that's why we are multiplying by 1000.
Stopping the sound: After a while we need to stop the sound with the corresponding stop method:audio.stop()
The audio demo code is listed as follows:
import pygame, sys from pygame.locals import * import numpy import urllib2 import time WAV_FILE = 'smashingbaby.wav' def play(): audio = pygame.mixer.Sound(WAV_FILE) audio.play(-1) TIMEOUT = 1 pygame.time.delay(TIMEOUT * 1000) audio.stop() time.sleep(TIMEOUT) pygame.init() pygame.display.set_caption('Sound Demo') response = urllib2.urlopen('http://www.thesoundarchive.com/austinpowers/smashingbaby.wav') filehandle = open(WAV_FILE, 'w') filehandle.write(response.read()) filehandle.close() screen = pygame.display.set_mode((400, 400)) while True: sys_font = pygame.font.SysFont("None", 19) rendered = sys_font.render('Smashing Baby', 0, (255, 100, 100)) screen.blit(rendered, (100, 100)) for event in pygame.event.get(): if event.type == QUIT: play() pygame.quit() sys.exit() pygame.display.update()
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Deep Learning with Python by François Chollet(12527)
Hello! Python by Anthony Briggs(9872)
OCA Java SE 8 Programmer I Certification Guide by Mala Gupta(9762)
The Mikado Method by Ola Ellnestam Daniel Brolund(9753)
Dependency Injection in .NET by Mark Seemann(9298)
Algorithms of the Intelligent Web by Haralambos Marmanis;Dmitry Babenko(8263)
Test-Driven iOS Development with Swift 4 by Dominik Hauser(7747)
Grails in Action by Glen Smith Peter Ledbrook(7672)
The Well-Grounded Java Developer by Benjamin J. Evans Martijn Verburg(7522)
Becoming a Dynamics 365 Finance and Supply Chain Solution Architect by Brent Dawson(6763)
Microservices with Go by Alexander Shuiskov(6530)
Practical Design Patterns for Java Developers by Miroslav Wengner(6424)
Test Automation Engineering Handbook by Manikandan Sambamurthy(6404)
Secrets of the JavaScript Ninja by John Resig Bear Bibeault(6384)
Angular Projects - Third Edition by Aristeidis Bampakos(5789)
The Art of Crafting User Stories by The Art of Crafting User Stories(5317)
NetSuite for Consultants - Second Edition by Peter Ries(5256)
Demystifying Cryptography with OpenSSL 3.0 by Alexei Khlebnikov(5077)
Kotlin in Action by Dmitry Jemerov(5024)
