vendredi 31 octobre 2014

Screen.blit() Trouble (Pygame)


Vote count:

0




Sorry for the second post in as many days, but I'm having trouble printing anything onto the screen that isn't the spirte labelled 'pokemon'. I import the image using the funtion;



img_snap = pygame.image.load("images/snap.png")


and then attempt to print the image (called "snap.png") with:



screen.blit(img_snap, (200,200))


where 200 and 200 are the x and y co ordinates that the object will be drawn. If anyone is familiar with pygame please lend your knowledge :)


thanks in advance


MAIN CODE:



import pygame,sys
from classes import *
from process import process

pygame.init()
WIDTH,HEIGHT = 640, 360
screen = pygame.display.set_mode((WIDTH,HEIGHT),0,32)
img_pokemon = pygame.image.load("images/pokemon.png")
img_screen = pygame.image.load("images/screen.png")
img_snap = pygame.image.load("images/snap.png")
#clock
clock = pygame.time.Clock()
FPS = 24
fivesecondinterval = FPS * 5
totalframes = 0
#pokemon object
pokemon = Pokemon(0, HEIGHT -80, 48, 76, "images/pokemon.png")

#-------------------------MAIN PROGRAM LOOP----------------------------
while True:
process(pokemon)
#LogicStart
Pokemon.motion(pokemon)
#LogicEnd
#DrawStart
screen.fill( (0,0,0) )
BaseClass.allsprites.draw(screen)
screen.blit(img_snap, (640,360))
pygame.display.flip()
#DrawEnd

clock.tick(FPS)


CLASSES CODE:



import pygame

class BaseClass(pygame.sprite.Sprite):

allsprites = pygame.sprite.Group()
def __init__(self, x, y, width, height, image_string):

pygame.sprite.Sprite.__init__(self)
BaseClass.allsprites.add(self)

self.image = pygame.image.load(image_string)
self.rect = self.image.get_rect()
self.rect.x = x
self.rect.y = y

self.width = width
self.height = height



class Pokemon(BaseClass):
List = pygame.sprite.Group()
def __init__(self, x, y, width, height, image_string):

BaseClass.__init__(self, x, y, width, height, image_string)
Pokemon.List.add(self)
self.velx = 0

def motion(self):
self.rect.x += self.velx


PROCESSES CODE:



import pygame,sys
def process(pokemon):

#processes
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()

keys = pygame.key.get_pressed()

if keys[pygame.K_d]:
pokemon.image = pygame.image.load("images/pokemon.png")
pokemon.velx = 5
elif keys[pygame.K_a]:
pokemon.image = pygame.image.load("images/pokemonflipped.png")
pokemon.velx = -5
else:
pokemon.velx = 0


asked 21 secs ago







Screen.blit() Trouble (Pygame)

Aucun commentaire:

Enregistrer un commentaire