The above recommended site is for SDL 1.x only for now. First question is: Which SDL2 headers are you using? Since there are several "under offer" it's hard to help because they differ in some things. I use the headers from github here: https://github.com/ev1313/Pascal-SDL-2-Headers
I saw a difference in how I use events, I don't use pSDL_event but TSDL_Event. My function getkey which returns the SDL_SCANCODE of a pressed key looks like this:
Code:
Function GetKey : integer;
var ch: integer;
event:TSDL_event;
Begin
while (SDL_PollEvent( @event ) <> 0) do
begin
if (event.type_ = SDL_QUITEV) then
begin
SDL_Quit();
halt;
end;
if (event.key.type_ = SDL_KEYDOWN) then
begin
ch := Event.key.keysym.scancode;
//key := char (ch);
result := ch;
end;
end;
end ;
And another thing was pointed out correctly by SilverWarrior: you don't need to use pointers with rects. Maybe my procedure drawsprite can help you:
Code:
procedure drawsprite (sprite:PSDL_Texture; x,y:integer;width,height,angle:real;vflip,hflip:boolean);
var dest:PSDL_Rect;
flip:TSDL_RendererFlip;
w,h:integer;
begin
SDL_QueryTexture(sprite, nil, nil, @w, @h);
new (dest);
dest.x:=x;
dest.y:=y;
dest.w:=round(w*width);
dest.h:=round(h*height);
if vflip then begin
flip:=SDL_FLIP_VERTICAL;
SDL_RenderCopyEx(SDL_GetRenderer (SDL_GetWindowFromID(activewindow)), sprite, nil, dest,angle, nil, PSDL_RendererFlip(flip));
end else
if hflip then begin
flip:=SDL_FLIP_HORIZONTAL;
SDL_RenderCopyEx(SDL_GetRenderer (SDL_GetWindowFromID(activewindow)), sprite, nil, dest,angle, nil, PSDL_RendererFlip(flip));
end else begin
SDL_RenderCopyEx(SDL_GetRenderer (SDL_GetWindowFromID(activewindow)), sprite, nil, dest,angle, nil, nil);
dispose (dest);
end;
end;
My engine can use several windows and renderers so don't be frightened by the construct SDL_GetRenderer (SDL_GetWindowFromID(activewindow)) - just place your renderer here.
Bookmarks