CapsAdmin

Untitled

Dec 1st, 2012
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.31 KB | None | 0 0
  1. local mode = ffi.new("sfVideoMode")
  2. mode.width = 800
  3. mode.height = 600
  4. mode.bitsPerPixel = 32
  5.  
  6. -- Create the main window
  7. local window = RenderWindow(mode, "SFML window", bit.bor(sfml.libraries.window.sfResize, sfml.libraries.window.sfClose), ffi.new("sfContextSettings"))
  8.  
  9. -- Load a sprite to display
  10. local rect = ffi.new("sfIntRect", 0, 0, 100, 100)
  11.  
  12. local texture = Texture("file", "../textures/cute_image.jpg", rect)
  13. local sprite = Sprite()
  14. sprite:SetTexture(texture, 1)
  15.  
  16. -- Create a graphical text to display
  17. local font = Font("file", "../fonts/arial.ttf")
  18. local text = Text()
  19. text:SetString("Hello SFML")
  20. text:SetFont(font)
  21. text:SetCharacterSize(50)
  22.  
  23. -- Load a music to play
  24. local music = Music("file", "../sound/nice_music.ogg")
  25.  
  26. -- Play the music
  27. music:Play()
  28.  
  29. local event = ffi.new("sfEvent")
  30.  
  31. -- Start the game loop
  32. hook.Add("OnUpdate", "test", function()
  33.     if window:IsOpen() then
  34.     -- Process events
  35.         if window:PollEvent(event) then
  36.             -- Close window : exit
  37.             if event.type == sfml.libraries.window.sfEvtClosed then
  38.                 window:Close()
  39.             end
  40.         end
  41.  
  42.         -- Clear the screen
  43.         window:Clear(sfml.libraries.graphics.sfBlack)
  44.  
  45.         -- Draw the sprite
  46.         window:DrawSprite(sprite, nil)
  47.  
  48.         -- Draw the text
  49.         window:DrawText(text, nil)
  50.  
  51.         -- Update the window
  52.         window:Display()
  53.     end
  54. end)
Advertisement
Add Comment
Please, Sign In to add comment