开发者

pygame - pixel collision map

I'm creating a game with pygame and I need a m开发者_如何学JAVAap where the user can select a country by clicking on it.

Can someone help me?


Unless you find that done, I see no easy way of doing that -- You have to start by having a World map, of course -- this one in Wikipedia seems a nice starting point: http://upload.wikimedia.org/wikipedia/commons/0/03/BlankMap-World6.svg

--Ah, I see by your comments you have the map drawn -- Yes.if all you need is to get the color for a click, that is easier - Pick the click coordinates with the mouse event for the click:

e = pygame.event.poll()
if e == pygame.MOUSEBUTTONDOWN:
    pos = e.pos
    # where "screen" is your variable holding the screen surface color = screen.get_at((pos))


If every country has another color and you know it, you could detect it with:

import pygame
pygame.init()
screen = pygame.display.set_mode([100,100])
print(screen.get_at([50,50]))#returns tuple with color values
pygame.quit()

I hope this helps to solve your problem

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