PicoPicoGameEngine

Quick Links

Graphics Object

ppgraph

:tileInfo()

ppgraph:tileInfo(tile_info)
tile_info = ppgraph:tileInfo()
tile_info : object

tile_info={
  size={
    width=[Tile width],
    height=[Tile height]
  },
  stride={
    x=[Horizontal tile stride],
    y=[Vertical tile stride]
  },
  offset={
    x=[Horizontal offset],
    y=[Vertical offset]
  }
}

:put()

ppgraph:put(x,y,tile, [texture_filename], [texture_option],[color])
ppgraph:put({x,y},tile, [texture_filename], [texture_option],[color])
ppgraph:put(pos,tile, [texture_filename], [texture_option],[color])
x : number

X position

y : number

Y position

pos : point object

Position

tile : number

Tile number

[texture_filename] : string/optional

Texture filename

[texture_option] : object/optional

Texture option

[color] : color object

Color

img="characters.png"
function start()
  ppgraph:tileInfo(
    {size={width=32,height=32}})
  ppgraph:put(0,0,1,img)
  ppgraph:put({0,32},2,img)
  ppgraph:put({x=0,y=64},3,img)
  ppgraph:tileInfo(
    {size={width=64,height=64}})
  ppgraph:put(32,0,4,img)
end
ppgraph:put(x,y,tile,[texture],[color])
ppgraph:put({x,y},tile,[texture],[color])
ppgraph:put(position,tile,[texture],[color])
x : number

y : number

position : point object

tile : number

[texture] : texture object/optional

[color] : color object/optional

img="characters.png"
tex = pptex:load(img)
function start()
  ppgraph:tileInfo(
    {size={width=32,height=32}})
  ppgraph:put(0,0,1,tex)
  ppgraph:put({0,32},2,tex)
  ppgraph:put({x=0,y=64},3,tex)
  ppgraph:tileInfo(
    {size={width=64,height=64}})
  ppgraph:put(32,0,4,tex)
end

:pos()
:locate()

ppgraph:pos(x,y)
ppgraph:locate(x,y)
ppgraph:pos({x,y})
ppgraph:locate({x,y})
ppgraph:pos(position)
ppgraph:locate(position)
x : number

y : number

position : point object

function start()
  ppgraph:pos(100,100)
  ppgraph:print("HELLO1")
  ppgraph:pos({100,116})
  ppgraph:print("HELLO2")
  ppgraph:pos({x=100,y=132})
  ppgraph:print("HELLO3")
end

:move()

ppgraph:move(x,y)
ppgraph:move({x,y})
ppgraph:move(position)
x : number

y : number

position : point object

function start()
  ppgraph:pos(100,100)
  ppgraph:print("HELLO1")
  --move to down 16 pixel
  ppgraph:move(0,16)
  ppgraph:print("HELLO2")
  --move to down 16 pixel
  ppgraph:move(0,16)
  ppgraph:print("HELLO3")
end

:print()

ppgraph:print(string,[color])
string : string

Drawing string

[color] : color object/optional

:color()

ppgraph:color(color)
color=ppgraph:color()
[color] : color object/optional

:scale()

ppgraph:scale(x,y)
ppgraph:scale({x,y})
ppgraph:scale(scale)
scale = ppgraph:scale()
x : number

Horizontal scale

y : number

Vertical scale

scale : point object

Scale

:flip()

ppgraph:flip(hflip,vflip,rot90)
hflip,vflip,rot90 = ppgraph:flip()
hflip : boolean

Enable horizontal flipping

  • true enable
  • false disable
vflip : boolean

Enable vertical flipping

  • true enable
  • false disable
rot90 : number

Rotate counterclockwise 0-3

pptex:default(
  pptex:load("characters.png"))
function start()
  ppgraph:flip(false,false,0)
  ppgraph:put(32,32,1)
  ppgraph:flip(true,false,1)
  ppgraph:put(66,32,1)
  ppgraph:flip(false,true,2)
  ppgraph:put(100,32,1)
  ppgraph:flip(true,true,3)
  ppgraph:put(134,32,1)
end

:rotate()

ppgraph:rotate(r)
r = ppgraph:rotate()
r : number

Angle (radian)

:alpha()

ppgraph:alpha(a)
a = ppgraph:alpha()
a : number

Transparent 0-255

:fill()

ppgraph:fill(x,y,width,height,[color])
ppgraph:fill({x,y,width,height},[color])
ppgraph:fill(rectangle,[color])
x : number

