📄 animatables.m
字号:
#import <CoreFoundation/CoreFoundation.h>#import <Foundation/Foundation.h>#import <UIKit/CDStructures.h>#import <UIKit/UIWindow.h>#import <UIKit/UIView-Hierarchy.h>#import <UIKit/UIHardware.h>#import <UIKit/UIKit.h>#import <UIKit/UIApplication.h>#import <UIKit/UITextView.h>#import <UIKit/UIView.h>#import <UIKit/UIKeyboard.h>#import <UIKit/UIBox.h>#import <Celestial/AVItem.h>#import <Celestial/AVController.h>#import <Celestial/AVQueue.h>
#import <math.h>
#import "Animatables.h"
@implementation Animatable- (BOOL)tick { dormant=YES; return NO;}- (BOOL)dormant { return dormant;}@end
@implementation Reward
- (id) initWithImage: (UIImage *) img X: (float)x Y: (float)y view: (UIView *)v{
[super initWithImage: img];
[v addSubview: self];
view = v;
posx = x - 75;
posy = y - 20;
life = 1;
[self tick];
dormant=NO;
return self;
}
- (BOOL) tick {
float scale = 1, alpha;
posy -= 1;
alpha = life * 4;
if (alpha > 1) alpha = 1;
scale = (0.5 - life) * 4;
if (scale < 1) scale = 1;
[self setAlpha: alpha];
[self setTransform: CGAffineTransformScale(CGAffineTransformMakeTranslation(posx, posy), scale, scale)];
//NSLog(@"Tick: %f,%f alpha %f scale %f", posx, posy, alpha, scale);
life *= 0.95;
if (life < 0.05) {
dormant=YES;
[self removeFromSuperview];
return NO;
}
return YES;
}
@end
UIImage * particleImage = nil;
@implementation Particle
- (id) initWithX: (float)x Y: (float)y view: (UIView *)v {
if (!particleImage) {
particleImage = [[UIImage alloc] initWithContentsOfFile: @"spark.png"];
srand(time(NULL));
}
[super initWithImage: particleImage];
[v addSubview: self];
posx = x;
posy = y;
velx = ((rand() % 100) - 50) / 13.0;
vely = ((rand() % 100) - 75) / 10.0;
life = 1;
return self;
}
- (BOOL) tick {
posx += velx;
posy += vely;
vely += 0.08;
vely *= 0.97;
float scale = 1, alpha;
alpha = life * 4;
if (alpha > 1) alpha = 1;
scale = (0.5 - life) * 4;
if (scale < 1) scale = 1;
[self setAlpha: alpha];
[self setTransform: CGAffineTransformScale(CGAffineTransformMakeTranslation(posx, posy), scale, scale)];
life *= 0.95;
if (life < 0.05) {
[self removeFromSuperview];
return NO;
}
return YES;
}
@end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -