2015-06-21 53 views
0

我在第一個表面上繪製了一些精靈在幾個位置,我想製作第二個表面,並添加一些其他從透明度的PNG圖像的精靈。問題是我無法正確創建第二個表面和廣告Blit表面。PySDL2製作多個表面

下面是一些代碼它的外觀:

'Library init' 
SDL_Init(SDL_INIT_EVERYTHING) 

'Creating window' 
window = SDL_CreateWindow(b"Game",SDL_WINDOWPOS_CENTERED,SDL_WINDOWPOS_CENTERED,screen_width,screen_height,SDL_WINDOW_SHOWN) 

'Adding resources' 
sprite_names = os.listdir(os.path.join(os.path.dirname(os.path.abspath(__file__)),"res")) 

'Sprite loading' 
for sprite in sprite_names: 
    sprite_list.append(IMG_Load(os.path.join(os.path.dirname(os.path.abspath(__file__)),"res", sprite).encode("utf-8"))) 
    print(sprite) 

'Creating window surface' 
window_surface = SDL_GetWindowSurface(window) 
'I am trying to create surface in that way' 
second_surface = SDL_CreateSurface() 
'PNG file with background' 
SDL_BlitSurface(sprite_list[0],None,window_surface,SDL_Rect(0,0)) 
'Second surface with object with transparency, i dont know how define second surface in PySDL to make it work' 
SDL_Blitsurface(sprite_list[1],None,second_surface,SDL_Rect(100,100)) 
SDL_Blitsurface(second_surface,None,window_surface,None) 

SDL_UpdateWindowSurface(window) 

我想我需要做類似的東西有在屏幕上我的意思是它會把我的第一個背景圖層,然後用鼠標右鍵就可以了對象?當我試圖在相同的位置繪製兩個對象時,我會閃爍,或者我獲得了對象的背景。任何想法如何讓它工作?

回答

0

我發現了一種方法,以限定第二表面:

second_surface = SDL_CreateRGBSurface(SDL_SWSURFACE,screen_width,screen_height,32, 0x000000FF, 0x0000FF00, 0x00FF0000, 0xFF000000) 

它是透明的表面,現在下一個問題,我發現,在使透明性較暗每個刷新,因爲它被繪製多次同一表面我使用的代碼,並將其曾工作:

SDL_FillRect(second_surface, None, 0x000000)