Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --All rotations in the drawing API are expressed in radians (-PI,PI)
- --To convert degrees to radians multiply the value by (math.pi/180)
- --To convert radians to degrees multiply the value by (180/math.pi)
- --So to render a sprite rotated 90 degrees you'd write _r.sprite(x, y, width, height, 90 * (math.pi/180))
- --All textures are stored in the '_t' table.
- --All sounds are stored in the '_s' table.
- --You can access a texture or sound by the name configured in the .mproject file (_t.mytexture, _s.mysound)
- --Optional arguments are surrounded by square brackets []
- --Callbacks
- init() --called when the game instance is created
- think(time, dt) --called every update tick
- -- time is seconds since the game started,
- -- dt is seconds since last think
- draw() --called every frame
- onMousePressed(x, y, button, focused) --called when a mouse button is pressed
- onMouseReleased(x, y, button, focused) --called when a mouse button is released
- onMouseMoved(x, y, dx, dy, focused) --called when the mouse is moved,
- -- (x,y) is the mouse position,
- -- (dx, dy) is how much the mouse has moved
- onKeyPressed(keycode) --called when a key is pressed
- onKeyReleased(keycode) --called when a key is released
- onKeyRepeat(keycode) --called when a key is repeated (holding a key down)
- onFocusGained(element) --called when the game gains focus
- onFocusLost(element) --called when the game loses focus
- --Render Library
- --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)
- _r.color(red, green, blue, [alpha], [blendmode])
- --Draws a rectangle with the upper-left vertex at (x, y), and the lower-right vertex at (x+width, y+height)
- _r.rect(x, y, width, height, [texture], [u0], [v0], [u1], [v1])
- --Draws a sprite centered at (x, y) with (width, height) being the size
- _r.sprite(x, y, width, height, [rotation], [texture], [u0], [v0], [u1], [v1])
- --Draws a quad using the specified vertices
- _r.quad(x0, y0, u0, v0, x1, y1, u1, v1, x2, y2, u2, v2, x3, y3, u3, v3)
- --Returns the width and height of the viewport
- _r.size()
- --Sets the layer to draw elements onto
- _r.layer(layer_index)
- --Pushes the current model-matrix onto the stack (causes all subsequent transform operations to be scoped to the 'push'/'pop' pairing)
- _r.push()
- --Pops the last model-matrix off of the stack and makes it current
- _r.pop()
- --Translate the model-matrix by the vector (x,y)
- _r.translate(x,y)
- --Rotate the model-matrix by rotation 'r' in radians
- _r.rotate(r)
- --Scales the model-matrix by 'sx' and 'sy'
- _r.scale(sx,sy)
- --Example showing usage of model-matrix
- --The root matrix is camera movement
- --Sprites are drawn under temporary matrix which provides rotation
- _r.push()
- _r.translate(-camera_x, -camera_y)
- for _, sp in pairs(allSprites) do
- _r.push() --push temporary matrix
- _r.translate(sp.x, sp.y) --translate to sprite position
- _r.rotate(time) --rotate
- _r.sprite(0,0,100,100) --draw sprite at 0,0 (which is now at sp.x, sp.y because of the current matrix)
- _r.pop() --pop temporary matrix, sets back to camera matrix
- end
- _r.pop()
- --Sound Library
- --Plays a sound, returns the channel the sound is played on.
- --specify channelindex to have explicit control over which channel the sound plays on (such as a music channel)
- sound.play(sound, [channelindex])
- --Stops a sound that is playing on 'channelindex'
- sound.stop(channelindex)
- --Sets the pitch of an audio channel [1 is normal, 2 is double, .5 is half, -1 is reverse, etc.]
- --Returns the channelindex through the function call
- sound.setPitch(channelindex, pitch)
- --Sets the volume of an audio channel [0 - 1]
- --Returns the channelindex through the function call
- sound.setVolume(channelindex, volume)
- --Set if the playing sound should loop when it's finished
- --Returns the channelindex through the function call
- sound.setLooping(channelindex, looping)
- --Set the overall pitch of all playing sounds
- sound.setMasterPitch(pitch)
- --Set the overall volume of all playing sounds
- sound.setMasterVolume(volume)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement