With the help of the thread RandomRocks I was able to create an application which creates multiple instances of snowflakes and animates them on the screen.
Unfortunately, the movements of the snowflakes seem a bit mechanic. Here is the code I use so far
With the help of the thread RandomRocks I was able to create an application which creates multiple instances of snowflakes and animates them on the screen.
Unfortunately, the movements of the snowflakes seem a bit mechanic. Here is the code I use so far
When I decrease the timer value, the snowflakes move smoother but also faster. How would I make them move slowly but smooth?
Find the line in your code that alters the position of the flakes (to achieve the "falling" animation effect), then tweak that line and observe how changing the value one way or the other affects the visual appearance of the falling speed.
-(void)moveSnowFlakes{
for (UIImageView *snow in snowArray) {
CGPoint newCenter = snow.center;
newCenter.y = newCenter.y +2;
int leftOrRight = arc4random() % 4;
if (leftOrRight == 0) {
// left
newCenter.x = newCenter.x - 1;
} else {
newCenter.x = newCenter.x + 1;
}
}
So every frame your flakes can reverse horizontal direction? That could make the movement look really jerky. Try assigning an x-velocity to each flake at creation and keeping it constant, or changing it less frequently.
I changed the line that moved the flakes down 2 pixels to moving them down only 1 pixel. It was a bit smoother but still didn't feel natural.
Then I figured out, that snowflakes actually don't change their direction every 2nd or 3rd pixel which was the reason why it all seemed a bit off.
I now simply store the direction each flake is going (left or right) .. I then configured the chance of a flake changing it's direction to about 5-10% and now it all seems exactly the way it should be.
Funny..first I thought I'm missing some magical paramter on how to smoothen image movements programmatically, but I actually didn't really think about how snow flakes move in real life.
So every frame your flakes can reverse horizontal direction? That could make the movement look really jerky. Try assigning an x-velocity to each flake at creation and keeping it constant, or changing it less frequently.
Yep, that's exactly what happened / made it look unnatural.
the most efficient way to handle this is inside a vertex shader.
but if you're on gles1, then the cpu must do it. The trick is to alter acceleration randomly at random intervals with seemingly no pattern.
define a struct or class for snowflake, containing x,y (and z if 3d) position. Initialize them within a random floating point range to fill your screen, random velocity (dx, dy dz), and random acceleration (ddx, ddy, ddz), the acceleration range should be small as it will quickly move your flakes. Lastly define a random time within say 0.1 to 0.5 seconds for the "shift"
Now during processing/update method, loop through all the flakes doing an x+=dx*delta and dx+=ddx*delta for each x,y,z of the flake, and a time -= delta where delta is the time between animation frame updates in seconds. If time goes negative, reinitialize the flake's acceleration like above with random values only and set a new timeout. Lastly if a flake falls down off the screen, respawn it at the top
IMO, at this introductory level, dealing with an acceleration vector as part of the equation is beyond the scope of what needs to be learned. Besides, aren't snowflakes and raindrops already at terminal velocity by the time they reach the surface of the Earth?
IMO, at this introductory level, dealing with an acceleration vector as part of the equation is beyond the scope of what needs to be learned. Besides, aren't snowflakes and raindrops already at terminal velocity by the time they reach the surface of the Earth?
its not about realism, its about gameism :-). If it looks cool, then do it
its not about realism, its about gameism :-). If it looks cool, then do it
Quote:
Originally Posted by ZunePod
Also, if there is a lot of wind, it can give the effect that snow is falling faster.
As a game developer, I totally get it. My point is that for the newb who hasn't quite got hold of the basics to get things moving in the first place, the introduction of an acceleration vector will only complicate things. Let's help the OP get walking before asking them to run the 100m hurdles...
As a game developer, I totally get it. My point is that for the newb who hasn't quite got hold of the basics to get things moving in the first place, the introduction of an acceleration vector will only complicate things. Let's help the OP get walking before asking them to run the 100m hurdles...