Advertisement
Guest User

Post 12

a guest
Mar 26th, 2013
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. function setup()
  2. --set up normal sprite
  3. img=readImage("Tyrian Remastered:Space Ice 3")
  4. w,h=img.width,img.height
  5. --set up mesh alternative
  6. g=mesh()
  7. g.texture="Tyrian Remastered:Flame 2" --name of the image we want to use
  8. parameter.boolean("Mesh",false)
  9. parameter.integer("NumberOfObjects",50,200,50)
  10. end
  11.  
  12. function draw()
  13. background(0)
  14. output:clear()
  15. print("This demo shows how to draw images using a mesh, rather than sprites, for speed.")
  16. 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.")
  17.  
  18. if Mesh==false then --sprites
  19. for i=1,NumberOfObjects do
  20. --position and size randomly
  21. sprite(img,math.random(0,WIDTH),math.random(0,HEIGHT-100),w*(math.random()*.4))
  22. end
  23. else --Mesh
  24. g:clear()
  25. for i=1,NumberOfObjects do
  26. local x=math.random()*.4 --pick a random size, as we did for sprites
  27. --add a rectangle the same size as our sprite
  28. local d=g:addRect(math.random(0,WIDTH),math.random(0,HEIGHT-100),w*x,h*x)
  29. --the numbers 0,0,1,1 mean to use the whole image, explanation in a later demo
  30. g:setRectTex(d,0,0,1,1) --apply the texture, ie image, but don't draw anything yet
  31. end
  32. g:draw() --draw the final result
  33. end
  34. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement