:파이썬에서 등각 투영 타일 기반의 세계를 렌더링하는 방법은 무엇입니까?
이'''
Map Rendering Demo
rendermap.py
By James Walker (trading as Ilmiont Software).
Copyright (C)Ilmiont Software 2013. All rights reserved.
This is a simple program demonstrating rendering a 2D map in Python with Pygame from a list of map data.
Support for isometric or flat view is included.
'''
import pygame
from pygame.locals import *
pygame.init()
DISPLAYSURF = pygame.display.set_mode((640, 480), DOUBLEBUF) #set the display mode, window title and FPS clock
pygame.display.set_caption('Map Rendering Demo')
FPSCLOCK = pygame.time.Clock()
map_data = [
[1, 1, 1, 1, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 0, 0, 0, 1],
[1, 1, 1, 1, 1]
] #the data for the map expressed as [row[tile]].
wall = pygame.image.load('wall.png').convert() #load images
grass = pygame.image.load('grass.png').convert()
tileWidth = 64 #holds the tile width and height
tileHeight = 64
currentRow = 0 #holds the current map row we are working on (y)
currentTile = 0 #holds the current tile we are working on (x)
for row in map_data: #for every row of the map...
for tile in row:
tileImage = wall
cartx = currentTile * 64 #x is the index of the currentTile * the tile width
print(cartx)
carty = currentRow * 64 #y is the index of the currentRow * the tile height
print(carty)
x = cartx - carty
print(x)
y = (cartx + carty)/2
print(y)
print('\n\n')
currentTile += 1 #increase the currentTile holder so we know that we are starting rendering a new tile in a moment
DISPLAYSURF.blit(tileImage, (x, y)) #display the actual tile
currentTile = 0 #reset the current working tile to 0 (we're starting a new row remember so we need to render the first tile of that row at index 0)
currentRow += 1 #increment the current working row so we know we're starting a new row (used for calculating the y coord for the tile)
while True:
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit()
sys.exit()
if event.type == KEYUP:
if event.key == K_ESCAPE:
pygame.quit()
sys.exit()
pygame.display.flip()
FPSCLOCK.tick(30)
사용되는 타일 크기는 64 × 64이다; 위의 코드를 실행하면 다음과 같은 출력이 생성됩니다. 타일은 모두 투명 에지가 있으며이 예제에서는 'wall'타일 만 사용되지만 타일이 너무 멀리 떨어져 있으므로 분명히 잘못된 것이 있습니다.
온라인 튜토리얼을 읽으려고 시도했지만 실제로 파이썬으로 작성된 튜토리얼을 찾을 수 없으므로 어디서 잘못되었는지 조언 해주십시오. 사전에
감사합니다, Ilmiont
잘 작동하지만 지금은이 결과를 얻습니다. http://i.stack.imgur.com/XJgBC.png 따라서 검은 색 삼각형 (부분적으로)이 남아 있습니다. – Ilmiont
검은 색 부분이 투명합니까? – Matthias
map.png를 첨부 파일에 게시 할 수 있습니까? 또한 시도해 볼 수 있습니다 : wall = pygame.image.load ('wall.png'). convert_alpha() –