Prikaz jedne poruke
Stara 15.1.2006, 18:53   #3
Andross
Kekule Mekule
 
Avatar korisnika Andross
 
Član od: 8.12.2005.
Lokacija: Beograd
Poruke: 4.132
Zahvalnice: 649
Zahvaljeno 1.351 puta na 692 poruka
Slanje poruke preko Skypea korisniku Andross
Određen forumom Re: Pygame game dev.

Evo od mene neka vrsta tutorijala(koju sam nasao na netu)O sprajtovima:

import pygame

class Box(pygame.sprite.Sprite):
def __init__(self, color, initial_position):

# All sprite classes should extend pygame.sprite.Sprite. This
# gives you several important internal methods that you probably
# don't need or want to write yourself. Even if you do rewrite
# the internal methods, you should extend Sprite, so things like
# isinstance(obj, pygame.sprite.Sprite) return true on it.
pygame.sprite.Sprite.__init__(self)

# Create the image that will be displayed and fill it with the
# right color.
self.image = pygame.Surface([15, 15])
self.image.fill(color)

# Make our top-left corner the passed-in location.
self.rect = self.image.get_rect()
self.rect.topleft = initial_position

Snimite rad kao kocke.Da bi je prikazali uzmite novi window i pisite:

import pygame
from pygame.locals import *
from kocke import Box

pygame.init()
screen = pygame.display.set_mode([150, 150])
b = Box([255, 0, 0], [0, 0]) # Make the box red in the top left
screen.blit(b.image, b.rect)
pygame.display.update()
while pygame.event.poll().type != KEYDOWN: pygame.time.delay(10)

Snimite rad kao prikazikocku.Ovo omogucuje prikaz jedne kocke.Za prikaz tri kocke otvorite novi prozor i upisite:

import pygame
from pygame.locals import *
from kocke import Box

pygame.init()
boxes = []
for color, location in [([255, 0, 0], [0, 0]),
([0, 255, 0], [0, 60]),
([0, 0, 255], [0, 120])]:
boxes.append(Box(color, location))

screen = pygame.display.set_mode([150, 150])
for b in boxes: screen.blit(b.image, b.rect)
pygame.display.update()
while pygame.event.poll().type != KEYDOWN: pygame.time.delay(10)

rectlist = [screen.blit(b.image, b.rect) for b in boxes]
pygame.display.update(rectlist)

Snimite rad kao prikazikocke.
Andross je offline   Odgovor sa citatom ove poruke