Advertisement
Guest User

Untitled

a guest
Aug 24th, 2017
681
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.80 KB | None | 0 0
  1. --All rotations in the drawing API are expressed in radians (-PI,PI)
  2. --To convert degrees to radians multiply the value by (math.pi/180)
  3. --To convert radians to degrees multiply the value by (180/math.pi)
  4. --So to render a sprite rotated 90 degrees you'd write _r.sprite(x, y, width, height, 90 * (math.pi/180))
  5.  
  6. --All textures are stored in the '_t' table.
  7. --All sounds are stored in the '_s' table.
  8. --You can access a texture or sound by the name configured in the .mproject file (_t.mytexture, _s.mysound)
  9.  
  10. --Optional arguments are surrounded by square brackets []
  11.  
  12. --Callbacks
  13.  
  14.     init()                                      --called when the game instance is created
  15.     think(time, dt)                             --called every update tick
  16.                                                 --   time is seconds since the game started,
  17.                                                 --   dt is seconds since last think
  18.  
  19.     draw()                                      --called every frame
  20.     onMousePressed(x, y, button, focused)       --called when a mouse button is pressed
  21.     onMouseReleased(x, y, button, focused)      --called when a mouse button is released
  22.     onMouseMoved(x, y, dx, dy, focused)         --called when the mouse is moved,
  23.                                                 --   (x,y) is the mouse position,
  24.                                                 --   (dx, dy) is how much the mouse has moved
  25.  
  26.     onKeyPressed(keycode)                       --called when a key is pressed
  27.     onKeyReleased(keycode)                      --called when a key is released
  28.     onKeyRepeat(keycode)                        --called when a key is repeated (holding a key down)
  29.     onFocusGained(element)                      --called when the game gains focus
  30.     onFocusLost(element)                        --called when the game loses focus
  31.  
  32.  
  33. --Render Library
  34.  
  35.     --Sets the color for the next render operation, color components are in the range of [0-1], blendmodes are (0 = normal, 1 = additive, 2 = alpha)
  36.     _r.color(red, green, blue, [alpha], [blendmode])
  37.  
  38.     --Draws a rectangle with the upper-left vertex at (x, y), and the lower-right vertex at (x+width, y+height)
  39.     _r.rect(x, y, width, height, [texture], [u0], [v0], [u1], [v1])
  40.  
  41.     --Draws a sprite centered at (x, y) with (width, height) being the size
  42.     _r.sprite(x, y, width, height, [rotation], [texture], [u0], [v0], [u1], [v1])
  43.  
  44.     --Draws a quad using the specified vertices
  45.     _r.quad(x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3)
  46.  
  47.     --Returns the width and height of the viewport
  48.     _r.size()
  49.  
  50.     --Sets the layer to draw elements onto
  51.     _r.layer(layer_index)
  52.  
  53.     --Pushes the current model-matrix onto the stack (causes all subsequent transform operations to be scoped to the 'push'/'pop' pairing)
  54.     _r.push()
  55.  
  56.     --Pops the last model-matrix off of the stack and makes it current
  57.     _r.pop()
  58.  
  59.     --Translate the model-matrix by the vector (x,y)
  60.     _r.translate(x,y)
  61.  
  62.     --Rotate the model-matrix by rotation 'r' in radians
  63.     _r.rotate(r)
  64.  
  65.     --Scales the model-matrix by 'sx' and 'sy'
  66.     _r.scale(sx,sy)
  67.  
  68.  
  69.     --Example showing usage of model-matrix
  70.     --The root matrix is camera movement
  71.     --Sprites are drawn under temporary matrix which provides rotation
  72.     _r.push()
  73.     _r.translate(-camera_x, -camera_y)
  74.         for _, sp in pairs(allSprites) do
  75.             _r.push()                 --push temporary matrix
  76.             _r.translate(sp.x, sp.y)  --translate to sprite position
  77.             _r.rotate(time)           --rotate
  78.             _r.sprite(0,0,100,100)    --draw sprite at 0,0 (which is now at sp.x, sp.y because of the current matrix)
  79.             _r.pop()                  --pop temporary matrix, sets back to camera matrix
  80.         end
  81.     _r.pop()
  82.  
  83.  
  84. --Sound Library
  85.  
  86.     --Plays a sound, returns the channel the sound is played on.
  87.     --specify channelindex to have explicit control over which channel the sound plays on (such as a music channel)
  88.     sound.play(sound, [channelindex])
  89.  
  90.     --Stops a sound that is playing on 'channelindex'
  91.     sound.stop(channelindex)
  92.  
  93.     --Sets the pitch of an audio channel [1 is normal, 2 is double, .5 is half, -1 is reverse, etc.]
  94.     --Returns the channelindex through the function call
  95.     sound.setPitch(channelindex, pitch)
  96.  
  97.     --Sets the volume of an audio channel [0 - 1]
  98.     --Returns the channelindex through the function call
  99.     sound.setVolume(channelindex, volume)
  100.  
  101.     --Set if the playing sound should loop when it's finished
  102.     --Returns the channelindex through the function call
  103.     sound.setLooping(channelindex, looping)
  104.  
  105.     --Set the overall pitch of all playing sounds
  106.     sound.setMasterPitch(pitch)
  107.  
  108.     --Set the overall volume of all playing sounds
  109.     sound.setMasterVolume(volume)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement