.net barcode generator code project 9: Particle Effects in Objective-C

Making Data Matrix 2d barcode in Objective-C 9: Particle Effects

CHAPTER 9: Particle Effects
Data Matrix Creator In Objective-C
Using Barcode drawer for iPhone Control to generate, create Data Matrix 2d barcode image in iPhone applications.
www.OnBarcode.com
Encoding EAN 128 In Objective-C
Using Barcode generation for iPhone Control to generate, create UCC-128 image in iPhone applications.
www.OnBarcode.com
There s only one type of effect that can t be moved, and these are one-time effects like the CCParticleExplosion shown in Figure 9 1. What s special about this effect is that it emits all its particles at once and then just stops emitting. All other particle effects run continuously, always creating new particles while those that have exceeded their lifetime are removed. The challenge in that situation is to balance the total number of particles that are on screen.
Drawing Barcode In Objective-C
Using Barcode generation for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Code 39 Maker In Objective-C
Using Barcode creation for iPhone Control to generate, create ANSI/AIM Code 39 image in iPhone applications.
www.OnBarcode.com
Figure 9 1. The CCParticleExplosion is an example effect provided by cocos2d.
GTIN - 12 Encoder In Objective-C
Using Barcode creation for iPhone Control to generate, create GS1 - 12 image in iPhone applications.
www.OnBarcode.com
Generate Barcode In Objective-C
Using Barcode maker for iPhone Control to generate, create Barcode image in iPhone applications.
www.OnBarcode.com
Listing 9 1 shows the relevant methods used in the ParticleEffects01 example project. By using the current particleType variable in the switch statement, the corresponding built-in particle effect is created. Note that a CCParticleSystem pointer is used to store the particles, so I only need to use the addChild code once at the end of the runEffect method. Every example particle effect is derived from CCParticleSystem.
Data Matrix ECC200 Creator In Objective-C
Using Barcode printer for iPhone Control to generate, create Data Matrix ECC200 image in iPhone applications.
www.OnBarcode.com
Universal Product Code Version E Creation In Objective-C
Using Barcode creator for iPhone Control to generate, create GTIN - 12 image in iPhone applications.
www.OnBarcode.com
Listing 9 1. Using the Built-in Effects -(void) runEffect { // remove any previous particle FX [self removeChildByTag:1 cleanup:YES]; CCParticleSystem* system; switch (particleType) { case ParticleTypeExplosion: system = [CCParticleExplosion node]; break; case ParticleTypeFire: system = [CCParticleFire node]; break; case ParticleTypeFireworks: system = [CCParticleFireworks node]; break; case ParticleTypeFlower: system = [CCParticleFlower node]; break; case ParticleTypeGalaxy: system = [CCParticleGalaxy node]; break;
Data Matrix ECC200 Scanner In VB.NET
Using Barcode reader for VS .NET Control to read, scan read, scan image in .NET framework applications.
www.OnBarcode.com
Printing DataMatrix In None
Using Barcode drawer for Font Control to generate, create Data Matrix ECC200 image in Font applications.
www.OnBarcode.com
CHAPTER 9: Particle Effects
EAN-13 Supplement 5 Drawer In Visual Studio .NET
Using Barcode encoder for Reporting Service Control to generate, create European Article Number 13 image in Reporting Service applications.
www.OnBarcode.com
UPC-A Decoder In .NET
Using Barcode reader for Visual Studio .NET Control to read, scan read, scan image in .NET applications.
www.OnBarcode.com
case ParticleTypeMeteor: system = [CCParticleMeteor node]; break; case ParticleTypeRain: system = [CCParticleRain node]; break; case ParticleTypeSmoke: system = [CCParticleSmoke node]; break; case ParticleTypeSnow: system = [CCParticleSnow node]; break; case ParticleTypeSpiral: system = [CCParticleSpiral node]; break; case ParticleTypeSun: system = [CCParticleSun node]; break; default: // do nothing break; } [self addChild: system z:1 tag:1]; [label setString:NSStringFromClass([system class])]; } -(void) setNextParticleType { particleType++; if (particleType == ParticleTypes_MAX) { particleType = 0; } }
Barcode Maker In None
Using Barcode maker for Excel Control to generate, create Barcode image in Office Excel applications.
www.OnBarcode.com
QR Code 2d Barcode Creator In Java
Using Barcode printer for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
NOTE: The NSStringFromClass method is very helpful in this example for printing out the name of the class without having to enter dozens of matching strings. It s one of the cool runtime features of the Objective-C language that you re able to get a class s name as a string. Try to do that in C++ and you ll be biting your toenails. For gameplay code, the NSStringFromClass and related methods hardly play any role, but they re very helpful debugging and logging tools. You can find a complete list and description of these methods in Apple s Foundation Function Reference: http://developer.apple.com/ mac/library/documentation/Cocoa/Reference/Foundation/Miscellaneous/Found ation_Functions/Reference/reference.html. If you use one of these example effects in your own project, you might be shocked to see ugly, square pixels. Figure 9 2 shows this effect very clearly. This occurs because the built-in particle effects try to load a specific texture named fire.png, which is
Paint EAN13 In None
Using Barcode creator for Online Control to generate, create EAN13 image in Online applications.
www.OnBarcode.com
Print European Article Number 13 In Visual Studio .NET
Using Barcode generation for Visual Studio .NET Control to generate, create GTIN - 13 image in Visual Studio .NET applications.
www.OnBarcode.com
CHAPTER 9: Particle Effects
Generate UCC - 12 In Java
Using Barcode maker for BIRT reports Control to generate, create GS1 128 image in BIRT reports applications.
www.OnBarcode.com
Data Matrix 2d Barcode Generator In None
Using Barcode maker for Software Control to generate, create Data Matrix image in Software applications.
www.OnBarcode.com
distributed with cocos2d-iphone in the Resources/Images folder. You can still create very good particle effects even without a texture, provided that the particle sizes remain fairly small. But to see the built-in particle effects as they were intended, you need to add the fire.png image to your Xcode project.
Barcode Encoder In None
Using Barcode creation for Microsoft Excel Control to generate, create Barcode image in Excel applications.
www.OnBarcode.com
PDF-417 2d Barcode Generator In None
Using Barcode creator for Font Control to generate, create PDF 417 image in Font applications.
www.OnBarcode.com
Figure 9 2. If your example particle effects, like this CCParticleFireworks, display huge, square particles, you forgot to add the fire.png image to your Xcode project.
Creating a Particle Effect the Hard Way
You can easily create your own subclass of the CCParticleSystem class. What s not so easy is creating a convincing particle effect with it, let alone one that comes close to what you originally envisioned. Following is the list of properties grouped by function that determine the particle system s look and behavior: emitterMode = gravity gravity, centerOfGravity radialAccel, radialAccelVar speed, speedVar tangentialAccel, tangentialAccelVar emitterMode = radius startRadius, startRadiusVar, endRadius, endRadiusVar rotatePerSecond, rotatePerSecondVar duration posVar positionType startSize, startSizeVar, endSize, endSizeVar angle, angleVar life, lifeVar
CHAPTER 9: Particle Effects
emissionRate startColor, startColorVar, endColor, endColorVar blendFunc, blendAdditive texture As you can imagine, there s a lot to tweak here. And, of course, there s a lot to understand in the first place about what each of these properties do. Let s start at the beginning, which requires creating a new class derived from CCParticleSystem. Actually, you should subclass either from CCPointParticleSystem or from CCQuadParticleSystem. Point particles are a bit faster on first- and second-generation iOS devices but don t perform well on third- and fourth-generation devices like the iPhone 3GS, iPad, and iPhone 4. This is due to the change in CPU architecture. The ARMv7 CPU architecture used in third- and fourth-generation devices introduced optimizations and new features, such as a vector floating-point processor and a SIMD instruction set (NEON), and the CCQuadParticleSystem takes advantage of these. If in doubt, use the CCQuadParticleSystem since it performs well on all devices and creates exactly the same visual effects. Or let cocos2d make that decision for you based on the build target. You ll see how in the ParticleEffectSelfMade file I ve added to the ParticleEffects02 project, shown in Listing 9 2.
Listing 9 2. Subclassing from the Optimal Particle System Class #import <Foundation/Foundation.h> #import "cocos2d.h" // Depending on the targeted device the ParticleEffectSelfMade class will either derive // from CCPointParticleSystem or CCQuadParticleSystem @interface ParticleEffectSelfMade : ARCH_OPTIMAL_PARTICLE_SYSTEM { } @end
The preprocessor definition ARCH_OPTIMAL_PARTICLE_SYSTEM, instead of an actual class name, is used to determine during compilation which of the two particle systems this class should subclass from. The definition in cocos2d is based on the processor architecture and results either in a CCQuadParticleSystem or CCPointParticleSystem:
// build each architecture with the optimal particle system #ifdef __ARM_NEON__ // armv7 #define ARCH_OPTIMAL_PARTICLE_SYSTEM CCQuadParticleSystem #elif __arm__ || TARGET_IPHONE_SIMULATOR // armv6 or simulator #define ARCH_OPTIMAL_PARTICLE_SYSTEM CCPointParticleSystem #else #error(unknown architecture) #endif
Now let s look at the implementation of the self-made particle effect, which uses all available properties. I ll attempt to explain each of them, but it s much better to see it for yourself and experiment with the parameters, so I encourage you to tweak the
Copyright © OnBarcode.com . All rights reserved.