Repeating an image?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Sullinger
Prole
Posts: 9
Joined: Mon Oct 08, 2012 5:30 am

Repeating an image?

Post by Sullinger »

How would you get a specific tile to repeat itself to fill up the entire screen?
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Repeating an image?

Post 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.
Sullinger
Prole
Posts: 9
Joined: Mon Oct 08, 2012 5:30 am

Re: Repeating an image?

Post 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)
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: Repeating an image?

Post 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.
Sullinger
Prole
Posts: 9
Joined: Mon Oct 08, 2012 5:30 am

Re: Repeating an image?

Post by Sullinger »

THERE HAS TO BE AN EASIER WAY!
User avatar
Helvecta
Party member
Posts: 167
Joined: Wed Sep 26, 2012 6:35 pm

Re: Repeating an image?

Post 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 5254 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!
"Bump." -CMFIend420
Sullinger
Prole
Posts: 9
Joined: Mon Oct 08, 2012 5:30 am

Re: Repeating an image?

Post 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!!!
10$man
Citizen
Posts: 77
Joined: Sun Apr 22, 2012 10:40 pm

Re: Repeating an image?

Post 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?
User avatar
Przemator
Party member
Posts: 107
Joined: Fri Sep 28, 2012 6:59 pm

Re: Repeating an image?

Post 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.
Post Reply

Who is online

Users browsing this forum: Ahrefs [Bot] and 4 guests