Skip to content
smithmule edited this page Jul 16, 2019 · 14 revisions

spr

spr id x y [colorkey=-1] [scale=1] [flip=0] [rotate=0] [w=1 h=1]

Parameters:

  • id : index of the sprite
  • x : x coordinate where the sprite will be drawn, starting from top left corner.
  • y : y coordinate where the sprite will be drawn, starting from top left corner.
  • colorkey : index (or array of indexes) of the color in the sprite that will be used as transparent color. Use -1 if you want an 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.
  • w : width of composite sprite
  • h : height of composite sprite

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 drawn to 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

You can draw a composite sprite (consisting of a rectangular region of sprites from the sprite sheet) by specifying the w and h parameters (which default to 1).

Example

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
You can’t perform that action at this time.