example_01.bmx 966 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. SuperStrict
  2. Framework SDL.SDLRenderMax2D
  3. Import Image.BMP
  4. Local w:Int = DesktopWidth() * .75
  5. Local h:Int = DeskTopHeight() * .75
  6. Graphics w, h, 0
  7. AutoMidHandle(True)
  8. Local img1:TImage = Loader("blackbuck.bmp", w, h)
  9. Local img2:TImage = Loader("bmp_24.bmp", w, h)
  10. If Not img1 Or Not img2 Then
  11. Throw "Failed to load image"
  12. End If
  13. Local image:Int
  14. Local img:TImage = img1
  15. While Not KeyDown(Key_ESCAPE)
  16. Cls
  17. If KeyHit(KEY_SPACE) Then
  18. image = Not image
  19. If image Then
  20. img = img2
  21. Else
  22. img = img1
  23. End If
  24. End If
  25. DrawImage img, w / 2, h / 2
  26. Flip
  27. Wend
  28. Function Loader:TImage(path:String, maxWidth:Int, maxHeight:Int)
  29. Local pix:TPixmap = LoadPixmap( path )
  30. If pix Then
  31. If pix.width > maxWidth Or pix.height > maxHeight Then
  32. Local ratio:Float = Min(maxWidth / Float(pix.width), maxHeight / Float(pix.height))
  33. pix = ResizePixmap(pix, Int(pix.width * ratio), Int(pix.height * ratio))
  34. End If
  35. Return LoadImage(pix)
  36. End If
  37. End Function