Also we have a new variable of TSDL_Rect type. In the var clause we declare the known variables for window, renderer and a texture. A part of the full image is stretched in the background while the full image is also squeezed into an area above the word “Free”.įor comparison, here is the original 200×200 px image. The result of the example program (500×500 px window). This image by is licensed under a Creative Commons Attribution 4.0 International License. SDL_RenderCopy(sdlRenderer, sdlTexture1, nil, render to window for 2 seconds SDL_RenderCopy(sdlRenderer, sdlTexture1, nil) SdlTexture1 := SDL_CreateTextureFromSurface(sdlRenderer, sdlSurface1) SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, 'nearest') You will be impressed how simple it actually is. The following code demonstrates the basic principle how to achieve the impression of movement of images (sprites) and how scaling works. Using Rectangles for Movement and Scaling If you use PSDL_Rect, you free the required memory by Pascal’s new procedure as you would for any simple record pointer. The next step is to define the rectangle by assign some values for x, y, w and h. a texture, window,… The variable w is the width and h the height of the rectangle. The variables x and y correspond to the x/y coordinates of the left upper corner of the rectangle, related to the origin 0/0 which is the left upper corner of, e.g. Simply, this record describes a rectangle, hence the name. This is the pointer counterpart to TSDL_Rect. Often functions require an argument of PSDL_Rect type. Rectangles: TSDL_Rect and PSDL_Rect in SDL 2.0 Screens and Images are rectangular, so this shape has a special importance to SDL2 and graphics programming in particular. A list of all the scancodes shows all possible scancodes. A detailed description of scancodes in the next chapter. The scancode represents the position of the related key state in the array. exit the program loop or change the x/y coordinates of the rectangle. SDL_SCANCODE_ESCAPE for the escape key) and react as desired, e.g. We now can check for the of any key in the array by sdlKeyboardState using its These actions have to performed on every cycle. After that we can grab the keyboard state by the former mentioned function SDL_GetKeyboardState. ![]() Here we need to update the event queue by procedure SDL_PumpEvents. program loopĪfter setting up a SDL2 window and and preparing a SDL2 rectangle, the program loop is entered. To get the keyboard state, we define a unsigned 8 bit pointer variable sdlKeyboardState in the var clause. SDL_RenderDrawRect(sdlRenderer, clear memory SDL_SetRenderDrawColor(sdlRenderer, 255, 0, 0, SDL_ALPHA_OPAQUE) SDL_SetRenderDrawColor(sdlRenderer, 0, 0, 0, SDL_ALPHA_OPAQUE) SdlKeyboardState := SDL_GetKeyboardState(nil) Therefore we read out their key states on every cycle of the program loop. The following code example will draw a red rectangle which can be moved by the WASD keys. The red rectangle can be moved by the WASD keys by reading out their key states.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |