ネタが無いので、パクリました。_( TxT)_
Emitting (発光 by Google 翻訳先生) のパクリネタ
本家を読んでくださいね。
パクリ元
UIKit Particle System in iOS 5 Tutorial
参考という名目のパクリ元
CAEmitterLayer and CAEmitterCellアップるぅぅぅの記事ですよね
その他ぽいの
プロパティの説明
birthRate | 毎秒どれくらいオブジェクトを作るか |
lifetime | セルのライフタイム |
color | tint 色合いを設定 |
contents | CGImageRef を設定 |
Layer は emitterShape と emitterPosition を設定するくらいでしょうか
emitterShape | オブジェクトの作成方法を設定 |
動かすとこんな感じ
使った適当な画像はこれです
ソース
ファイルのコメント的にはコピペはOKそうだったのですが。
問題ありましたらご指摘ください
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// DSAppDelegate.m | |
// DrawSmoke | |
// | |
// Created by developer on 12/03/27. | |
// Copyright (c) 2012 your good mind. All rights reserved. | |
// | |
#import "DSAppDelegate.h" | |
#import <QuartzCore/QuartzCore.h> | |
#if __has_feature(objc_arc) | |
#define ARC_ON | |
#define AUTORELEASE(A) A | |
#define RETAIN(A) A | |
#define RELEASE(A) | |
#else | |
#define ARC_OFF | |
#define AUTORELEASE(A) [A autorelease] | |
#define RETAIN(A) [A retain] | |
#define RELEASE(A) [A release] | |
#endif | |
// | |
// SmokeView | |
// | |
@interface DSSmokeView : UIView | |
@end | |
@implementation DSSmokeView | |
-(id) initWithFrame:(CGRect)frame { | |
if ((self = [super initWithFrame:frame]) != nil) { | |
CAEmitterLayer* fireEmitter = (CAEmitterLayer*)self.layer; | |
fireEmitter.emitterPosition = CGPointMake(self.bounds.size.width/2, self.bounds.size.height); | |
fireEmitter.emitterMode = kCAEmitterLayerSurface; //kCAEmitterLayerOutline; | |
fireEmitter.emitterShape = kCAEmitterLayerLine; // kCAEmitterLayerSphere; kCAEmitterLayerCircle; kCAEmitterLayerPoint; | |
fireEmitter.emitterSize = CGSizeMake(self.bounds.size.width/5,self.bounds.size.width/5 ); | |
float gas=.6; | |
CAEmitterCell *smoke = [CAEmitterCell emitterCell]; | |
smoke.BirthRate = 0;//11; | |
smoke.emissionLongitude = -M_PI ; | |
smoke.emissionLatitude = -M_PI; | |
smoke.lifetime = gas*4; | |
smoke.Velocity = 40; | |
smoke.VelocityRange = 20; | |
smoke.emissionRange = M_PI / 4; | |
smoke.Spin = 1; | |
smoke.SpinRange = 6; | |
smoke.yAcceleration = -160; | |
smoke.Scale = 0.3f; | |
smoke.AlphaSpeed = -0.22f; | |
smoke.ScaleSpeed = 0.7f; | |
smoke.color = [[UIColor colorWithRed:1 green:1 blue:1 alpha:0.3*gas] CGColor]; | |
smoke.contents = (id)[[UIImage imageNamed:@"smoke.png"] CGImage]; | |
[smoke setName:@"smoke"]; | |
fireEmitter.emitterCells = [NSArray arrayWithObject:smoke]; | |
} | |
return self; | |
} | |
+ (Class) layerClass { | |
//configure the UIView to have emitter layer | |
return [CAEmitterLayer class]; | |
} | |
-(void)setEmitterPositionFromTouch: (UITouch*)t { | |
CAEmitterLayer* smokeEmitter = (CAEmitterLayer*)self.layer; | |
//change the emitter's position | |
smokeEmitter.emitterPosition = [t locationInView:self]; | |
} | |
-(void)setIsEmitting:(BOOL)isEmitting { | |
CAEmitterLayer* smokeEmitter = (CAEmitterLayer*)self.layer; | |
//turn on/off the emitting of particles | |
[smokeEmitter setValue:[NSNumber numberWithInt:isEmitting?50:0] forKeyPath:@"emitterCells.smoke.birthRate"]; | |
} | |
@end | |
// | |
// ViewController | |
// | |
@interface DSViewController : UIViewController | |
@end | |
@implementation DSViewController | |
-(void) loadView { | |
CGRect screen = [[UIScreen mainScreen] bounds]; | |
DSSmokeView* smoke = [[DSSmokeView alloc] initWithFrame:screen]; | |
smoke.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight; | |
smoke.backgroundColor = [UIColor whiteColor]; | |
self.view = smoke; | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { | |
return YES; | |
} | |
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { | |
[(DSSmokeView*)self.view setEmitterPositionFromTouch: [touches anyObject]]; | |
} | |
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { | |
[(DSSmokeView*)self.view setEmitterPositionFromTouch: [touches anyObject]]; | |
[(DSSmokeView*)self.view setIsEmitting:YES]; | |
} | |
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { | |
[(DSSmokeView*)self.view setIsEmitting:NO]; | |
} | |
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { | |
[(DSSmokeView*)self.view setIsEmitting:NO]; | |
} | |
@end | |
// | |
// DSAppDelegate | |
// | |
// | |
// Header File | |
// #import <UIKit/UIKit.h> | |
// | |
// @interface DSAppDelegate : UIResponder <UIApplicationDelegate> | |
// | |
// @property (strong, nonatomic) UIWindow *window; | |
// | |
// @end | |
// | |
// | |
// | |
// | |
@implementation DSAppDelegate | |
@synthesize window = _window; | |
#ifdef ARC_OFF | |
- (void)dealloc { | |
[_window release]; | |
[super dealloc]; | |
} | |
#endif | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { | |
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; | |
self.window.rootViewController = AUTORELEASE([[DSViewController alloc] initWithNibName:nil bundle:nil]); | |
[self.window makeKeyAndVisible]; | |
return YES; | |
} | |
- (void)applicationWillResignActive:(UIApplication *)application {} | |
- (void)applicationDidEnterBackground:(UIApplication *)application {} | |
- (void)applicationWillEnterForeground:(UIApplication *)application {} | |
- (void)applicationDidBecomeActive:(UIApplication *)application {} | |
- (void)applicationWillTerminate:(UIApplication *)application {} | |
@end |