Repeating an image?
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Repeating an image?
How would you get a specific tile to repeat itself to fill up the entire screen?
Re: Repeating an image?
Use
See here: https://love2d.org/wiki/%28Image%29:setWrap
And then draw the image with a quad, that is larger than the image.
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.
Code: Select all
image:setWrap('repeat','repeat')
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, ...)
Check out my blog on gamedev
Re: Repeating an image?
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?
I would go about this with a for loop something like this (Note, this is psuedo code)How would you get a specific tile to repeat itself to fill up the entire screen?
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
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?
THERE HAS TO BE AN EASIER WAY!
Re: Repeating an image?
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!
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!
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
Re: Repeating an image?
AHHH! Thanks! That kicks ass!!!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!
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?
It took me less then a minute to type... Is it really that bad?Sullinger wrote:THERE HAS TO BE AN EASIER WAY!
Re: Repeating an image?
Tell me, is wrap faster than spritebatch? I am using the following code:
256x256 is the size of the tile. I create it once and then just draw the "batch" object.
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
Who is online
Users browsing this forum: Ahrefs [Bot], Google [Bot] and 6 guests