sprite

Pygame sprite not moving while jumping

空扰寡人 提交于 2021-01-28 11:26:46
问题 I'm confused why my sprite is not moving while jumping. I've checked several times and changed my code over and over with no luck. My code is below and contains 3 pages, first contain the main loop, second contain the player class and third contain some game functions. Main import pygame from player import Player import game_functions as gf import sys import time def run_game(): # Intialise the game and start the screen pygame.init() screen = pygame.display.set_mode((800, 600)) pygame.display

Ship moves up and left faster than down and right when rotating in pygame

被刻印的时光 ゝ 提交于 2021-01-28 09:55:35
问题 I am working on a simple game. I created a pygame sprite which and tested it by making it move forward and rotating at a consistent speed. However, it seams to be moving left and up (where sin and cos are negative) quicker than right and down (where sin and cos are positive). I tested it without moving and just rotating and it works. Here is the code: import pygame import sys from math import cos, sin, pi from time import sleep SCREEN_WIDTH = 800 SCREEN_HEIGHT = 800 FPS = 60 pygame.init()

Ship moves up and left faster than down and right when rotating in pygame

安稳与你 提交于 2021-01-28 09:55:32
问题 I am working on a simple game. I created a pygame sprite which and tested it by making it move forward and rotating at a consistent speed. However, it seams to be moving left and up (where sin and cos are negative) quicker than right and down (where sin and cos are positive). I tested it without moving and just rotating and it works. Here is the code: import pygame import sys from math import cos, sin, pi from time import sleep SCREEN_WIDTH = 800 SCREEN_HEIGHT = 800 FPS = 60 pygame.init()

Why do group lists in pygame have to have “update” functions, and not any other?

大兔子大兔子 提交于 2021-01-28 07:16:21
问题 I made a small particles application, but I was testing it and the function at the bottom has to be called "update". I thought the function name, just like variables, was just a name. I thought it didn't matter what it was named, as long as it's the same when you call it. Apparently I was wrong. It will only recognize "update". If I change the function to "move", it will throw an error. Could someone explain why it's like this? import pygame import random pygame.init() win_height=600 win

Make a line as a sprite with its own collision in Pygame

喜你入骨 提交于 2021-01-24 07:50:28
问题 I am making a game that connects a line between a 2 players. I want to make it so I can tell when an object (which is also a sprite) collides with the line. The way I thought of doing this is creating a line that acts a sprite. The line will be able to change length depending on where the players are. I'm a bit new to PyGame so I'm not too sure on what I have so far: class Line(pygame.sprite.Sprite): def __init__(self): pygame.sprite.Sprite.__init__(self) self.image = pygame.Surface([400,400]

How to Display Sprites in Pygame?

雨燕双飞 提交于 2021-01-23 11:02:10
问题 This is just a quick question regarding sprites in PyGame, I have my image loaded as in the code below, and I'm just wondering how to display the sprite in PyGame like drawing a rectangle or circle. I don't want to have it behave in anyway. I think I use a blit command, but I'm not sure and I'm not finding much online. Here's my image code for loading it. Star = pygame.image.load('WhiteStar.png').convert_alpha() You could just provide an outline for loading a sprite. I simply want to display

How to turn the sprite in pygame while moving with the keys

拟墨画扇 提交于 2020-12-23 12:17:13
问题 So basically ive been hoping it would be possible to effectively turn your sprite while moving it around with W A S D . Any ideas because im certainly stumped, thanks! 回答1: See How do I rotate an image around its center using PyGame? for rotating a surface. If you want to rotate an image around a center point ( cx , cy ) you can just do that: rotated_car = pygame.transform.rotate(car, angle) window.blit(rotated_car, rotated_car.get_rect(center = (cx, cy)) Use pygame.math.Vector2 to store the

How to turn the sprite in pygame while moving with the keys

放肆的年华 提交于 2020-12-23 12:14:51
问题 So basically ive been hoping it would be possible to effectively turn your sprite while moving it around with W A S D . Any ideas because im certainly stumped, thanks! 回答1: See How do I rotate an image around its center using PyGame? for rotating a surface. If you want to rotate an image around a center point ( cx , cy ) you can just do that: rotated_car = pygame.transform.rotate(car, angle) window.blit(rotated_car, rotated_car.get_rect(center = (cx, cy)) Use pygame.math.Vector2 to store the

Changing colour of a surface without overwriting transparency [duplicate]

百般思念 提交于 2020-11-25 03:45:18
问题 This question already has answers here : Is it possible to change sprite colours in Pygame? (1 answer) Trying to make sections of sprite change colour, but whole sprite changes instead (1 answer) Closed 17 days ago . I want to change the colour of a rect dynamically during runtime. Currently set_colour is filling all of the pixels of the surface with a single colour value. This works, but an issue arises when a method like set_outline is called, which modifies the transparency of the surface.

Changing colour of a surface without overwriting transparency [duplicate]

牧云@^-^@ 提交于 2020-11-25 03:43:49
问题 This question already has answers here : Is it possible to change sprite colours in Pygame? (1 answer) Trying to make sections of sprite change colour, but whole sprite changes instead (1 answer) Closed 17 days ago . I want to change the colour of a rect dynamically during runtime. Currently set_colour is filling all of the pixels of the surface with a single colour value. This works, but an issue arises when a method like set_outline is called, which modifies the transparency of the surface.