2012-01-07 4 views
1

私がしたいのは、(brick_tile)と呼ばれるタイル画像で覆われている(0,390)、(0,450)、(610,390)、(610,450)です。これまでのところ私が持っているすべてはこれです:ループであなただけのブリットする必要がレンガとタイル、ブリット、ブリットへどのようにして、python/pygameでタイル(画像)の領域をカバーしますか?

import pygame 
from pygame.locals import* 

cloud_background = pygame.image.load('clouds.bmp') 
brick_tile = pygame.image.load('brick_tile.png') 

pink = (255, 64, 64) 
w = 640 
h = 480 
screen = pygame.display.set_mode((w, h)) 
running = 1 

while running: 
    screen.fill((pink)) 
    screen.blit(cloud_background,(0,0)) 
    screen.blit(brick_tile,(0,450)) 
    pygame.display.flip() 

    event = pygame.event.poll() 
    if event.type == pygame.QUIT: sys.exit() 

答えて

2

:私は追加

import pygame 
import sys 
import itertools 

cloud_background = pygame.image.load('clouds.bmp') 
brick_tile = pygame.image.load('brick_tile.png') 

pink = (255, 64, 64) 
w = 640 
h = 480 
screen = pygame.display.set_mode((w, h)) 
running = 1 

def setup_background(): 
    screen.fill((pink)) 
    screen.blit(cloud_background,(0,0)) 
    brick_width, brick_height = brick_tile.get_width(), brick_tile.get_height() 
    for x,y in itertools.product(range(0,610+1,brick_width), 
           range(390,450+1,brick_height)): 
     # print(x,y) 
     screen.blit(brick_tile, (x, y)) 
    pygame.display.flip() 

while running: 
    setup_background()  
    event = pygame.event.poll() 
    if event.type == pygame.QUIT: sys.exit() 
+0

OKそのプログラムの終わりまで。レンガは動作しません – enrique2334

+0

'setup_background()'関数を呼び出す必要があります。私が意味することを示すコードを編集しました。 – unutbu

+0

'トレースバック(最新の呼び出しの最後): ファイル "C:\ユーザーはエンリケ\ Dropboxの\ GAMEZ_PYGAMEの\ gamez.py \":名 'setup_background' – enrique2334

関連する問題