School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 300,439 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,490 people online right now. Registration is fast and FREE... Join Now!




[pygame] Why is my sprite spiralling out of the window area?

 

[pygame] Why is my sprite spiralling out of the window area?

xZachtmx

14 Jun, 2009 - 08:24 AM
Post #1

New D.I.C Head
*

Joined: 14 Jun, 2009
Posts: 38



Thanked: 1 times
My Contributions
Ok im using pygame to make a simple 2d game and i tried to make a rotation script:
here is all my code so far:
CODE

import pygame
from pygame.locals import*
pygame.init()


windowSize = 1024,768

    # 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.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.isComp = False

while True:
    # Limit frame speed to 50 FPS
    #
    time_passed = clock.tick(50)
    


    keyBState = pygame.event.get()
    


    
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            exit()
    ship.turn(playerShip, 5)
      
    ship.draw(playerShip)    
            
    pygame.display.flip()


so my little ship was supposed to rotate in the same stop endlessly... but instead it rolled out of the view... its position wasnt supposed to change... only the direction it is facing... if you would like to see what happened check the attached image.

i think a partial reason for this happening was because the sprite's rotational point was in the top left corner and not in the center... but i dont think that explains why it kept moving off the screen Attached Image

User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 01:07AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month