Giter Site home page Giter Site logo

px.sdl's Introduction

px.sdl

px.sdl.pas is a single Delphi unit to help with a quick start of Delphi+SDL 2.0 projects. Once it's up you keep full control, but with some help if needed and shouldn't be too late to see if it works or not, so this is the minimal example program:

program minimal;
{$APPTYPE CONSOLE}
uses
  px.sdl;
begin
  sdl.start;
end.

Animated gif minimal demo

With sdl.start we have a default SDL app with: A window, renderer, default loop, update, FPS calc, and animated bouncing box.

The basic texture loading and animated sprite

program simpleDraw;
{$APPTYPE CONSOLE}
uses
  px.sdl, sdl2;
var
    angle :single;
    img :PSDL_Texture;
    spriteRect :TSDL_Rect;

procedure GameInit; //your game init/loading textures
begin
  angle := 0;
  img := sdl.loadTexture('isabella.png', spriteRect.w, spriteRect.h);
end;

procedure GameUpdate; //game logic update
begin
  angle := angle + 0.06;
  spriteRect.x:=round( 200 + sin(angle)*80);
  spriteRect.y:=round( 120 + cos(angle)*80);
end;

procedure GameDraw; //game draw sprites
begin
  SDL_RenderClear(sdl.rend);  //do your own direct SDL function calls
  SDL_RenderCopy(sdl.rend, img, nil, @spriteRect);
  SDL_Delay(15);
end;

begin
  sdl.cfg.window.w := 480; //config Window size
  sdl.cfg.window.h := 320;
  sdl.onLoad := gameInit;  //callbacks events
  sdl.onDraw := gameDraw;
  sdl.onUpdate := gameUpdate;
  sdl.start;               //start game
end.

Animated gif minimal demo

Replacing the default behavoir we get our own simple animated sprite app.

prerequisits

On Windows the DLLs that should go next to your .EXE looks like this:

SDL2.dll
SDL2_image.dll
SDL2_ttf.dll
zlib1.dll
libfreetype-6.dll
libpng16-16.dll

tested on:

  • Delphi XE3 - Windows 7

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.