LuaDrawing.wiki
changeset 258 9c815950568d
parent 257 3d03892b7545
child 259 903c90df0e5d
equal deleted inserted replaced
257:3d03892b7545 258:9c815950568d
     8 = Details =
     8 = Details =
     9 
     9 
    10 First, a couple of convenience functions for drawing to the map.
    10 First, a couple of convenience functions for drawing to the map.
    11 <code lang="lua">
    11 <code lang="lua">
    12 PointsBuffer = ''  -- A string to accumulate points in
    12 PointsBuffer = ''  -- A string to accumulate points in
    13 function AddPoint(x, y, size, erase)
    13 function AddPoint(x, y, width, erase)
    14     PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
    14     PointsBuffer = PointsBuffer .. string.char(band(x,0xff00) / 256 , band(x,0xff) , band(y,0xff00) / 256 , band(y,0xff))
    15     if size then
    15     if size then
    16         size = bor(size,0x80)
    16         size = bor(size,0x80)
    17         if erase then
    17         if erase then
    18             size = bor(size,0x40)
    18             size = bor(size,0x40)
    31         ParseCommand('draw '..PointsBuffer)
    31         ParseCommand('draw '..PointsBuffer)
    32         PointsBuffer = ''
    32         PointsBuffer = ''
    33     end
    33     end
    34 end
    34 end
    35 </code>
    35 </code>
    36 AddPoint takes an x and y location for the point, a size (required to start a line) and erase (whether the line is erasing from the map).  The size is the "width" value from [[DrawnMapFormat]].
    36 AddPoint takes an x and y location for the point, a width (indicates the start of a new line) and erase (whether the line is erasing from the map).  The width calculation is described in [DrawnMapFormat].
    37 
    37 
    38 FlushPoints writes out any values from PointsBuffer that have not already been sent to the engine.
    38 FlushPoints writes out any values from PointsBuffer that have not already been sent to the engine.
    39 It would be called at the end of a drawing session.
    39 It would be called at the end of a drawing session.
    40 
    40 
    41 A simple example below.
    41 A simple example below.
    80         AddPoint(4000,i)
    80         AddPoint(4000,i)
    81     end
    81     end
    82     for i = 500,3500,1000 do
    82     for i = 500,3500,1000 do
    83         AddPoint(i,1000,63,true)
    83         AddPoint(i,1000,63,true)
    84     end
    84     end
       
    85     FlushPoints()
    85 </code>
    86 </code>
    86 This one fills the map with solid land, and draws 3 circular erased points in it.
    87 This one fills the map with solid land, and draws 3 circular erased points in it.