ok so im using pygame jto create a simple 2d game and i have a sprite (little triangle for now) that is always in the center and only movement it does is rotate.
here is the code:
Code:
Code:import pygame from pygame.locals import* from sys import exit pygame.init() windowSize = 1024,768 frameRate = 50 # initializing the game window gameWindow = pygame.display.set_mode((windowSize)) #, FULLSCREEN ) pygame.display.set_caption('STARBOUND') screen = pygame.display.get_surface() #loading textures # ship sprites podTex = 'shipPlaceholder.png' podSprite = pygame.image.load(podTex).convert_alpha() clock = pygame.time.Clock() class ship: def __init__(self): self.shipName = "pod" self.xPos = 0 self.yPos = 0 self.position = (self.xPos, self.yPos) self.width = 120 self.height = 120 self.hull = 100 self.hullMax = 1000 self.energy = 1000 self.energyMax = 1000 self.engineSpeed = 5 self.turningSpeed = 5 self.thrustingSpeed = 0 self.thrustingSpeedMax = 10 self.primaryWeapon = 1 self.secondaryWeapon = 0 self.secondaryWeaponMax = 0 self.angle = 0 self.isComp = True; self.shipTexture = podSprite; def turn(self, amount): self.angle += amount self.shipTexture = pygame.transform.rotate(self.shipTexture, self.angle) def draw(self): screen.blit(self.shipTexture, (self.position)) playerShip = ship() playerShip.xPos = windowSize[0] / 2 - 60 playerShip.yPos = windowSize[1] / 2 - 60 playerShip.position = (playerShip.xPos, playerShip.yPos); playerShip.turningSpeed = 90 playerShip.isComp = False while True: # Limit frame speed to 50 FPS # time_passed = clock.tick(frameRate) ship.turn(playerShip, playerShip.turningSpeed) ship.draw(playerShip) pygame.display.flip()
now.. i want the sprite so slowly spim at a speed of 90 degrees per second (playerShip.turningSpeed)
so it spins... but instead of it being centered... it spins out of the window:
dreamincode.net/forums/index.php?act=Attach&type=post&id=12345
How can i get it so that it stays in the middle instead of spiraling out of the window?
xZachtmx is offline Reply With Quote
I'm running your code on my machine and I can't seem to reproduce your problem. The ship is stationary and only rotating.
Your speed of rotation is off though. It's rotating at much more than 90 degrees per second. You are incrementing your angle by 90 each frame.
EDIT: I've discovered that the bug can be reproduced with turningSpeed is not a multiple of 90 degrees. I'll take a look at the code more closely this afternoon and try to find the problem.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks