• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Making a snow flake fall

 
Ranch Hand
Posts: 50
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 5465
212
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Bartender
Posts: 5465
212
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, a List is an interface, and an ArrayList is an impementation. It resizes the underlying array, if necessary.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic