Page 1 of 1

Repeating an image?

Posted: Fri Oct 12, 2012 7:03 am
by Sullinger
How would you get a specific tile to repeat itself to fill up the entire screen?

Re: Repeating an image?

Posted: Fri Oct 12, 2012 7:27 am
by micha
Use

Code: Select all

image:setWrap('repeat','repeat')
See here: https://love2d.org/wiki/%28Image%29:setWrap

And then draw the image with a quad, that is larger than the image.

Code: Select all

quad = love.graphics.newQuad( 0, 0, largeWidth, largeHeight, imageWidth, imageHeight )
love.graphics.drawq( image, quad, x, y, ...)
This, however, only works, if there is only this one tile in your image. If you have a tile sheet, you have to come up with a different solution. For example a for-loop.

Re: Repeating an image?

Posted: Fri Oct 12, 2012 7:12 pm
by Sullinger
hmmm.... I keep trying it, but it either doesn't do anything or I get an error. And yes, my image is in PO2. (sorry, I'm a noob, haha)

Re: Repeating an image?

Posted: Fri Oct 12, 2012 7:29 pm
by 10$man
How would you get a specific tile to repeat itself to fill up the entire screen?
I would go about this with a for loop something like this (Note, this is psuedo code)

Code: Select all

for w = 0, screen_width/tile:width() do
for h = 0, screen_height/tile:height() do
screen:blit(w * tile:width, h * tile:height(), tile_image)
end
end
This method turns the screen into a grid that is tile:widthXtile:height big and fills each place on the grid with the tile that we want to loop.
Or, a faster method would be to draw all of those onto a canvas then simply blit the canvas (1 graphics card call vs. a few hundred to over a thousand).

I'm not sure if Love has a simpler way to do this.

Re: Repeating an image?

Posted: Sat Oct 13, 2012 3:57 am
by Sullinger
THERE HAS TO BE AN EASIER WAY!

Re: Repeating an image?

Posted: Sat Oct 13, 2012 5:19 am
by Helvecta
Not that I know of! But I wrote this up for you because I actually know how to do this one. It's a pretty thorough explanation of the process and everything. Hope it helps you out, dude! :awesome:

main.lua
The main file. Store in a cozy place (alongside "imageToWrap.jpg")
(1.23 KiB) Downloaded 268 times
Just in case you are too lazy to find an image to wrap, here.
Just in case you are too lazy to find an image to wrap, here.
imageToRepeat.jpg (3.17 KiB) Viewed 5257 times


P.S. Put the main.lua and the image you want to wrap (name it "imageToWrap.jpg", or change the file you want to load by changing the code.. your call) in the same folder. Badabing, LOVE magic!

Re: Repeating an image?

Posted: Sat Oct 13, 2012 6:17 am
by Sullinger
Helvecta wrote:Not that I know of! But I wrote this up for you because I actually know how to do this one. It's a pretty thorough explanation of the process and everything. Hope it helps you out, dude! :awesome:

main.lua
imageToRepeat.jpg


P.S. Put the main.lua and the image you want to wrap (name it "imageToWrap.jpg", or change the file you want to load by changing the code.. your call) in the same folder. Badabing, LOVE magic!
AHHH! Thanks! That kicks ass!!!

Re: Repeating an image?

Posted: Sat Oct 13, 2012 9:28 pm
by 10$man
Sullinger wrote:THERE HAS TO BE AN EASIER WAY!
It took me less then a minute to type... Is it really that bad?

Re: Repeating an image?

Posted: Sat Oct 13, 2012 10:23 pm
by Przemator
Tell me, is wrap faster than spritebatch? I am using the following code:

Code: Select all

grass = love.graphics.newImage("grass.png")
batch = love.graphics.newSpriteBatch(grass, 2000)
for x = 0, 40 do
	for y = 0, 40 do
		batch:add(x * 256, y * 256)
	end
end
256x256 is the size of the tile. I create it once and then just draw the "batch" object.