Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

My current project, using Java and OpenGL, has a fairly standard overhead tilemap in the style of the Zelda games.

I'd really like to add "real" grass to the grass tiles so that there are actually blades that can sway in the wind and maybe, if possible, react to the player's movement as well. I'm figuring that since this is only in 2D, a rather striking effect should be possible without much performance hit.

What possible algorithms are there for rendering dynamic 2D grass? If possible, I'd like to keep the effect strictly 2D--i.e., I don't want to render actually 3D grass, as it would break the artistic design of the world.

share|improve this question
up vote 6 down vote accepted

I would make an animation sprite map for the grass. This way you can apply a scene wide call (atleast all visible grass in the scene) to have them randomly go through their animation to make it look like the wind sparsely gusts through the scene. Just have a loopable animation setup for the grass and play them at different speeds and randomly to get the effect. You can also use this to interact with the player by determining which way the player is walking over the grass and play the animation in that direction. This is definitely a high level answer and would require a bit of figuring out to completely hash this idea out.

You could even save on space if you want to. Have a middle position that the grass sits straight up. Have a blowing to the right animation. Then if you want it to blow to the left, smoothly move the animation towards the center and flip the sprite then play the same animation.

share|improve this answer
This could work and probably wouldn't be too hard. One issue I foresee is making the grass show up behind or in front of the player, since it would be pre-drawn in chunks the size of tiles. – Zach Conn Apr 26 '11 at 4:05
just add an alpha layer to the tiles. if you want it in front of the player give it a higher z index. if you want it lower, give it a lower index. the rendering order of this should not be related to this approach. since it's an animated sprite, treat each frame of the animation as one entity and set it's z-order to be the same in every frame unless explicitly told to change. Most engines handle this anyway. – brandon Apr 26 '11 at 4:12
What I mean is that the grass won't be able to smoothly transition from being in front of to behind the player or vice versa. When standing on a tile, either all the grass is in front or it's all behind, whereas ideally some blades would be in front and others would be behind, and the individual blades would get pushed to the side as the player moves up or down, allowing them to smoothly slide between sides. – Zach Conn Apr 26 '11 at 4:20
you can do little tricks like having a very sparse version of the grass that fades in only when the player is standing on the tile. This is a common problem of transitioning tiles in any 2d game. Less of a technical challenge, more of a how can I work with these logical constraints and make it look good. Fading in a sparse version of the sprite is probably the most known way I know of. To the player it may be obvious that it faded in after they walked on it. But if they notice that, they will notice the logical constraint posed by having multi layer sprites – brandon Apr 26 '11 at 4:26

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.