Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-15-2011, 02:03 PM   #1 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 90
SeanyK is on a distinguished road
Default Rain / Snow falling how do you make it repeat?

Hey all,

I have created a basic rain falling type-animation;

However, when the objects falls to the bottom of the screen, it simply dissapears, how would I make this just repeat when it goes off the screen?

ie if you image it was an image of raindrops falling, I want it to then start again when it hits the bottom of the screen...

Hope this makes sense!

I currently use;

Code:
{
- (void)viewDidLoad
   
{
 moveObjectTimer = [NSTimer scheduledTimerWithTimeInterval:0.01 target:self selector:@selector (moveObject) userInfo:nil repeats:YES];

    [super viewDidLoad];
    
}

- (void) moveObject {    
   
    image.center = CGPointMake(image.center.x, image.center.y +5); 
    
}
SeanyK is offline   Reply With Quote
Old 12-15-2011, 02:12 PM   #2 (permalink)
Registered Member
 
mediaspree's Avatar
 
Join Date: Sep 2011
Posts: 179
mediaspree is on a distinguished road
Default

psuedo code:

- (void) moveObject {

image.center = CGPointMake(image.center.x, image.center.y +5);

if (image.center.y > someYvalue) {
image.center.y=0;

}

}
mediaspree is offline   Reply With Quote
Old 12-15-2011, 02:22 PM   #3 (permalink)
Registered Member
 
Join Date: Dec 2011
Posts: 3
leormagal is on a distinguished road
Default

You should check the frame origin x and y. If the values are greater than you screen size, set them zero.

Code:
if (image.frame.origin.x > self.view.frame.size.width) {
CCGRect rect = image.frame;
rect.origin.x = 0.0f;
image.frame = rect;
}

if (image.frame.origin.y > self.view.frame.size.heigth) {
CCGRect rect = image.frame;
rect.origin.y = 0.0f;
image.frame = rect;
}
To do the animations, I would use the code bellow:

Code:
while(should_continue_animating) {
[UIView animateWithDuration:0.1 
                              delay:0.0 
                            options:(UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionCurveLinear) animations:^{ 
                                
                                image.center = CGPointMake(image.center.x, image.center.y +5);
                                
                                ;}
                         completion:^(BOOL finished)
         { 

if (image.frame.origin.x > self.view.frame.size.width) {
CCGRect rect = image.frame;
rect.origin.x = 0.0f;
image.frame = rect;
}

if (image.frame.origin.y > self.view.frame.size.heigth) {
CCGRect rect = image.frame;
rect.origin.y = 0.0f;
image.frame = rect;
}
}];
}

Last edited by leormagal; 12-15-2011 at 02:29 PM. Reason: improving animation
leormagal is offline   Reply With Quote
Old 12-15-2011, 02:22 PM   #4 (permalink)
Registered Member
 
Join Date: Apr 2010
Posts: 90
SeanyK is on a distinguished road
Default

Leor, that works absolutely perfectly,

Thank you so much for your help.
SeanyK is offline   Reply With Quote
Old 12-15-2011, 02:53 PM   #5 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by SeanyK View Post
Leor, that works absolutely perfectly,

Thank you so much for your help.

The approach the other posters have outlined is good, as far as it goes.

However, you should not do animation the way you are doing it.

You should use core animation to set up an animation that moves your snowflakes from the top to the bottom of the screen in 1 step. The system will take care of animating the motion. It will be smoother than moving the views yourself, it will be less prone to problems if your program gets busy doing something else, and it will put a MUCH smaller load on the system, because it uses the graphics hardware to do the animation, and it uses highly optimized system frameworks to do the animation.

Take a look at the UIView animation class methods who's names start with animateWithDuration.

You probably want animateWithDuration:delayptions:animations:compl etion:

That method will let you specify that you want linear animation (options = UIViewAnimationOptionCurveLinear) , and will also let you include a completion routine that will start the animation over once the objects reach the bottom of the screen.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 02-07-2012, 09:43 AM   #6 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 16
sandromandro is on a distinguished road
Default

Hey, I have a question, if i paste it in my project with my image names in my
-(void) moveObjekt.
i have an error: "Use of undeclared identifier 'should_continue_animation'"


please help me
sandromandro is offline   Reply With Quote
Old 02-07-2012, 10:47 AM   #7 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by sandromandro View Post
Hey, I have a question, if i paste it in my project with my image names in my
-(void) moveObjekt.
i have an error: "Use of undeclared identifier 'should_continue_animation'"


please help me
Post a new thread.

Include the relevant code. You're saying that you have a method moveObjekt, but did not show that code. It sounds like that method tries to use a boolean should_continue_animation, but we don't know what that is.

Again, create a new thread with your specific question and the background info we need to help you.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Old 02-07-2012, 11:22 AM   #8 (permalink)
Registered Member
 
Join Date: Feb 2012
Posts: 16
sandromandro is on a distinguished road
Default

My code is:
Quote:
- (void)viewDidLoad
{
ObjektTimer = [NSTimer scheduledTimerWithTimeInterval:0.035 target:self selector:@selector(movepicture) userInfo:nil repeats:YES];
[super viewDidLoad];
}

-(void) movepicture{
while (should_continue_animating) {
[UIView animateWithDuration:0.1
delay:0.1
optionsUIViewAnimationOptionAllowUserInteraction |UIViewAnimationOptionCurveLinear) animations:^{

Menueball.center = CGPointMake(Menueball.center.x, Menueball.center.y +1);

;}
completion:^(BOOL finished)
{

if (Menueball.frame.origin.x > self.view.frame.size.width) {
CGRect rect = Menueball.frame;
rect.origin.x = 0.0f;
Menueball.frame = rect;
}

if (Menueball.frame.origin.y > self.view.frame.size.height) {
CGRect rect = Menueball.frame;
rect.origin.y = 0.0f;
Menueball.frame = rect;
}
}
];
}
}
and i have an error with "should_continue_animating"
what can i do?
please help me
i'm searching for a code to repeat this falling image, since a week
sandromandro is offline   Reply With Quote
Old 02-07-2012, 11:50 AM   #9 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,005
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by sandromandro View Post
My code is:


and i have an error with "should_continue_animating"
what can i do?
please help me
i'm searching for a code to repeat this falling image, since a week
You can create a new thread.

And use code tags rather than quotes to include code.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.
Duncan C is online now   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 397
13 members and 384 guests
7twenty7, AppsBlogger, Creativ, Dalia, David-T, Duncan C, HemiMG, heshiming, LunarMoon, Murphy, pbart, teebee74, Tomsky
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,915
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:49 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0