Skip to content
Kesi edited this page Mar 26, 2017 · 29 revisions

spr

id x y [colorkey [scale [flip:0..3 [rotate:0..3] ] ] ]

Parameters:

  • id : index of the sprite
  • x : x coordinate where the sprite will be draw, starting from top left corner.
  • y : y coordinate where the sprite will be draw, starting from top left corner.
  • colorkey : index of the color in the sprite that will be used as transparent color. Use -1 if you want a opaque sprite.
  • scale : scale factor applied to sprite.
  • flip : flip the sprite vertically or horizontally or both.
  • rotate : rotate the sprite by 0, 90, 180 or 270 degrees.

Description:

It will put the sprite number index in the x and y coordinate.

You can specify a colorkey in the palette that will be used as transparent color. Use -1 to have an opaque sprite.

The sprite can be scaled up by a desired factor. As example: a scale of 2 means the sprite is draw in the screen as 16x16 pixel

You can flip the sprite where:

  • 0 = No Flip
  • 1 = Flip horizontally
  • 2 = Flip vertically
  • 3 = Flip both vertically and horizontally

When you rotate the sprite, it's rotated in 90° step clockwise:

  • 0 = No rotation
  • 1 = 90° rotation
  • 2 = 180° rotation
  • 3 = 270° rotation

Example

-- spr demo

--Build sprite from text
data="010000000160010015240160170170170170170175170166250255170170170175106170170170170170051051051051"
for i=0,31 do
 poke(0x4000+32+i,
 tonumber(string.sub(data,i*3+1,i*3+3)))
end

p={
 x={val=100,min=0,max=240},
 y={val=68,min=0,max=136},
 colorkey={val=0,min=-1,max=15},
 scale={val=1,min=0,max=256},
 flip={val=0,min=0,max=3},
 rotate={val=0,min=0,max=3},
}
sel=next(p,nil)
  

function TIC()

 --Keys
 if btnp(0,30,6) then 
  for n=0,4 do
   sel=next(p,sel) or next(p,nil)
  end
 end
 if btnp(1,30,6) then
  sel=next(p,sel) or next(p,nil) 
 end
 
 if btnp(2,30,6) then
  p[sel].val=p[sel].val-1  
 end
 if btnp(3,30,6) then
  p[sel].val=p[sel].val+1
 end 
 
 --Clamp
 if p[sel].val>p[sel].max then
   p[sel].val=p[sel].max
 end
 if p[sel].val<p[sel].min then
   p[sel].val=p[sel].min
 end

 cls(0)
 print("Use up/down  to select parameter",0,0)
 print("left/right to change its value:",0,10)
  
 --Build menu with cursor
 r=0
 for k,v in pairs(p) do
  cur=(k==sel) and '>' or ' '
  print(cur..k..':'..v.val,0,30+10*r)
  r=r+1
 end 
 
 --Draw Sprite
 spr(1,
    p.x.val,
    p.y.val,
    p.colorkey.val,
    p.scale.val,
    p.flip.val,
    p.rotate.val)

end
Clone this wiki locally