Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function setup()
- --set up normal sprite
- img=readImage("Tyrian Remastered:Space Ice 3")
- w,h=img.width,img.height
- --set up mesh alternative
- g=mesh()
- g.texture="Tyrian Remastered:Flame 2" --name of the image we want to use
- parameter.boolean("Mesh",false)
- parameter.integer("NumberOfObjects",50,200,50)
- end
- function draw()
- background(0)
- output:clear()
- print("This demo shows how to draw images using a mesh, rather than sprites, for speed.")
- print("NB You won't see an obvious speed change when you switch between them, because this hasn't been set up as a speed test.")
- if Mesh==false then --sprites
- for i=1,NumberOfObjects do
- --position and size randomly
- sprite(img,math.random(0,WIDTH),math.random(0,HEIGHT-100),w*(math.random()*.4))
- end
- else --Mesh
- g:clear()
- for i=1,NumberOfObjects do
- local x=math.random()*.4 --pick a random size, as we did for sprites
- --add a rectangle the same size as our sprite
- local d=g:addRect(math.random(0,WIDTH),math.random(0,HEIGHT-100),w*x,h*x)
- --the numbers 0,0,1,1 mean to use the whole image, explanation in a later demo
- g:setRectTex(d,0,0,1,1) --apply the texture, ie image, but don't draw anything yet
- end
- g:draw() --draw the final result
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement