def showStartScreen(): title1 = SPRITE_FACTORY.from_text("Wormy!", size=100, bg_color=DARKGREEN) title2 = SPRITE_FACTORY.from_text("Wormy!", size=100, color=GREEN) #titleSurf1 = titleFont.render('Wormy!', True, WHITE, DARKGREEN) #titleSurf2 = titleFont.render('Wormy!', True, GREEN) pressKey = SPRITE_FACTORY.from_text("Press a key to play.", color=DARKGRAY) pressKey.position = WINDOWWIDTH - 200, WINDOWHEIGHT - 30 degrees1 = 0 degrees2 = 0 win_surf = WINDOW.get_surface() while True: REN.clear(BGCOLOR) #fill? rot_title1p = sdlgfx.rotozoomSurface(title1.surface, degrees1, 1, sdlgfx.SMOOTHING_ON) rot_title2p = sdlgfx.rotozoomSurface(title2.surface, degrees2, 1, sdlgfx.SMOOTHING_ON) rot1 = rot_title1p.contents rot2 = rot_title2p.contents rect1 = sdl2.rect.SDL_Rect(WINDOWWIDTH//2 - rot1.w//2, WINDOWHEIGHT//2 - rot1.h//2, 0, 0) rect2 = sdl2.rect.SDL_Rect(WINDOWWIDTH//2 - rot2.w//2, WINDOWHEIGHT//2 - rot2.h//2, 0, 0) sdl2.SDL_BlitSurface(rot1, None, win_surf, rect1) sdl2.SDL_BlitSurface(rot2, None, win_surf, rect2) if check_for_key_press(): return SPRITE_RENDERER.render(pressKey) REN.present() sdl2.SDL_Delay(1000//FPS) degrees1 += 3 # rotate by 3 degrees each frame degrees2 += 7 # rotate by 7 degrees each frame
def test_surface_sprites(): test1 = sprite_factory.from_text("A text sprite") degrees = 0 while degrees < 360: if get_events([sdl2.SDL_QUIT]): shutdown() keylen = ctypes.c_int(10) print(keylen.value) keyboard_status = sdl2.SDL_GetKeyboardState(ctypes.byref(keylen)) print(type(keyboard_status)) print(keylen.value) if keyboard_status[sdl2.SDL_SCANCODE_D]: print("d is down") ren.clear() #fill? rot = sdlgfx.rotozoomSurface(test1.surface, degrees, 3, sdlgfx.SMOOTHING_ON) #print(type(rot), type(rot.contents)) #<class 'sdl2.surface.LP_SDL_Surface'> <class 'sdl2.surface.SDL_Surface'> #this is lame ... from_surface takes sdl2.surface.SDL_Surface which means calling contents #which creates a copy #Note that ctypes does not have OOR (original object return), it constructs a new, equivalent object each time you retrieve an attribute #so rot.contents creates a new ~52 byte surface rot = sprite_factory.from_surface(rot.contents) rot.position = WIDTH//2 - rot.size[0]//2, HEIGHT//2 -rot.size[1]//2 degrees += 1 sdl2.SDL_Delay(1000//90) sprite_renderer.render(rot) ren.present()
def test_surface_drawing(): win_surf = window.get_surface() test1 = sprite_factory.from_text("A text sprite") degrees = 0 while degrees < 180: ren.clear() #fill? rot = sdlgfx.rotozoomSurface(test1.surface, degrees, 3, sdlgfx.SMOOTHING_ON) #same lame copy necessary as below tmp = rot.contents pos = WIDTH//2 - tmp.w//2, HEIGHT//2 -tmp.h//2 sdl2.SDL_BlitSurface(rot, None, win_surf, sdl2.rect.SDL_Rect(pos[0], pos[1], 0, 0)) degrees += 1 sdl2.SDL_Delay(1000//90) window.refresh() #equ to sdl2.SDL_UpdateWindowSurface(window.window) ...?