Very specific sprite transformation

Hi everyone,
I was wondering if it is possible to do a very specific in-game sprite transformation: bending a sprite. Imagine a tree in the wind. You'd want the top half part to gradually rotate with the wind, but not the base. The only good example I can think of is when you hit a tree with an axe in stardew valley. Only the top parts seem to be manipulated. I really want to include a ''storm wind'' effect to the trees in my game, but I don't want to draw each individual frame. I'd love to code a script of sorts, that could rotate the top half by 1 degree for example. The top quarter rotates an extra degree. The top eight part rotates another, and so on. This would create an illusion of an object bending only on its top part.
 

obscene

Member
The best way to do this is to use something like Spine which supports "freeform deformation" which does exactly what you are talking about. These animations can be imported directly into GM. However it's not free.

Alternatively, you can break the tree trunk into segments and then move each segment by a degree more than the one below it.

The final way would be to create a textured primitive, which is basically what Spine is doing but you'll have do all the leg work....

 
It would be a lot less complicated if the whole tree rotated by the same amount. And it would probably look more accurate to what you see in reality.
Yeah I can actually do that, but the very bottom (not just the bottom ''half'') rotates as well. It's that small part, basically the bottom line pixels, that I want to stay in their place. For that, I'd need something like ''fractional rotation'' as I've described
 
The best way to do this is to use something like Spine which supports "freeform deformation" which does exactly what you are talking about. These animations can be imported directly into GM. However it's not free.

Alternatively, you can break the tree trunk into segments and then move each segment by a degree more than the one below it.

The final way would be to create a textured primitive, which is basically what Spine is doing but you'll have do all the leg work....

I'm gonna look into this, even if I can't use it I might learn something about animation :)
 
If your trees don't change over time (besides a deterministic swaying), then a vertex buffer and shader can produce a swaying tree effect with great efficiency.
They don't in fact, just the sprites I've drawn and nothing else. Can you point me towards such a vertex buffer, or at least a decent tutorial on vertex buffers in general? I really want to have a cool weather effect without the need to re-draw. Besides, what if I want to use it somewhere else too right? It's more efficient to learn a system instead of redrawing frames each time :p
 
Actually, I've just been setting up a basic example for you. It was made in gms1, but it should also work if you import it into gms2.

https://www.dropbox.com/s/g19oxf6sj3f20wh/Tree_Sway.gmz?dl=0

Rather than have the trees rotate, I just made the top move along the x axis. It seems good enough to me, but if you wanted to, you could do it differently. You could an additional shader uniform to control the strength of the wind.

EDIT: Be sure to use vertex_delete_buffer() when you no longer need a vertex buffer.
 
Last edited:
Actually, I've just been setting up a basic example for you. It was made in gms1, but it should also work if you import it into gms2.

https://www.dropbox.com/s/g19oxf6sj3f20wh/Tree_Sway.gmz?dl=0

Rather than have the trees rotate, I just made the top move along the x axis. It seems good enough to me, but if you wanted to, you could do it differently. You could an additional shader uniform to control the strength of the wind.

EDIT: Be sure to use vertex_delete_buffer() when you no longer need a vertex buffer.
I have gms2, I'll check this out. Right now I'm not at home, but dude you really don't don't need to create an example just for me :p I'm really beginning to like this community, hot damn!
 
Actually, I've just been setting up a basic example for you. It was made in gms1, but it should also work if you import it into gms2.

https://www.dropbox.com/s/g19oxf6sj3f20wh/Tree_Sway.gmz?dl=0

Rather than have the trees rotate, I just made the top move along the x axis. It seems good enough to me, but if you wanted to, you could do it differently. You could an additional shader uniform to control the strength of the wind.

EDIT: Be sure to use vertex_delete_buffer() when you no longer need a vertex buffer.
duuuude I can't thank you enough for this, this is EXACTLY what I wanted. The wind effect looks freaking GOOD.
 
There's something important I forgot to mention. I used "current_time" as a basis for the "time" uniform. But you probably wont want to do that. The reason is current_time wont work well if you need to pause your game. So it would probably be better to use a variable that you increment each step.
 
Top