Page 1 of 1
Cutting a Drawable image
Posted: Fri Jun 13, 2014 3:35 pm
by BetaBlaze
I'm adding ladders into my game. Since my game allows people to construct ladders of various heights, I need to be able to tile the ladder image vertically until the ladder stops.
This is simple, except I need to also be able to cut off the ladder image if it exceeds the height of the ladder. How can I go about this?
Here's how I am drawing the ladder to the screen (it only draws 1 tile, when I figure this out I can draw the rest)
Code: Select all
a.graphics.draw(Pool.Get("Ladder"), v.Position.x, v.Position.y, 0, 1, 1, v.Size.x / 2, v.Size.y / 2)
Re: Cutting a Drawable image
Posted: Fri Jun 13, 2014 4:26 pm
by Scratchthatguys
Maybe you could draw an example in Paint or similar. I can't help you if I don't know how it's supposed to look. I assume it's supposed to cut the ladder off at the exact height it stops at in case it exceeds the exact image. In my opinion, if this is what you're trying to do, you might want to make the image only a ladder segment. It would take more time to draw the ladder, but it would work for what I think you're trying to do.
A drawn example would help me know what you're trying to do.
Re: Cutting a Drawable image
Posted: Fri Jun 13, 2014 4:28 pm
by BetaBlaze
Scratchthatguys wrote:Maybe you could draw an example in Paint or similar. I can't help you if I don't know how it's supposed to look. I assume it's supposed to cut the ladder off at the exact height it stops at in case it exceeds the exact image. In my opinion, if this is what you're trying to do, you might want to make the image only a ladder segment. It would take more time to draw the ladder, but it would work for what I think you're trying to do.
A drawn example would help me know what you're trying to do.
Yes, that is exactly what I am trying to do. I might draw the ladder manually using love.graphics.rectangle instead of using an image then.
Basically, my ladder image is 50px by 50px. In-game, if I have a 50x200 ladder, I'll have no issue tiling my ladder image, but what about a 50x220 ladder? The bottom ladder image needs to be cut off to fit the 220 height.
Re: Cutting a Drawable image
Posted: Fri Jun 13, 2014 4:43 pm
by Scratchthatguys
All right, I understand now. You need a ladder segment image, not a ladder image, and if your ladder segment is an eighth of a tile, you would only move up by an eighth of a tile and draw it there. If you want it to be a sixteenth or a tenth, you can do that instead of an eighth. Maybe someone else could explain this better; without your code I can't explain it very well. Basically, you tile your image up by laddersegment:getHeight() / tilesize instead of the tile size.
EDIT: All right, I'm gonna try to create an example using your code.
Code: Select all
a.graphics.draw(Pool.Get("Ladder"), v.Position.x, v.Position.y, 0, 1, 1, v.Size.x / 2, v.Size.y / 2)
Now, I can only assume what the a and v are, but since you're drawing it there, I assume it's the player. Now, you'd want some gridlocked placement function like this:
Code: Select all
function toLadderPoint(x, y)
local incXSize = 50
local incYSize = 50 / 20 -- assuming your tiles are 50 pixels wide and your segments are 20 pixels tall
local x = math.floor( v.Position.x / incXSize ) * incXSize
local y = math.floor( v.Position.y / incYSize ) * incYSize
return x, y
end
All the math of that was made by someone on here named Plu, I just modified it so the placement sections would be the correct sizes.
Re: Cutting a Drawable image
Posted: Fri Jun 13, 2014 9:33 pm
by dusoft
BetaBlaze wrote:
Yes, that is exactly what I am trying to do. I might draw the ladder manually using love.graphics.rectangle instead of using an image then.
Basically, my ladder image is 50px by 50px. In-game, if I have a 50x200 ladder, I'll have no issue tiling my ladder image, but what about a 50x220 ladder? The bottom ladder image needs to be cut off to fit the 220 height.
What about using love.graphics.setScissor(......) ?
Re: Cutting a Drawable image
Posted: Sat Jun 14, 2014 1:45 am
by BetaBlaze
dusoft wrote:BetaBlaze wrote:
Yes, that is exactly what I am trying to do. I might draw the ladder manually using love.graphics.rectangle instead of using an image then.
Basically, my ladder image is 50px by 50px. In-game, if I have a 50x200 ladder, I'll have no issue tiling my ladder image, but what about a 50x220 ladder? The bottom ladder image needs to be cut off to fit the 220 height.
What about using love.graphics.setScissor(......) ?
I tried using that earlier, didn't work as expected. I might have done it wrong though, so I'll try again.
Re: Cutting a Drawable image
Posted: Sat Jun 14, 2014 9:18 am
by micha
You can use a
Quad for that. If you set the quad coordinates larger than the given image, then the image is repeated, if you set the
wrapping properties to
"repeat".
Re: Cutting a Drawable image
Posted: Sat Jun 14, 2014 5:48 pm
by Scratchthatguys
Textured quads seem like the way to go. Good luck with your game!
Re: Cutting a Drawable image
Posted: Sat Jun 14, 2014 8:13 pm
by BetaBlaze
Scratchthatguys wrote:Textured quads seem like the way to go. Good luck with your game!
Yes, I agree.
I've managed to make use of the scissor in love.graphics to render some other stuff in my game, but it definitely looks like I'll be using quads for ladders and other textures.