PicoPicoGameEngine

Quick Links

Game System Object

ppgame

:start()

Call ppgame:start(fn) to change the function that the engine calls to update your game.

By default, the engine will call your function called "start" but you can update this at run time based on your game logic. For example, you might call ppgame:start(mainmenu) and then later ppgame:start(play) and then ppgame:start(gameover). The argument you pass is a lua closure.

ppgame:start(gameloop)
gameloop : function

Game Loop function.

local timer=0

--default game loop is start()
function start()
  ppgraph:print("first loop");
  timer=timer+1
  --1second later.
  if timer>60 then
    --change game loop.
    ppgame:start(title)
  end
end

function title()
  ppgraph:print("second loop");
end

:platform()

Returns a string that identifies which platform your game is running on.

platform = ppgame:platform()
platform : string

  • mac
  • ios
  • ios-simulator
  • win
  • android
function start()
  ppgraph:print(ppgame:platform())
end

:fps()

Returns the number of frames per second that your game is running at right now. This is useful for debugging. See also ppgame:deltaTime()

fps = ppgame:fps()
fps : number

function start()
  ppgraph:print(ppgame:fps())
end

:deltaTime()

Returns the elapsed time in seconds since the last game loop iteration. For example, at 60 fps, ppgame:deltaTime() will return 1/60 = 0.01667

deltaTime = ppgame:deltaTime()
deltaTime : number

function start()
  local t=ppgame:deltaTime()
  ppgraph:print(t)
end

:mouse()

Returns the position of the mouse pointer as a pppoint. This only works on the desktop, not iOS.

point = ppgame:mouse()
point : point object

function start()
  local p=ppgame:mouse()
  ppgraph:print(p.x..","..p.y)
end

:volume()

Sets the master volume of the MML audio engine. If you don't pass a parameter, ppgame:volume() will return the current volume. Volume ranges from 0 = silent up to 1.0 for full volume.

ppgame:volume(volume)
volume = ppgame:volume()
volume : number

:setNumber()
:setInteger()
:setString()

You can save values between game sessions. This is useful for saving high scores, or your character in an RPG.

ppgame:setNumber(name,value)
name : string

value : number

ppgame:setInteger(name,value)
name : string

value : number

ppgame:setString(name,value)
name : string

value : string

:getNumber()
:getInteger()
:getString()

Get values that have been previously saved with setNumber, setInteger and setString. If no value has been set, null is returned.

ppgame:getNumber(name,default)
name : string

default : number

default value

ppgame:getInteger(name,default)
name : string

default : number

ppgame:getString(name,default)
name : string

default : string

local score = ppgame:getInteger("score",100)
ppgame:setInteger("score",200)
function start()
  ppgraph:print(score)
end