Re: Smooth Animation
Re: Smooth Animation
- Subject: Re: Smooth Animation
- From: Nicko van Someren <email@hidden>
- Date: Sat, 12 Jun 2004 09:57:08 +0100
Rhon,
One enhancement you might like to consider is to move the
windowAlphaCurrentIncrement into the object and also record the time at
which the current fade started in some instance variable. In the
changeTransparency method look to see how long it has been since you
started the fade and adjust the transparency according to how long it
has been since the fade started.
The point of this is that there is no guarantee that timers will go
off when you asked, only that they won't go off before that requested
time. If your computer is slow and busy doing other things the timer
events may be delayed and the fade will take much longer than expected.
By setting the transparency level according to how long it has been
since the fade started your fades will always take about the same
amount of time and if your computer is being slow it will simply take
fewer steps.
Of course you might think that this is too much hassle, in which case
don't bother :-)
Nicko
On 12 Jun 2004, at 2:01, Rhon Fitzwater wrote:
Your solution worked perfect. Couldnt have asked for more. Many
thanks.
-Rhon
On Jun 11, 2004, at 8:50 PM, Daniel Waylonis wrote:
On Jun 11, 2004, at 4:25 PM, Rhon Fitzwater wrote:
Right now I have my window so its alpha setting is set to 1.0 when
the mouse enters the window and 0.2 when the mouse exits, using this
code:
//mouse entered exited window code below
- (void)viewDidMoveToWindow {
[self addTrackingRect:[self frame] owner:self userData:nil
assumeInside:NO];
[super viewDidMoveToWindow];
}
- (void)mouseEntered:(NSEvent *)event {
NSLog(@"Mouse Entered");
[[self window] setAlphaValue:1.0];
}
- (void)mouseExited:(NSEvent *)event {
NSLog(@"Mouse Exited");
[[self window] setAlphaValue:0.2];
}
//end of mouse entered or exited window code
What I want to know how to do is make the transition between alpha
settings smooth. gradually increase or decrease alpha settings. Can
someone tell me how this can be done, possible with some coding
examples?
Hi Rhon,
Try this:
- (void)viewDidMoveToWindow {
[self addTrackingRect:[self frame] owner:self userData:nil
assumeInside:YES];
[super viewDidMoveToWindow];
}
static float windowAlphaIncrement = 0.15;
static float windowAlphaCurrentIncrement;
static float windowAlphaMin = 0.2;
static float windowAlphaMax = 1.0;
static float windowAlphaFadeRate = 1.0 / 15.0;
- (void)changeTransparency:(NSTimer *)timer
{
float alpha = [[self window] alphaValue];
BOOL reschedule = NO;
alpha += windowAlphaCurrentIncrement;
// Reschedule timer if we haven't reached desired value
if (windowAlphaCurrentIncrement > 0)
{
if (alpha < windowAlphaMax)
reschedule = YES;
else
alpha = windowAlphaMax;
}
else
{
if (alpha > windowAlphaMin)
reschedule = YES;
else
alpha = windowAlphaMin;
}
if (reschedule)
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
target:self selector:@selector(changeTransparency:) userInfo:nil
repeats:NO];
[[self window] setAlphaValue:alpha];
}
- (void)mouseEntered:(NSEvent *)event {
NSLog(@"Mouse Entered");
windowAlphaCurrentIncrement = windowAlphaIncrement;
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
target:self selector:@selector(changeTransparency:) userInfo:nil
repeats:NO];
}
- (void)mouseExited:(NSEvent *)event {
NSLog(@"Mouse Exited");
windowAlphaCurrentIncrement = -windowAlphaIncrement;
[NSTimer scheduledTimerWithTimeInterval:windowAlphaFadeRate
target:self selector:@selector(changeTransparency:) userInfo:nil
repeats:NO];
}
Dan
_________________________________________________
Dan Waylonis email@hidden
Software Engineer http://www.nekotech.com
nekotech SOFTWARE 650.964.2490 (O)
[demime 0.98b removed an attachment of type
application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.