y : number

width : number

height : number

rectangle : rectangle object

[color] : color object/optional

:box()

ppgraph:box(x,y,width,height,[color])
ppgraph:box({x,y,width,height},[color])
ppgraph:box(rectangle,[color])
x : number

y : number

width : number

height : number

rectangle : rectangle object

Rectangle position

[color] : color object/optional

:line()

ppgraph:line(x1,y1,x2,y2,[color])
ppgraph:line({x1,y1},{x2,y2},[color])
ppgraph:line(pos1,pos2,[color])
x1 : number

Start x position

y1 : number

Start y position

x2 : number

End x position

y2 : number

End y position

pos1 : point object

Start position

pos2 : point object

End position

[color] : color object/optional

:circle()

ppgraph:circle(x,y, radius, [color], [start], [end])
ppgraph:circle({x,y}, radius, [color], [start], [end])
ppgraph:circle(center, radius, [color], [start], [end])
ppgraph:circle(x,y, rx,ry, [color], [start], [end])
ppgraph:circle({x,y}, {rx,ry}, [color], [start], [end])
ppgraph:circle(center, oval_radius, [color], [start], [end])
x,y : number

center : point object

radius : number

oval_radius : point object

[color] : color object/optional

[start] : number/optional

[end] : number/optional

g=ppgraph

function start()
 local r
 for r=160,10,-10 do
  local c={
    math.random(0,255),
    math.random(0,255),
    math.random(0,255),
    255
  }
  g:circle(160,200,r,c)
 end
end

:triangleFan()

ppgraph:triangleFan(x1, y1, x2, y2, ..., [color])
ppgraph:triangleFan({x1, y1, x2, y2, ...}, [color])
ppgraph:triangleFan({{x1, y1}, {x2, y2}, ...}, [color])
ppgraph:triangleFan(p1, p2, p3, ..., [color])
ppgraph:triangleFan({p1, p2, p3, ...}, [color])
x1,y1,x2,y2,... : number

p1,p2,p3,... : point object

[color] : color object/optional

g=ppgraph
sin=math.sin
cos=math.cos
pi=math.pi
c=pppoint(160,200)

function start()
 local r=100
 local p={}
 for q=0,360,30 do
  p[#p+1] = {
    sin(q*pi/180)*r+c.x,
    cos(q*pi/180)*r+c.y,
  }
 end
 g:triangleFan(p,g.green)
end

:triangleStrip()

ppgraph:triangleStrip(x1, y1, x2, y2, ..., [color])
ppgraph:triangleStrip({x1, y1, x2, y2, ...}, [color])
ppgraph:triangleStrip({{x1, y1}, {x2, y2}, ...}, [color])
ppgraph:triangleStrip(p1, p2, p3, ..., [color])
ppgraph:triangleStrip({p1, p2, p3, ...}, [color])
x1,y1,x2,y2,... : number

p1,p2,p3,... : point object

[color] : color object/optional

:layout()

pos=ppgraph:layout(x,y, width,height, centerx,centery, [area])
pos=ppgraph:layout({x,y, width,height}, centerx,centery, [area])
pos=ppgraph:layout(rectangle, centerx,centery, [area])
x : number

Horizontal offset

y : number

Vertical offset

width : number

height : number

centerx : boolean

  • true
  • false
centery : boolean

  • true
  • false
[area] : rectangle object

pos : point object

img="characters.png"
function start()
  local p = ppgraph:layout(
    {x=0,y=0,
     width=32,height=32},
    true,true)
  ppgraph:put(p,1,img)
end
img="characters.png"
function start()
  local p = ppgraph:layout(
    {x=-1,y=0,
     width=32,height=32},
    false,true)
  ppgraph:put(p,1,img)
end
img="characters.png"
function start()
  local p = ppgraph:layout(
    {x=-33,y=-33,
     width=32,height=32},
    false,false)
  ppgraph:put(p,1,img)
end
img="characters.png"
function start()
  local area = {0,0,100,100}
  local p = ppgraph:layout(
    {x=-17,y=-17,
     width=32,height=32},
    false,false,area)
  ppgraph:fill(area,
    ppgraph.lightgray)
  ppgraph:put(p,1,img)
end

:update()

ppgraph:update()
function start()
  for i=0,60 do
    ppgraph:print(
      "SCREEN 1")
    ppgraph:update()
  end
  for i=0,60 do
    ppgraph:print(
      "SCREEN 2")
    ppgraph:update()
  end
