Cutting a Drawable 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
BetaBlaze
Prole
Posts: 5
Joined: Fri Jun 13, 2014 1:34 am

Cutting a Drawable image

Post 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)
Scratchthatguys
Prole
Posts: 8
Joined: Thu Jun 12, 2014 10:49 pm

Re: Cutting a Drawable image

Post 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.
Last edited by Scratchthatguys on Fri Jun 13, 2014 4:41 pm, edited 2 times in total.
BetaBlaze
Prole
Posts: 5
Joined: Fri Jun 13, 2014 1:34 am

Re: Cutting a Drawable image

Post 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.
Scratchthatguys
Prole
Posts: 8
Joined: Thu Jun 12, 2014 10:49 pm

Re: Cutting a Drawable image

Post 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.
User avatar
dusoft
Party member
Posts: 635
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: Cutting a Drawable image

Post 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(......) ?
BetaBlaze
Prole
Posts: 5
Joined: Fri Jun 13, 2014 1:34 am

Re: Cutting a Drawable image

Post 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. :3
User avatar
micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

Re: Cutting a Drawable image

Post 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".
Scratchthatguys
Prole
Posts: 8
Joined: Thu Jun 12, 2014 10:49 pm

Re: Cutting a Drawable image

Post by Scratchthatguys »

Textured quads seem like the way to go. Good luck with your game!
BetaBlaze
Prole
Posts: 5
Joined: Fri Jun 13, 2014 1:34 am

Re: Cutting a Drawable image

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

Who is online

Users browsing this forum: Ahrefs [Bot], Bing [Bot] and 2 guests