• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Making a snow flake fall

 
Christopher McKay
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have made a class (snowflake) which extends android ImageView, this is what is in it:



then in my main class, I create an instance of snowflake when the screen is touched:



I know that this is android, but this question isn't exactly android related, my question is, how do I make the snow fall to the bottom of the screen. I have tried a for loop, but the snow instantly appears at the bottom of the screen. Help would be very much appreciated!
 
Piet Souris
Rancher
Posts: 1540
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Christopher,

I know nothing about Android, but in a Java program I would do a thing like this:

1) have a Timer object fire every so much milliseconds
2) then call an 'updatePanel/Frame/whatever() method
3) in this method, you update the Y-values of every snowflake you have. Maybe even some
random disturbance of the X values.
4) do the repaint()

But, I don't know if Android works in a similar fashion.

Greetings,
Piet
 
Christopher McKay
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:hi Christopher,

I know nothing about Android, but in a Java program I would do a thing like this:

1) have a Timer object fire every so much milliseconds
2) then call an 'updatePanel/Frame/whatever() method
3) in this method, you update the Y-values of every snowflake you have. Maybe even some
random disturbance of the X values.
4) do the repaint()

But, I don't know if Android works in a similar fashion.

Greetings,
Piet


The problem is, the snowfake 'id' if you will, is lost after the user touches the screen again. e.g. I am basically just calling determining what snowflake is what to set the Y of them might be impossible/difficult.
 
Piet Souris
Rancher
Posts: 1540
33
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can't you add the newly created snowflake to some ArrayList of snowflakes
before adding it to the layout?

But, I guess it is time for an Android expert. Hope someone will step in.

Greetz,
Piet

 
Christopher McKay
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Piet Souris wrote:Can't you add the newly created snowflake to some ArrayList of snowflakes
before adding it to the layout?

But, I guess it is time for an Android expert. Hope someone will step in.

Greetz,
Piet



Ofcourse, I was thinking of using arrays, but I never thought of using arraylists. It has been a while since I used them, is the difference between lists and arrays that you can add and remove from arraylists and it resizes the array?
 
Piet Souris
Rancher
Posts: 1540
33
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, a List is an interface, and an ArrayList is an impementation. It resizes the underlying array, if necessary.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic