Difference between revisions of "Lua Player"
(initial page; partial save) |
(No difference)
|
Revision as of 12:43, 5 November 2019
Lua Player is an application that plays back Lua scripts on the PSP. Similar to LÖVE, Lua Player allows for development of games and apps using a simpler language than C++.
Functions
Graphics
Font Font.load(filename)
- Loads a true type font.Font Font.createMonoSpaced()
- Creates an instance of the built-in mono-spaced font.Font Font.createProportional()
- Creates an instance of the built-in proportional font.Font Font:setCharSize(number width, number height, number dpiX, number dpiY)
- Changes the size of the current font to the specified point size height and width (if width is 0, it will be calculated proportional to the height for every character). dpiX and dpiY is the resolution of the display (see the Freetype documentation for details).Font Font:setPixelSizes(number width, number height)
- Changes the size of the current font to the specified pixel size height and width (if width is 0, it will be calculated proportional to the height for every character). (see the Freetype documentation for details).width, height Font:getTextSize(string)
- Returns the width and height, which will be used, if the specified text is drawn with this font and the current font size.Image Image.createEmpty(width, height)
- Creates an empty image, initially cleared. Max width and height is 512.Image Image.load(filename)
- Loads an image. Currently JPEG and PNG files are supported.Image Image.loadFromMemory(data)
- Loads an image from memory (data is a Lua string). Currently JPEG and PNG files are supported.
jpegFile = io.open("test.jpg", "rb") data = jpegFile:read("*a") jpegFile:close() image = Image.loadFromMemory(data)
nil image:blit(x, y, Image source, [sourcex, sourcey, width, height], [alpha = true])
- Paints the image, which is specified as “source” to the image on which this function is called on (or to the double buffered screen, when using the “screen:blit(...)” variable, which is a special image). “sourcex” and “sourcey” is the position in the source image, from where a rectangle of the size width/height is copied.nil image:clear([color = transparent-black])
- Sets all pixels of an image to the specified color.nil image:fillRect(x, y, width, height, [color = transparent-black])
- Draws a filled rectangle.nil image:drawLine(x0, y0, x1, y1, [color = black])
- Draws a line. TODO: Clipping needs to be enhanced.Color image:pixel(x, y) --get
- Gets the color of a pixel. See for example this code to get the color of an pixel and assert the value of all color components:
image = Image.createEmpty(1, 1) color = image:pixel(0, 0) colors = color:colors() assert(colors.r == 0) assert(colors.g == 0) assert(colors.b == 0) assert(colors.a == 0)
nil image:pixel(x, y, Color)
- Sets the color of a pixel.nil image:print(x, y, text, [color = black])
- Prints some text with a predefined fixed width font with 8×8 pixels per character.nil image:fontPrint(font, x, y, text, [color = black])
- Prints some text with the specified true type font.Number image:width()
- Returns the width of an image.Number image:height()
- Returns the height of an image.nil image:save( filename )
- Saves an image to memory stick. Currently JPEG and PNG files are supported.global Image screen
- The special double buffered screen object, which has all methods of an image and some more, see below.nil screen.flip() -- note the small s; this is a function of the screen
- Flips the offscreen and onscreen screen.nil screen.waitVblankStart([count])
- Waits until vertical retrace starts.Color Color.new(r, g, b, [a=255])
- Creates a new color object with the specified RGBA values.table[r,g,b,a] color:colors()
- Returns the RGBA values of a color object.Bool (Color a == Color b)
- Color objects are equal, if all RGBA components are equal.
3D GU Mapping
Gu.start3d()
saves the current GE state for the normal 2D operations. Call this function first and then draw your scene. You can use the following functions:
Gu.clearColor, Gu.clearDepth, Gu.clear, Gum.matrixMode, Gum.loadIdentity, Gum.perspective, Gum.translate, Gum.rotateXYZ, Gu.texImage, Gu.texFunc, Gu.texEnvColor, Gu.texFilter, Gu.texScale, Gu.texOffset, Gu.ambientColor, Gu.enable, Gu.disable, Gu.blendFunc, Gu.light, Gu.lightAtt, Gu.lightColor, Gu.lightMode, Gu.lightSpot and Gum.drawArray
. See the PSPSDK for documenation about the parameters, for example pspgu.h. If there is a ScePspFVector3
, write 3 numbers instead one parameter (this will be changed in a later version). Whereever a color is expected, use a Color
object. For textures use an Image
object.
Gum.drawArray
is something special: It has just 3 parameters: "prim", "vtype" and a table. With "prim" you specify which primitive should be used, for example Gu.TRIANGLES
. "vtype" specifies the vertex format and the transformation operation. For example "Gu.COLOR_8888|Gu.VERTEX_32BITF|Gu.TRANSFORM_3D" means, that your vertices has a color component and a 3 vertex coordinate components and is transformed before passed to the rasterizer. The table is then a list of vertex entries, where each vertex entry has the form (color, x, y, z). If you have specified GU_TEXTURE_32BITF
, too, then one entry looks like this: (textureU, textureV, color, x, y, z)
. The order of the entries is defined in pspgu.h: textureU, textureV, color, normalX, normalY, normalZ, vertexX, vertexY, vertexZ. Indices, weights and multiple vertices per entry (which you’ll need for the morphing feature) currently are not supported.
After drawing anything, call Gu.end3d()
, which flushs the display buffer and draws all pending 3D graphics and restores the 2D GE state. Don’t forget to call a screen:clear()
before fullscreen 2D operations, because otherwise the z-buffer is not cleared and the blitting functions may not work correctly. If you need to blit 2D images in 3D mode, use textures and triangles.
See the 3D Cube example in the Applications folder of the distribution of Lua Player to see how to use the 3D functions and take a look at the GU example in the PSPSDK how to use all the other functions. Most of the time you can copy and paste the examples and just remove all those C fussinesses like ".0f", semicolon, malloc etc. :-)
Note: The 3D API might change in the future.
Controls
Controls Controls.read()
Bool controls:select() Bool controls:start() Bool controls:up() Bool controls:right() Bool controls:down() Bool controls:left() Bool controls:l() Bool controls:r() Bool controls:triangle() Bool controls:circle() Bool controls:cross() Bool controls:square() Bool controls:home() Bool controls:hold() Bool controls:note()
Number controls:analogX() -- ranges from -127 to 128
- Returns the current analog stick position in x direction.Number controls:analogY() -- ranges from -127 to 128
- Returns the current analog stick position in y direction.Bool (Controls a == Controls b) -- note! The analog stick is NOT considered when comparing because of analog fluctuations
- Compares two pad states.Number controls:buttons() -- returns the bitmask like sceCtrlReadBufferPositive reads it
- Constants for binary operations on buttons() result (for example "Controls.read():buttons() & Controls.startMask > 0" is the same as "Controls.read():start()")
Number Controls.selectMask Number Controls.startMask Number Controls.upMask Number Controls.rightMask Number Controls.downMask Number Controls.leftMask Number Controls.ltriggerMask Number Controls.rtriggerMask Number Controls.triangleMask Number Controls.circleMask Number Controls.crossMask Number Controls.squareMask Number Controls.homeMask Number Controls.holdMask Number Controls.noteMask
Millisecond Timer
Timer Timer.new([startTime])
- Creates a new Timer object, sets to 0 or startTime in milliseconds, if specified BUT don’t start ticking as yet.Number Timer:start()
- Starts to tick the timer (incrementing by one every millisecond), or resumes to tick after being stopped. Returns the current time() value. If the timer is running, it is the same as time().Number Timer:time()
- Returns in milliseconds since the timer started/resumed.Number Timer:stop()
- Stops the timer. Returns the current time(). Subsequent time() calls returns the value when stopped. If the timer is stopped, this call is the same as time().Number Timer:reset([startTime])
- Resets the timer to 0 by default or startTime in milliseconds and holds the timer. Returns the time before resetted to the new value.