Closed Thread
Results 1 to 2 of 2

Thread: [Pygame] how to get my sprite rotations working properly?

  1. #1
    xZachtmx is offline Newbie
    Join Date
    Jun 2009
    Posts
    3
    Rep Power
    0

    Question [Pygame] how to get my sprite rotations working properly?

    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

  2. CODECALL Circuit advertisement
    Join Date
    Always
    Posts
    Many

     
  3. #2
    ShadenSmith's Avatar
    ShadenSmith is offline Newbie
    Join Date
    May 2009
    Location
    Kentucky - USA
    Posts
    19
    Rep Power
    10

    Re: [Pygame] how to get my sprite rotations working properly?

    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.

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Sprite + Map, Only shows Sprite (?)
    By FenixEden in forum Managed C++
    Replies: 0
    Last Post: 11-27-2010, 05:58 AM
  2. Replies: 9
    Last Post: 11-12-2010, 09:55 AM
  3. Why is this program not working properly?
    By camdaddy09 in forum C and C++
    Replies: 1
    Last Post: 10-03-2010, 02:56 PM
  4. Internet is not working properly
    By najaubais in forum Linux Hardware
    Replies: 4
    Last Post: 02-26-2009, 05:09 PM
  5. Replies: 0
    Last Post: 06-29-2008, 10:32 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts