Since I’ve seen no one do this yet with the new sprite zsize function, it thought I might as well. It was extremely easy, but here is the code:
function setup()
mx = 0
my = 0
end
function tileImage(image,movex,movey,iscale)
local oldScale = scale
local currentScale = 1
scale = function( d )
if d == nil then
return currentScale
else
currentScale = currentScale * d
oldScale(d)
end
end
bsmode = spriteMode()
currentScale = scale()
bscale = currentScale
spriteMode(CORNER)
scale(iscale)
ssx, ssy = spriteSize(image)
mx = mx + movex
my = my + movey
for y = -1, HEIGHT/ssy/iscale do
for x = -1, WIDTH/ssx/iscale do
if mx >= ssx or mx <= -ssx then
mx = 0
elseif my >= ssy or my <= -ssy then
my = 0
end
sprite(image, x * ssx+mx, y * ssy+my)
end
end
spriteMode(bsmode)
scale(bscale)
end
That was easy. But it’s still full of bugs and needs improvement. Here’s what’s on my list:
Fix the jolt when repeating the images when moving
Fix the problem when you tell it to move mor pixels than the image is
Fix the returning to the original scale and sprite mode
Madage to contain all the variables within the function
Speed up the process. It really slows down the program and even crashes Codea when you use some pixel art.
Add option to tell it if it’s a block or not and it will automatically offset it correctly and draw the blocks right.
Yes. Push/pull is like a stack of plastic cups. You push the current style down on the stack, then you can change whatever and when done, pop the style back up. Since it’s a stack, you can push multiple times and they pop LIFO - last (most recent) in first out
-- This sets the line thickness
strokeWidth(5)
-- Do your drawing here
line(100,100,100,200) --5
pushStyle() --push 5
line(110,100,110,200) --still 5
strokeWidth(10) --changed to 10
line(120,100,120,200) --10
popStyle() --pop 5
line(130,100,130,200) --5
Are you talking about movex and movey? Those automatically move the background. In the loop, I start at -1 so when it is moving 1,1 pixels, I loop the position back to 0 (which there is a better method I’m about to add) to simulate continuous motion.
@Martin - mx means move x. Mabey I shouldve called it adjust x. I change it whatever amount the image should be offset to make the images move. Then when it’s greater than the image size, I set it back to 0 to simulate an ongoing background.