intro.bbdoc 5.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. The Max2D module provides a set of commands for drawing 2D graphics.<br>
  2. <br>
  3. Before using any of the Max2D commands, you must first create a Max2D graphics
  4. object. The easiest way to do this is using the #Graphics command.<br>
  5. <br>
  6. By default, Max2D is double buffered which means you will have to use
  7. #Flip once you have finished drawing each frame of graphics.<br>
  8. <br>
  9. <h2>Drawing</h2>
  10. Max2D provides support for the following drawing commands:<br>
  11. <br>
  12. <table>
  13. <tr><th>Drawing command</th><th>Action</th></tr>
  14. <tr><td><a href=#Cls class=token>Cls</a></td><td>Clears the viewport</td></tr>
  15. <tr><td><a href=#Plot class=token>Plot</a></td><td>Draws a single pixel</td></tr>
  16. <tr><td><a href=#DrawLine class=token>DrawLine</a></td><td>Draws a line</td></tr>
  17. <tr><td><a href=#DrawRect class=token>DrawRect</a></td><td>Draws a rectangle</td></tr>
  18. <tr><td><a href=#DrawOval class=token>DrawOval</a></td><td>Draws an oval</td></tr>
  19. <tr><td><a href=#DrawPoly class=token>DrawPoly</a></td><td>Draws a polygon</td></tr>
  20. <tr><td><a href=#DrawText class=token>DrawText</a></td><td>Draws some text</td></tr>
  21. <tr><td><a href=#DrawImage class=token>DrawImage</a></td><td>Draws an image</td></tr>
  22. <tr><td><a href=#DrawPixmap class=token>DrawPixmap</a></td><td>Draws a pixmap</td></tr>
  23. </table>
  24. <br>
  25. <h2>Viewport, origin and handle</h2>
  26. Drawing commands are clipped to a rectangular area known as the <i>viewport</i>. Only the area within the viewport is ever modified, and attempting to draw outside the viewport will result in the drawing command being clipped or <i>chopped</i> to the viewport. To set the viewport, use the <a href=#SetViewport class=token>SetViewport</a> command.<br>
  27. <br>
  28. Drawing commands are also offset by the current <i>origin</i> and <i>handle</i>. To set these properties, use the <a href=#SetOrigin class=token>SetOrigin</a> and <a href=#SetHandle class=token>SetHandle</a> commands.<br>
  29. <br>
  30. The current handle is an x,y coordinate subtracted from all drawing x,y coordinates <i>before</i> any rotation or scaling occurs. This allows you to provide a local 'center' for drawing. On the other hand, the current origin is an x,y coordinate added to all drawing x,y coordinates <i>after</i> any rotation or scaling.<br>
  31. <br>
  32. <h2>Color, alpha and blend mode</h2>
  33. Drawing commands are affected by the current color, alpha and blend mode. You can set these properties by using the <a href=#SetColor class=token>SetColor</a>, <a href=#SetAlpha class=token>SetAlpha</a> and <a href=#SetBlend class=token>SetBlend</a> commands.<br>
  34. <br>
  35. The current alpha value controls the transparency level when using the ALPHABLEND blend mode.<br>
  36. <br>
  37. The current blend mode controls how pixels are combined with existing pixels in the back buffer and can be one of the following:<br>
  38. <br>
  39. <table>
  40. <tr><th>Blend mode</th><th>Effect</th></tr>
  41. <tr><td>SOLIDBLEND</td><td>Pixels overwrite existing backbuffer pixels</td></tr>
  42. <tr><td>MASKBLEND</td><td>Pixels are drawn only if their alpha component is greater than .5</td></tr>
  43. <tr><td>ALPHABLEND</td><td>Pixels are alpha blended with existing backbuffer pixels</td></tr>
  44. <tr><td>LIGHTBLEND</td><td>Pixel colors are added to backbuffer pixel colors, giving a 'lighting' effect</td></tr>
  45. <tr><td>SHADEBLEND</td><td>Pixel colors are multiplied with backbuffer pixel colors, giving a 'shading' effect</td></tr>
  46. </table>
  47. <br>
  48. <h2>Rotation and scale</h2>
  49. Drawing commands can be scaled and rotated using the <a href=#SetScale class=token>SetScale</a> and <a href=#SetRotation class=token>SetRotation</a> commands. Rotation and scaling occur relative to the current handle.<br>
  50. <br>
  51. <h2>Images</h2>
  52. Images are pre-rendered chunks of graphics that can be efficiently drawn using a single <a href=#DrawImage class=token>DrawImage</a> command. Images are typically stored in png, bmp or jpg format, and can be loaded using the <a href=#LoadImage class=token>LoadImage</a> command.<br>
  53. <br>
  54. Image drawing is also affected by color, alpha, blend, rotation and scale. The current color is multiplied with each pixel color before the image is drawn to the backbuffer, allowing you to <i>tint</i> images. To disable this effect, you should set the current color to white.<br>
  55. <br>
  56. Images can also have a mask color. This is the color that represents transparency when an image is drawn using the MASKBLEND blend mode. To set the mask color, use the <a href=#SetMaskColor class=token>SetMaskColor</a> command.<br>
  57. <br>
  58. Images can be created by snapshotting regions of the back buffer using the <a href=#GrabImage class=token>GrabImage</a> command.
  59. <h2>Pixmaps</h2>
  60. Pixmaps are used to manipulate images at a pixel level, see the #pixmaps module for details.<p>
  61. <a href=#LockImage class=token>LockImage</a> allows for direct Image pixel access and requires a corresponding call to
  62. <a href=#UnlockImage class=token>UnlockImage</a> when you have have finished reading or modifying the pixels.
  63. The <a href=#DrawPixmap class=token>DrawPixmap</a> and <a href=#GrabPixmap class=token>GrabPixmap</a>
  64. commands allow you to move pixels to and from the current graphic display's backbuffer.
  65. <h2>Collisions</h2>
  66. Max2D features a multilayered pixel perfect collision system.
  67. The <a href=#CollideRect class=token>CollideRect</a> and
  68. <a href=#CollideImage class=token>CollideImage</a> commands
  69. provide a dual function allowing the drawing and hit testing of Rects and
  70. Images with any combination of 32 collision layers.<p>
  71. The current Scale, Rotation, Origin and Handle settings are taken into account
  72. so coordinates for the collision commands acurately match their drawing counterparts
  73. <a href=#DrawRect class=token>DrawRect</a> and <a href=#DrawImage class=token>DrawImage</a>.<p>
  74. <a href=#ResetCollisions class=token>ResetCollisions</a> is used
  75. to clear any or all of the 32 collision layers provided.<br>
  76. <br>