-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimpleNotes
More file actions
87 lines (65 loc) · 6.32 KB
/
Copy pathsimpleNotes
File metadata and controls
87 lines (65 loc) · 6.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
Pygame represents images as Surface Objects. The display.set_mode() function creates a new surface object
that represents the actual displayed graphics. Any drawing you do to this Surface will become on the monitor.
Drawing of images is handled by the Surface.blit() method. A blit basically means copying pixel colors from one
image to another. We pass the blit method a source Surface to copy from, and a position to place the source onto
the destination.
Para usar Variables Constantes, debes usar la palabra reservada global
EX:
date = '10-07-2001'
def get_date():
global date
date = '10-07-2001'
pygame.local, si importamos este modulo de pygame, lo que va a ser es colocar un set de limite de cuantas constantes y
funciones puede haber en el namespace del Script
Antes de poder usar Pygame, se debe inicializar: pygame.init. Inicializa todos los modulos de python para ti.
No todos los modulos de python deben ser inicializados, pero esto automaticamente inicializa los que lo hagan.
Tambien puedes inicializar cada modulo de Pygame por tu cuenta a mano, asi seria un ejemplo:
pygame.font.init()
Tenga en cuenta que si hay un error al inicializar con "pygame.init()", fallará silenciosamente.
Al inicializar manualmente módulos como este, cualquier error generará una excepción.
Cualquier módulo que deba inicializarse también tiene una función "get_init()", que devolverá true si el módulo
se ha inicializado. Es seguro llamar a la función init() para cualquier módulo más de una vez.
Los modulos que se inicializan tienen usualmente un funcion de quit() que limpiara y quitara el codigo (por ejemplo la ventana)
No hay necesidad de llamar a las funciones de quit(), ya que pygame quitara todo una vez python haya finalizado de ejecutarse
The 3 main objects in Pygame: The Screen, The Background and the Text. Each of these objects can be created by first calling an
in-built Pygame Object, and then modifying it to fit our needs.
The Background we create an object and then we convert ( pygame.Surface.convert() ) to a Single Pixel Format. This is more obviously
necessary when we have several images and surfaces, all of different pixel formats. Summary: One Pixel Format for everything.
By converting all the Surfaces, we can drastically speed up rendering times.
With Text, we require more than one object. First we define a Font object, which defines which font to use, and the size of the font
Then we create a Text object, by using the render method that belongs.
The term used for rendering objects is Blitting, which is where you copy the pixels belonging to said object onto the destination
object. So to render the background object, you blit it onto the screen. Blitting is one of the slowest operation in any game,
so you need to be careful not to blit too much onto the screen in every frame. If you have a background image, and a ball flying
around the screen, then you could blit the background and then the ball in every frame, which would cover up the ball's previous
position and then render the new ball, but this would be pretty slow. A better solution is to blit the background onto the area
that the ball previously occupied, which can be found by the ball's previous rectangle, and then blitting the ball, so that
you are only blitting two small areas.
Pygame handles all its event messaging through an event queue. The routines in this module help you manage that event queue.
The input queue is heavily dependent on the pygame.display pygame module to control the display window and screen module.
If the display has not been initialized and a video mode not set, the event queue may not work properly.
The event queue has an upper limit on the number of events it can hold. When the queue becomes full new events are quietly dropped.
To prevent lost events, especially input events which signal a quit command, your program must handle events every frame
(with pygame.event.get(), pygame.event.pump(), pygame.event.wait(), pygame.event.peek() or pygame.event.clear()) and process them.
Not handling events may cause your system to decide your program has locked up. To speed up queue processing use
pygame.event.set_blocked() control which events are allowed on the queue to limit which events get queued.
To get the state of various input devices, you can forego the event queue and access the input devices directly with their appropriate
modules: pygame.mousepygame module to work with the mouse, pygame.keypygame module to work with the keyboard, and pygame.joystickPygame
module for interacting with joysticks, gamepads, and trackballs..
If you use this method, remember that pygame requires some form of communication with the system window manager and other parts of the
platform. To keep pygame in sync with the system, you will need to call pygame.event.pump() internally process pygame event handlers to
keep everything current. Usually, this should be called once per game loop. Note: Joysticks will not send any events until the device
has been initialized.
The event queue also offers some simple filtering which can slightly help performance by blocking certain event types from the queue.
Use pygame.event.set_allowed()control which events are allowed on the queue and pygame.event.set_blocked()control which events are
allowed on the queue to change this filtering. By default, all event types can be placed on the queue.
You can put functions within the def __init__() function. Example:
def __init__(self, window):
pygame.rect.Rect(Information_to_diplay)
self.window
Estos archivos .json se encuentran en una carpeta oculta llamada .vs en la carpeta raíz del código base. Visual Studio crea los archivos
tasks.vs.json y launch.vs.json según sea necesario cuando se elija Configurar tareas o Configuración de depuración e inicio en un archivo
o una carpeta del Explorador de soluciones.Estos archivos .json están ocultos porque los usuarios habitualmente no desean insertarlos en
el control de código fuente. Sin embargo, si desea poder comprobarlos en el control de código fuente, arrastre los archivos a la raíz del
código base mediante el sistema de archivos, donde estarán visibles en el Explorador de soluciones y en el control de código fuente.
The flags argument is a collection of additional options. The depth argument represents the number of bits to use for color.