Ok, I suppose I should go into a bit more detail then.
I'm making a top-down game and thus am working with a psudo-3D environment. I need to constrain the drawing so that, for example, if the player was jumping over a box, the shadow would only appear on the top of the box. I would then draw another shadow on the ground. This is so that the shadow does not show up on the sides of the box, as that would be weird. Also, as the ground's surface is a different distance away from the player than the top surface of the box, the shadow size and opacity should be different.
Just imagine what it should look like, looking straight-down from the top and seeing a shadow resulting from light which comes straight down. This would appear as simply a circle. However, if you use a top-down perspective a-la the 2D Zelda games, then then just using a circle would be weird, as in this perspective you can view the top and sides of a building, box, or what-have-you in the same plane.
Hope that's clear enough and everything makes sense >.<
If you draw out a picture of what the scene should look like as seen from directly above, and then try to draw the same thing from the typical top-down psudo-3D perspective, I think you'll see what my problem is.
clip_to
works with the other transformations like rotate
and translate
if that helps at all. If you could show a wee snippet of code for what you're trying to do, I might be able to figure out what needs to be done about it. If you're using a fixed perspective (no rotation or parallax) then it should be as simple as clipping to the coordinates of the tile that the player is over.
By jlnr (dev)
Date 2011-01-15 03:38
Is the box a pixel-perfect rectangle? Then you could draw the shadow on the floor, draw the box, clip to the box' top plane and draw the shadow again with an offset?
Maybe I am getting the situation wrong though :)
I had the exact same idea. The problem with this is that it starts to get weird when you have non-rectangular objects, doesn't it? For now I'm simply using pixel-perfect rectangles, but I wanted to be able to expand beyond that and have various sorts of buildings and such.
I think for some reason I thought that it would get to expensive to draw the shadow on the floor and then draw tho box on top of it. Perhaps I just don't know what I'm talking about ^.^;
Also, I had somehow thought that this would require some odd coding flow, but I suppose simply using the z-index would take care of ordering the drawing.
Am I just over thinking this? That does tend to happen every so often...
By jlnr (dev)
Date 2011-01-15 09:31
As long as you have rectangles (or objects that can be approximated using a few rectangles), the actual clipping and drawing will not be a problem. The Ruby overhead to find these rectangles is probably worse :)
If you want to render onto other images, that is not only tough in Gosu but probably OpenGL too. I imagine it's possible with stencil buffers, but designing around the issue would be the smoothest solution in any case.
Actually, as a result of the way I have the Chipmunk integrating going in my game, finding the rectangles is fairly trivial.
Alright then, I'll just try to avoid this problem for now. Thanks for the help. I'll try to look into stencil buffers later on.