Is there any better way to display 90 object each frame than writing 90 lines of sprite displaying? Because I need to update it each frame so that I can make my man move… My try:
if BlockCount ~= 90 then
sprite("Planet Cute:Grass Block", BlockPosition.x, BlockPosition.y)
BlockPosition.x = BlockPosition.x + 101
if BlockPosition.x > 1024 then
BlockPosition.x = 57
BlockPosition.y = BlockPosition.y - 80
end
BlockCount = BlockCount + 1
end
@g1t2r3 - put ~~~ on a line before after your code to make it look nice
try this, it creates a picture at the beginning with all your grass blocks, then you only need to draw that one picture each time after that
function setup()
--put your other setup code first, then this..
local img=readImage("Planet Cute:Grass Block")
local w,h = img.width, img.height
local x = 10 --number of times to copy image left to right
local y = 9 --number of times to copy image top to bottom
grass=image(x*w,y*h)
setContext(img) --draw to image instead of screen
for i=0,x-1 do
for j=0,y-1 do
sprite(img,i*w+1,j*h+1)
end
end
setContext()
end
--then in draw
sprite(grass, x, y ) --choose x,y to position it correctly
Try this, it also trims the image to get rid of the edges
function setup()
--put your other setup code first, then this..
local img=readImage("Planet Cute:Grass Block")
img=img:copy(4,45,95,73)
local w,h = img.width, img.height
local x = 10 --number of times to copy image left to right
local y = 9 --number of times to copy image top to bottom
grass=image(x*w,y*h)
setContext(grass) --draw to image instead of screen
for i=0,x-1 do
for j=0,y-1 do
sprite(img,i*w+1,j*h+1)
end
end
setContext()
end
--then in draw
function draw()
background(100)
sprite(grass, 400, 400 ) --choose x,y to position it correctly
end