end

:pivot()

ppgraph:pivot(x,y)
ppgraph:pivot({x,y})
ppgraph:pivot(pivot)
pivot = ppgraph:pivot()
x : number

y : number

pivot : point object

Center position

:lineWrap()

ppgraph:lineWrap(flag)
flag = ppgraph:lineWrap()
flag : boolean

  • true
  • false

:append()

ppgraph:append(display_object)
display_object : object

display_object={
  draw=function(self)
    -- draw
  end
}
sp = ppsprite.new()
sp:texture("characters.png")
sp:tile(1)
ppgraph:append(sp)

local t=0

function show()
  t=t+1
  if t > 60 then 
    ppgraph:remove(sp)
    ppgame:start(hide)
    t=0
  end
end

function hide()
  t=t+1
  if t > 60 then 
    ppgraph:append(sp)
    ppgame:start(show)
    t=0
  end
end

ppgame:start(show)

:remove()

ppgraph:remove(display_object)
display_object : object

display_object={
  draw=function(self)
    -- draw something
  end
}

:tileRect()

rect = ppgraph:tileRect(tile,[texture])
tile : number

[texture] : texture object

Texture

rect : rectangle object

Tile position

pptex:default(
  pptex:load("characters.png"))
r02=ppgraph:tileRect(2)
r35=ppgraph:tileRect(35)
function start()
  ppgraph:print(
    r02.x..","..r02.y..","..
    r02.width..","..r02.height)
  ppgraph:move(0,16)
  ppgraph:print(
    r35.x..","..r35.y..","..
    r35.width..","..r35.height)
end

:stretch()

ppgraph:stretch( {x,y,width,height},tile, [edge],[texture])
ppgraph:stretch( rect,tile, [edge],[texture])
x : number

y : number

width : number

height : number

rect : rectangle object

Drawing position

tile : number

[edge] : number

Edge width

[texture] : textire object

Texture

pptex:default(
  pptex:load("characters.png"))
function start()
  ppgraph:stretch(
    {64,32,128,64},3)
  ppgraph:stretch(
    pprect(64,116,128,32),3)
  ppgraph:stretch(
    pprect(64,168,128,64),3,8)
end

.white
.red
.green
.blue
.yellow
.cyan
.magenta
.black
.gray
.lightgray
.orange
.skin
.darkgreen
.lightgreen
.brown

There are some preset colors.

ppgraph.white={r=255,g=255,b=255}
ppgraph.red={r=255,g=0,b=0}
ppgraph.green={r=0,g=255,b=0}
ppgraph.blue={r=0,g=0,b=255}
ppgraph.yellow={r=255,g=255,b=0}
ppgraph.cyan={r=0,g=255,b=255}
ppgraph.magenta={r=255,g=0,b=255}
ppgraph.black={r=0,g=0,b=0}
ppgraph.gray={r=96,g=96,b=96}
ppgraph.lightgray={r=188,g=188,b=188}
ppgraph.orange={r=255,g=128,b=0}
ppgraph.skin={r=255,g=216,b=160}
ppgraph.darkgreen={r=56,g=104,b=0}
ppgraph.lightgreen={r=152,g=232,b=0}
ppgraph.brown={r=120,g=64,b=0}
g=ppgraph
function start()
 g:pos(0,0)
 g:print("WHITE",g.white)
 g:move(0,16)
 g:print("RED",g.red)
 g:move(0,16)
 g:print("GREEN",g.green)
 g:move(0,16)
 g:print("BLUE",g.blue)
 g:move(0,16)
 g:print("YELLOW",g.yellow)
 g:move(0,16)
 g:print("CYAN",g.cyan)
 g:move(0,16)
 g:print("MAGENTA",g.magenta)
 g:move(0,16)
 g:print("BLACK",g.black)
 g:move(0,16)
 g:print("GRAY",g.gray)
 g:move(0,16)
 g:print("LIGHTGRAY", g.lightgray)
 g:move(0,16)
 g:print("ORANGE",g.orange)
 g:move(0,16)
 g:print("SKIN",g.skin)
 g:move(0,16)
 g:print("DARKGREEN", g.darkgreen)
 g:move(0,16)
 g:print("LIGHTGREEN",
   g.lightgreen)
 g:move(0,16)
 g:print("BROWN",g.brown)
end