21462
备注:
|
21103
|
删除的内容标记成这样。 | 加入的内容标记成这样。 |
行号 5: | 行号 5: |
pygame module for cursor resources pygame.cursors.compile - create binary cursor data from simple strings create binary cursor data from simple strings pygame.cursors.load_xbm - load cursor data from an xbm file load cursor data from an xbm file Pygame offers control over the system hardware cursor. Pygame only supports black and white cursors for the system. You control the cursor with functions inside pygame.mouse. This cursors module contains functions for loading and unencoding various cursor formats. These allow you to easily store your cursors in external files or directly as encoded python strings. The module includes several standard cursors. The pygame.mouse.set_cursor - set the image for the system mouse cursor function takes several arguments. All those arguments have been stored in a single tuple you can call like this: >>> pygame.mouse.set_cursor(*pygame.cursors.arrow) |
pygame中控制鼠标指针资源的模块 pygame提供了对系统硬件鼠标指针的控制。pygame只支持系统中黑白色的指针。你可以通过pygame.mouse模块控制指针。 这个cursors模块包含载入和解码各种不同格式指针的函数。这些函数允许你把指针很容易的保存在外部文件中,也很容易直接编码为字符串。 模块包括几个标准的鼠标指针。pygame.mouse.set_cursor需要好几个参数。所有那些参数都已经保存在一个元组中,可以这样调用 {{{ >>> pygame.mouse.set_cursor(*pygame.cursors.arrow) }}} |
pygame.cursors
pygame中控制鼠标指针资源的模块
pygame提供了对系统硬件鼠标指针的控制。pygame只支持系统中黑白色的指针。你可以通过pygame.mouse模块控制指针。
这个cursors模块包含载入和解码各种不同格式指针的函数。这些函数允许你把指针很容易的保存在外部文件中,也很容易直接编码为字符串。
模块包括几个标准的鼠标指针。pygame.mouse.set_cursor需要好几个参数。所有那些参数都已经保存在一个元组中,可以这样调用
>>> pygame.mouse.set_cursor(*pygame.cursors.arrow)
- This module also contains a few cursors as formatted strings. You'll need to pass these to pygame.cursors.compile - create binary cursor data from simple strings function before you can use them. The example call would look like this:
>>> cursor = pygame.cursors.compile(pygame.cursors.textmarker_strings) >>> pygame.mouse.set_cursor(*cursor)
- o pygame.cursors.arrow o pygame.cursors.diamond o pygame.cursors.broken_x o pygame.cursors.tri_left o pygame.cursors.tri_right
- o pygame.cursors.thickarrow_strings o pygame.cursors.sizer_x_strings o pygame.cursors.sizer_y_strings o pygame.cursors.sizer_xy_strings
1. pygame.cursors.compile
- create binary cursor data from simple strings pygame.cursor.compile(strings, black='X', white='.', xor='o'): return data, mask A sequence of strings can be used to create binary cursor data for the system cursor. The return values are the same format needed by pygame.mouse.set_cursor - set the image for the system mouse cursor. If you are creating your own cursor strings, you can use any value represent the black and white pixels. Some system allow you to set a special toggle color for the system color, this is also called the xor color. If the system does not support xor cursors, that color will simply be black. The width of the strings must all be equal and be divisible by 8. An example set of cursor strings looks like this
- thickarrow_strings = ( #sized 24x24
- "XX ", "XXX ", "XXXX ", "XX.XX ", "XX..XX ", "XX...XX ", "XX....XX ", "XX.....XX ", "XX......XX ", "XX.......XX ", "XX........XX ", "XX........XXX ", "XX......XXXXX ", "XX.XXX..XX ", "XXXX XX..XX ", "XX XX..XX ", " XX..XX ", " XX..XX ", " XX..XX ", " XXXX ", " XX ", " ", " ", " ")
\ZnbNzgytswsc %%%%%%%%%%%%%% _
- thickarrow_strings = ( #sized 24x24
2. pygame.cursors.load_xbm
- load cursor data from an xbm file pygame.cursors.load_xbm(cursorfile, maskfile=None): return cursor_args This loads cursors for a simple subset of XBM files. XBM files are traditionally used to store cursors on unix systems, they are an ascii format used to represent simple images. Sometimes the black and white color values will be split into two separate XBM files. You can pass a second maskfile argument to load the two images into a single cursor. The cursorfile and maskfile arguments can either be filenames or filelike object with the readlines method. The return value cursor_args can be passed directly to the pygame.mouse.set_cursor - set the image for the system mouse cursor function.
pygame.joystick
- pygame module for interacting with joystick devices The joystick module manages the joystick devices on a computer (there can be more than one). Joystick devices include trackballs and video-game-style gamepads, and the module allows the use of multiple buttons and "hats".
1. pygame.joystick.init
- initialize the joystick module pygame.joystick.init(): return None This function is called automatically by pygame.init - initialize all imported pygame modules. It initializes the joystick module. This will scan the system for all joystick devices. The module must be initialized before any other functions will work. It is safe to call this function more than once.
2. pygame.joystick.quit
- uninitialize the joystick module pygame.joystick.quit(): return None Uninitialize the joystick module. After you call this any existing joystick objects will no longer work. It is safe to call this function more than once.
3. pygame.joystick.get_init
- true if the joystick module is initialized pygame.joystick.get_init(): return bool Test if the pygame.joystick.init - initialize the joystick module function has been called.
4. pygame.joystick.get_count
- number of joysticks on the system pygame.joystick.get_count(): return count Return the number of joystick devices on the system. The count will be 0 if there are no joysticks on the system. When you create Joystick objects using Joystick(id), you pass an integer that must be lower than this count.
5. pygame.joystick.Joystick
- create a new Joystick object
pygame.joystick.Joystick(id): return Joystick Joystick.init - initialize the Joystick initialize the Joystick Joystick.quit - uninitialize the Joystick uninitialize the Joystick Joystick.get_init - check if the Joystick is initialized check if the Joystick is initialized Joystick.get_id - get the Joystick ID get the Joystick ID Joystick.get_name - get the Joystick system name get the Joystick system name Joystick.get_numaxes - get the number of axes on a Joystick get the number of axes on a Joystick Joystick.get_axis - get the current position of an axis get the current position of an axis Joystick.get_numballs - get the number of trackballs on a Joystick get the number of trackballs on a Joystick Joystick.get_ball - get the relative position of a trackball get the relative position of a trackball Joystick.get_numbuttons - get the number of buttons on a Joystick get the number of buttons on a Joystick Joystick.get_button - get the current button state get the current button state Joystick.get_numhats - get the number of hat controls on a Joystick get the number of hat controls on a Joystick Joystick.get_hat - get the position of a joystick hat get the position of a joystick hat
- Create a new joystick to access a physical device. The id argument must be a value from 0 to pygame.joystick.get_count()-1. To access most of the Joystick methods, you'll need to init() the Joystick. This is separate from making sure the joystick module is initialized. When multiple Joysticks objects are created for the same physical joystick device (i.e., they have the same ID number), the state and values for those Joystick objects will be shared. The Joystick object allows you to get information about the types of controls on a joystick device. Once the device is initialized the Pygame event queue will start receiving events about its input. You can call the Joystick.get_name - get the Joystick system name and Joystick.get_id - get the Joystick ID functions without initializing the Joystick object. January 14, 2006 10:59pm - Anonymous I have both a four button and two button joystick. (Two for older games). What they have in common is that when I pull the joystick in any direction it goes FULL BLAST. I need a joystick which will move SLOWLY with a minimal turn rather than a MAXIMUM turn upon any movement of the joy stick. Is there any way to make the joystick move a little bit with small movements of the stick? If I want maximum movement I would pull the stick FULL in that direction! Please advise
5.1. Joystick.init
- initialize the Joystick Joystick.init(): return None The Joystick must be initialized to get most of the information about the controls. While the Joystick is initialized the Pygame event queue will receive events from the Joystick input. It is safe to call this more than once.
5.2. Joystick.quit
- uninitialize the Joystick Joystick.quit(): return None This will unitialize a Joystick. After this the Pygame event queue will no longer receive events from the device. It is safe to call this more than once.
5.3. Joystick.get_init
- check if the Joystick is initialized Joystick.get_init(): return bool Returns True if the init() method has already been called on this Joystick object.
5.4. Joystick.get_id
- get the Joystick ID Joystick.get_id(): return int Returns the integer ID that represents this device. This is the same value that was passed to the Joystick() constructor. This method can safely be called while the Joystick is not initialized.
5.5. Joystick.get_name
- get the Joystick system name Joystick.get_name(): return string Returns the system name for this joystick device. It is unknown what name the system will give to the Joystick, but it should be a unique name that identifies the device. This method can safely be called while the Joystick is not initialized.
5.6. Joystick.get_numaxes
- get the number of axes on a Joystick Joystick.get_numaxes(): return int Returns the number of input axes are on a Joystick. There will usually be two for the position. Controls like rudders and throttles are treated as additional axes. The pygame.JOYAXISMOTION events will be in the range from -1.0 to 1.0. A value of 0.0 means the axis is centered. Gamepad devices will usually be -1, 0, or 1 with no values in between. Older analog joystick axes will not always use the full -1 to 1 range, and the centered value will be some area around 0. Analog joysticks usually have a bit of noise in their axis, which will generate a lot of rapid small motion events.
5.7. Joystick.get_axis
- get the current position of an axis Joystick.get_axis(axis_number): return float Returns the current position of a joystick axis. The value will range from -1 to 1 with a value of 0 being centered. You may want to take into account some tolerance to handle jitter, and joystick drift may keep the joystick from centering at 0 or using the full range of position values. The axis number must be an integer from zero to get_numaxes()-1.
5.8. Joystick.get_numballs
- get the number of trackballs on a Joystick Joystick.get_numballs(): return int Returns the number of trackball devices on a Joystick. These devices work similar to a mouse but they have no absolute position; they only have relative amounts of movement. The pygame.JOYBALLMOTION event will be sent when the trackball is rolled. It will report the amount of movement on the trackball.
5.9. Joystick.get_ball
- get the relative position of a trackball Joystick.get_ball(ball_number): return x, y Returns the relative movement of a joystick button. The value is a x, y pair holding the relative movement since the last call to get_ball. The ball number must be an integer from zero to get_numballs()-1.
5.10. Joystick.get_numbuttons
- get the number of buttons on a Joystick Joystick.get_numbuttons(): return int Returns the number of pushable buttons on the joystick. These buttons have a boolean (on or off) state. Buttons generate a pygame.JOYBUTTONDOWN and pygame.JOYBUTTONUP event when they are pressed and released. December 8, 2005 9:12pm - Anonymous There is a way to know the state of a button! Joystick.get_button(n)
5.11. Joystick.get_button
- get the current button state Joystick.get_button(button): return bool Returns the current state of a joystick button.
5.12. Joystick.get_numhats
- get the number of hat controls on a Joystick Joystick.get_numhats(): return int Returns the number of joystick hats on a Joystick. Hat devices are like miniature digital joysticks on a joystick. Each hat has two axes of input. The pygame.JOYHATMOTION event is generated when the hat changes position. The position attribute for the event contains a pair of values that are either -1, 0, or 1. A position of (0, 0) means the hat is centered.
5.13. Joystick.get_hat
- get the position of a joystick hat Joystick.get_hat(hat_number): return x, y Returns the current position of a position hat. The position is given as two values representing the X and Y position for the hat. (0, 0) means centered. A value of -1 means left/down and a value of 1 means right/up: so (-1, 0) means left; (1, 0) means right; (0, 1) means up; (1, 1) means upper-right; etc. This value is digital, i.e., each coordinate can be -1, 0 or 1 but never in-between. The hat number must be between 0 and get_numhats()-1.
pygame.time
- pygame module for monitoring time Times in pygame are represented in milliseconds (1/1000 seconds). Most platforms have a limited time resolution of around 10 milliseconds.
1. pygame.time.get_ticks
- get the time in milliseconds pygame.time.get_ticks(): return milliseconds Return the number of millisconds since pygame.init - initialize all imported pygame modules was called. Before pygame is initialized this will always be 0.
2. pygame.time.wait
- pause the program for an amount of time pygame.time.wait(milliseconds): return time Will pause for a given number of milliseconds. This function sleeps the process to share the processor with other programs. A program that waits for even a few milliseconds will consume very little processor time. It is slightly less accurate than the pygame.time.delay - pause the program for an amount of time function. This returns the actual number of milliseconds used.
3. pygame.time.delay
- pause the program for an amount of time pygame.time.delay(milliseconds): return time Will pause for a given number of milliseconds. This function will use the processor (rather than sleeping) in order to make the delay more accurate than pygame.time.wait - pause the program for an amount of time. This returns the actual number of milliseconds used.
4. pygame.time.set_timer
- repeatedly create an event on the event queue pygame.time.set_timer(eventid, milliseconds): return None Set an event type to appear on the event queue every given number of milliseconds. The first event will not appear until the amount of time has passed. Every event type can have a separate timer attached to it. It is best to use the value between pygame.USEREVENT and pygame.NUMEVENTS. To disable the timer for an event, set the milliseconds argument to 0.
5. pygame.time.Clock
- create an object to help track time pygame.time.Clock(): return Clock
- Clock.tick - update the clock update the clock Clock.tick_busy_loop - update the clock update the clock Clock.get_time - time used in the previous tick time used in the previous tick Clock.get_rawtime - actual time used in the previous tick actual time used in the previous tick Clock.get_fps - compute the clock framerate compute the clock framerate
5.1. Clock.tick
- update the clock Clock.tick(framerate=0): return milliseconds control timer events This method should be called once per frame. It will compute how many milliseconds have passed since the previous call. If you pass the optional framerate argument the function will delay to keep the game running slower than the given ticks per second. This can be used to help limit the runtime speed of a game. By calling Clock.tick(40) once per frame, the program will never run at more than 40 frames per second. Note that this function uses SDL_Delay function which is not accurate on every platform, but does not use much cpu. Use tick_busy_loop if you want an accurate timer, and don't mind chewing cpu.
5.2. Clock.tick_busy_loop
- update the clock Clock.tick_busy_loop(framerate=0): return milliseconds control timer events This method should be called once per frame. It will compute how many milliseconds have passed since the previous call. If you pass the optional framerate argument the function will delay to keep the game running slower than the given ticks per second. This can be used to help limit the runtime speed of a game. By calling Clock.tick(40) once per frame, the program will never run at more than 40 frames per second. Note that this function uses pygame.time.delay, which uses lots of cpu in a busy loop to make sure that timing is more acurate.
5.3. Clock.get_time
- time used in the previous tick Clock.get_time(): return milliseconds Returns the parameter passed to the last call to Clock.tick - update the clock. It is the number of milliseconds passed between the previous two calls to Pygame.tick().
5.4. Clock.get_rawtime
- actual time used in the previous tick Clock.get_rawtime(): return milliseconds Similar to Clock.get_time - time used in the previous tick, but this does not include any time used while Clock.tick - update the clock was delaying to limit the framerate.
5.5. Clock.get_fps
- compute the clock framerate Clock.get_fps(): return float Compute your game's framerate (in frames per second). It is computed by averaging the last few calls to Clock.tick - update the clock.