Skip to content

Commit 9c58b15

Browse files
committed
Merge pull request #17 from spritebuilder/effects
Effects - Added drop shadow effect (with blur).
2 parents dc6d8ce + 38b723e commit 9c58b15

File tree

10 files changed

+443
-2
lines changed

10 files changed

+443
-2
lines changed

Resources/Images/DistanceFieldX.png

2.26 KB
Loading

Resources/Images/Ohm.png

20.1 KB
Loading

cocos2d-ios.xcodeproj/project.pbxproj

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,12 @@
261261
B7EE69E31819E75700B983FE /* CCLayoutBox.m in Sources */ = {isa = PBXBuildFile; fileRef = B7EE69DF1819E75700B983FE /* CCLayoutBox.m */; };
262262
B7EE6A1E181AE34600B983FE /* CCSlider.h in Headers */ = {isa = PBXBuildFile; fileRef = B7EE6A1C181AE34600B983FE /* CCSlider.h */; };
263263
B7EE6A1F181AE34600B983FE /* CCSlider.m in Sources */ = {isa = PBXBuildFile; fileRef = B7EE6A1D181AE34600B983FE /* CCSlider.m */; };
264+
D208E79F1993FEDA00BD8D6B /* CCEffectDropShadow.m in Sources */ = {isa = PBXBuildFile; fileRef = D208E79C1993FEDA00BD8D6B /* CCEffectDropShadow.m */; };
265+
D208E7A01993FEDA00BD8D6B /* CCEffectDropShadow.m in Sources */ = {isa = PBXBuildFile; fileRef = D208E79C1993FEDA00BD8D6B /* CCEffectDropShadow.m */; };
266+
D208E7AD19959A4800BD8D6B /* CCEffectOuterGlow.h in Headers */ = {isa = PBXBuildFile; fileRef = D208E7AB19959A4800BD8D6B /* CCEffectOuterGlow.h */; };
267+
D208E7AE19959A4800BD8D6B /* CCEffectOuterGlow.h in Headers */ = {isa = PBXBuildFile; fileRef = D208E7AB19959A4800BD8D6B /* CCEffectOuterGlow.h */; };
268+
D208E7AF19959A4800BD8D6B /* CCEffectOuterGlow.m in Sources */ = {isa = PBXBuildFile; fileRef = D208E7AC19959A4800BD8D6B /* CCEffectOuterGlow.m */; };
269+
D208E7B019959A4800BD8D6B /* CCEffectOuterGlow.m in Sources */ = {isa = PBXBuildFile; fileRef = D208E7AC19959A4800BD8D6B /* CCEffectOuterGlow.m */; };
264270
D23C5CB4194BC108007CA669 /* CCTouchIOS.h in Headers */ = {isa = PBXBuildFile; fileRef = D23C5CB2194BC108007CA669 /* CCTouchIOS.h */; };
265271
D23C5CB5194BC108007CA669 /* CCTouchIOS.m in Sources */ = {isa = PBXBuildFile; fileRef = D23C5CB3194BC108007CA669 /* CCTouchIOS.m */; };
266272
D23C5CBC194BC500007CA669 /* CCTouchAndroid.h in Headers */ = {isa = PBXBuildFile; fileRef = D23C5CBA194BC500007CA669 /* CCTouchAndroid.h */; };
@@ -356,6 +362,8 @@
356362
D2DDB0A619805E8400233D80 /* CCQuaternion.m in Sources */ = {isa = PBXBuildFile; fileRef = D2DDB09119805E8400233D80 /* CCQuaternion.m */; };
357363
D2DDB0A719805E8400233D80 /* CCMatrix3.m in Sources */ = {isa = PBXBuildFile; fileRef = D2DDB09219805E8400233D80 /* CCMatrix3.m */; };
358364
D2DDB0A819805E8400233D80 /* CCMatrix3.m in Sources */ = {isa = PBXBuildFile; fileRef = D2DDB09219805E8400233D80 /* CCMatrix3.m */; };
365+
D2E8E1861999ABA2004F18DF /* CCEffectDropShadow.h in Headers */ = {isa = PBXBuildFile; fileRef = D2F78CC71999AB6E00229357 /* CCEffectDropShadow.h */; };
366+
D2F78CC81999AB6E00229357 /* CCEffectDropShadow.h in Headers */ = {isa = PBXBuildFile; fileRef = D2F78CC71999AB6E00229357 /* CCEffectDropShadow.h */; };
359367
D2EC6039199D9F82001A15E9 /* CCRendererGLSupport.m in Sources */ = {isa = PBXBuildFile; fileRef = D36DFA2719996EC500DEC135 /* CCRendererGLSupport.m */; };
360368
D2FEB611194F6C9E00FC0574 /* CCBLocalizationManager.h in Headers */ = {isa = PBXBuildFile; fileRef = B7D273041822F4AA0054849B /* CCBLocalizationManager.h */; };
361369
D2FEB612194F6C9E00FC0574 /* CCAction.h in Headers */ = {isa = PBXBuildFile; fileRef = 5018F2520DFDEAFF00C013A5 /* CCAction.h */; };
@@ -1007,6 +1015,9 @@
10071015
B7EE69DF1819E75700B983FE /* CCLayoutBox.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCLayoutBox.m; sourceTree = "<group>"; };
10081016
B7EE6A1C181AE34600B983FE /* CCSlider.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCSlider.h; path = "cocos2d-ui/CCSlider.h"; sourceTree = "<group>"; };
10091017
B7EE6A1D181AE34600B983FE /* CCSlider.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCSlider.m; path = "cocos2d-ui/CCSlider.m"; sourceTree = "<group>"; };
1018+
D208E79C1993FEDA00BD8D6B /* CCEffectDropShadow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCEffectDropShadow.m; sourceTree = "<group>"; };
1019+
D208E7AB19959A4800BD8D6B /* CCEffectOuterGlow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCEffectOuterGlow.h; sourceTree = "<group>"; };
1020+
D208E7AC19959A4800BD8D6B /* CCEffectOuterGlow.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCEffectOuterGlow.m; sourceTree = "<group>"; };
10101021
D23C5CB2194BC108007CA669 /* CCTouchIOS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCTouchIOS.h; sourceTree = "<group>"; };
10111022
D23C5CB3194BC108007CA669 /* CCTouchIOS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCTouchIOS.m; sourceTree = "<group>"; };
10121023
D23C5CBA194BC500007CA669 /* CCTouchAndroid.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCTouchAndroid.h; path = Android/CCTouchAndroid.h; sourceTree = "<group>"; };
@@ -1068,6 +1079,7 @@
10681079
D2DDB09019805E8400233D80 /* CCVector2.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = CCVector2.h; path = Platforms/Android/CCVector2.h; sourceTree = "<group>"; };
10691080
D2DDB09119805E8400233D80 /* CCQuaternion.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCQuaternion.m; path = Platforms/Android/CCQuaternion.m; sourceTree = "<group>"; };
10701081
D2DDB09219805E8400233D80 /* CCMatrix3.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = CCMatrix3.m; path = Platforms/Android/CCMatrix3.m; sourceTree = "<group>"; };
1082+
D2F78CC71999AB6E00229357 /* CCEffectDropShadow.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCEffectDropShadow.h; sourceTree = "<group>"; };
10711083
D2FEB74F194F6C9E00FC0574 /* libcocos2dAndroid.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libcocos2dAndroid.a; sourceTree = BUILT_PRODUCTS_DIR; };
10721084
D309054F18AC23110081BF11 /* CCRenderer_private.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CCRenderer_private.h; sourceTree = "<group>"; };
10731085
D31C794F19994126007921E1 /* CCMetalSupport.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CCMetalSupport.m; sourceTree = "<group>"; };
@@ -1820,6 +1832,10 @@
18201832
9D856720191B019900573093 /* CCEffectContrast.m */,
18211833
9DF3761F191C594A00C6D27A /* CCEffectPixellate.h */,
18221834
9DF37620191C594A00C6D27A /* CCEffectPixellate.m */,
1835+
D2F78CC71999AB6E00229357 /* CCEffectDropShadow.h */,
1836+
D208E79C1993FEDA00BD8D6B /* CCEffectDropShadow.m */,
1837+
D208E7AB19959A4800BD8D6B /* CCEffectOuterGlow.h */,
1838+
D208E7AC19959A4800BD8D6B /* CCEffectOuterGlow.m */,
18231839
);
18241840
name = Effects;
18251841
sourceTree = "<group>";
@@ -1954,6 +1970,7 @@
19541970
B7705FE21831A07B0043CC67 /* ALCaptureDevice.h in Headers */,
19551971
5018F26F0DFDEAFF00C013A5 /* CCActionInstant.h in Headers */,
19561972
B7705FF21831A07B0043CC67 /* ALWrapper.h in Headers */,
1973+
D2F78CC81999AB6E00229357 /* CCEffectDropShadow.h in Headers */,
19571974
5018F2710DFDEAFF00C013A5 /* CCActionInterval.h in Headers */,
19581975
5018F2730DFDEAFF00C013A5 /* CCLabelTTF.h in Headers */,
19591976
5018F2750DFDEAFF00C013A5 /* CCNodeColor.h in Headers */,
@@ -1978,6 +1995,7 @@
19781995
B7705FF81831A07B0043CC67 /* OALSuspendHandler.h in Headers */,
19791996
D268FE0F198078FF00ECBCD0 /* CCEffectGlass.h in Headers */,
19801997
D24160FE1958F6EE003673BD /* CCAnimationManager.h in Headers */,
1998+
D208E7AD19959A4800BD8D6B /* CCEffectOuterGlow.h in Headers */,
19811999
50305AF40E40E33200F63373 /* cocos2d.h in Headers */,
19822000
D285ECF8192EF5B2009F4E88 /* CCDirectorAndroid.h in Headers */,
19832001
B7705FE81831A07B0043CC67 /* ALDevice.h in Headers */,
@@ -2267,7 +2285,9 @@
22672285
D2FEB68F194F6C9E00FC0574 /* ObjectALConfig.h in Headers */,
22682286
D2FEB690194F6C9E00FC0574 /* CCDirectorMac.h in Headers */,
22692287
D2FEB691194F6C9E00FC0574 /* CCGLView.h in Headers */,
2288+
D208E7AE19959A4800BD8D6B /* CCEffectOuterGlow.h in Headers */,
22702289
D2FEB692194F6C9E00FC0574 /* CCWindow.h in Headers */,
2290+
D2E8E1861999ABA2004F18DF /* CCEffectDropShadow.h in Headers */,
22712291
D2FEB693194F6C9E00FC0574 /* CCProgressNode.h in Headers */,
22722292
D2DDB09419805E8400233D80 /* CCMathUtilsAndroid.h in Headers */,
22732293
D2FEB694194F6C9E00FC0574 /* CCLayout.h in Headers */,
@@ -2489,8 +2509,10 @@
24892509
50F7B2790F28DE7C00057537 /* CCActionEase.m in Sources */,
24902510
571CD02919649E03003D460C /* CCPlatformTextField.m in Sources */,
24912511
D3A2E7D3181E12750033614C /* CCPhysicsShape.m in Sources */,
2512+
D208E79F1993FEDA00BD8D6B /* CCEffectDropShadow.m in Sources */,
24922513
B7705FE71831A07B0043CC67 /* ALContext.m in Sources */,
24932514
B7EE6A1F181AE34600B983FE /* CCSlider.m in Sources */,
2515+
D208E7AF19959A4800BD8D6B /* CCEffectOuterGlow.m in Sources */,
24942516
D37D197A18B6665700B23FDE /* CCTMXXMLParser.m in Sources */,
24952517
509A79980F6188420032F449 /* CCSprite.m in Sources */,
24962518
D37D197718B6665700B23FDE /* CCTiledMap.m in Sources */,
@@ -2699,11 +2721,13 @@
26992721
D2FEB6FC194F6C9E00FC0574 /* CCPhysicsNode.m in Sources */,
27002722
D2FEB6FD194F6C9E00FC0574 /* CCGLView.m in Sources */,
27012723
D2FEB6FE194F6C9E00FC0574 /* CCLabelBMFont.m in Sources */,
2724+
D208E7A01993FEDA00BD8D6B /* CCEffectDropShadow.m in Sources */,
27022725
D2FEB701194F6C9E00FC0574 /* CCDirectorAndroid.m in Sources */,
27032726
D2FEB702194F6C9E00FC0574 /* CCGLView.m in Sources */,
27042727
D3903B18199528F3003AA81A /* CCEffectBlur.m in Sources */,
27052728
D2FEB703194F6C9E00FC0574 /* CCEffectBrightness.m in Sources */,
27062729
D24161171958F738003673BD /* CCAnimationManager+FrameAnimation.m in Sources */,
2730+
D208E7B019959A4800BD8D6B /* CCEffectOuterGlow.m in Sources */,
27072731
D2FEB705194F6C9E00FC0574 /* CCBKeyframe.m in Sources */,
27082732
D2FEB706194F6C9E00FC0574 /* CCTexturePVR.m in Sources */,
27092733
D2FEB707194F6C9E00FC0574 /* ALListener.m in Sources */,

cocos2d-ui-tests/tests/CCEffectsTest.m

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22
#import "CCTextureCache.h"
33
#import "CCNodeColor.h"
44
#import "CCEffectNode.h"
5-
#import "CCEffectBlur.h"
6-
75

86
@interface CCEffectsTest : TestBase @end
97
@implementation CCEffectsTest
@@ -18,6 +16,57 @@ -(id)init
1816
return self;
1917
}
2018

19+
-(void)setupOuterGlowEffectTest
20+
{
21+
self.subTitle = @"OuterGlow Effect Test";
22+
23+
// CCNodeColor* environment = [CCNodeColor nodeWithColor:[CCColor whiteColor]];
24+
CCSprite *environment = [CCSprite spriteWithImageNamed:@"Images/MountainPanorama.jpg"];
25+
environment.positionType = CCPositionTypeNormalized;
26+
environment.anchorPoint = ccp(0.5, 0.5);
27+
environment.position = ccp(0.5f, 0.5f);
28+
29+
[self.contentNode addChild:environment];
30+
31+
CCColor *glowColor = [CCColor colorWithRed:0.0 green:0.0 blue:1.0 alpha:0.5];
32+
CCEffectOuterGlow* effect = [CCEffectOuterGlow effectWithGlowColor:glowColor];
33+
34+
CCSprite *sampleSprite = [CCSprite spriteWithImageNamed:@"Images/DistanceFieldX.png"];
35+
sampleSprite.position = ccp(0.5, 0.5);
36+
sampleSprite.positionType = CCPositionTypeNormalized;
37+
sampleSprite.effect = effect;
38+
39+
[self.contentNode addChild:sampleSprite];
40+
}
41+
42+
-(void)setupDropShadowEffectTest
43+
{
44+
self.subTitle = @"DropShadow Effect Test";
45+
46+
CCSprite *environment = [CCSprite spriteWithImageNamed:@"Images/MountainPanorama.jpg"];
47+
environment.positionType = CCPositionTypeNormalized;
48+
environment.position = ccp(0.5f, 0.5f);
49+
50+
[self.contentNode addChild:environment];
51+
52+
CCColor *shadowColor = [CCColor colorWithRed:0.0 green:1.0 blue:0.0 alpha:0.5];
53+
CCEffectDropShadow* effect = [CCEffectDropShadow effectWithShadowOffset:GLKVector2Make(2.0, -2.0) shadowColor:shadowColor];
54+
55+
CCSprite *sampleSprite = [CCSprite spriteWithImageNamed:@"Images/Ohm.png"];
56+
sampleSprite.position = ccp(0.5, 0.5);
57+
sampleSprite.positionType = CCPositionTypeNormalized;
58+
59+
CCEffectNode* effectNode = [[CCEffectNode alloc] init];
60+
effectNode.contentSize = CGSizeMake(300, 300);
61+
effectNode.anchorPoint = ccp(0.5, 0.5);
62+
effectNode.positionType = CCPositionTypeNormalized;
63+
effectNode.position = ccp(0.5, 0.5);
64+
[effectNode addChild:sampleSprite];
65+
effectNode.effect = effect;
66+
67+
[self.contentNode addChild:effectNode];
68+
}
69+
2170
-(void)setupGlassEffectTest
2271
{
2372
self.subTitle = @"Glass Effect Test";

cocos2d/CCEffectDropShadow.h

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
//
2+
// CCEffectDropShadow.h
3+
// cocos2d-ios
4+
//
5+
// Created by Oleg Osin on 8/7/14.
6+
//
7+
//
8+
9+
#import "CCEffect.h"
10+
11+
/**
12+
* CCEffectDropShadow create a drop shadow.
13+
*
14+
*/
15+
16+
@interface CCEffectDropShadow : CCEffect
17+
18+
/// -----------------------------------------------------------------------
19+
/// @name Accessing Effect Attributes
20+
/// -----------------------------------------------------------------------
21+
22+
/** Adjust which direction the shadow should point. A value of (5.0, -5,0) will
23+
* place the drop shadow at the bottom right.
24+
*/
25+
@property (nonatomic) GLKVector2 shadowOffset;
26+
27+
/** Color of the shadow,
28+
* [CCColor blackColor] will result in an opaque black drop shadow.
29+
*/
30+
@property (nonatomic) CCColor* shadowColor;
31+
32+
/// -----------------------------------------------------------------------
33+
/// @name Initializing a CCEffectDropShadow object
34+
/// -----------------------------------------------------------------------
35+
36+
/**
37+
* Initializes a CCEffectDropShadow object with a (5, -5) black drop shadow offset .
38+
*
39+
* @return The CCEffectDropShadow object.
40+
*/
41+
-(id)init;
42+
43+
/**
44+
* Initializes a CCEffectDropShadow object with the supplied parameters.
45+
*
46+
* @param shadowOffset A value of (5.0, -5,0) will place the drop shadow at the bottom right.
47+
* @param shadowColor Color of the shadow, a [CCColor blackColor] will result in an opaque black drop shadow.
48+
*
49+
* @return The CCEffectDropShadow object.
50+
*/
51+
-(id)initWithShadowOffset:(GLKVector2)shadowOffset shadowColor:(CCColor*)shadowColor;
52+
53+
54+
/// -----------------------------------------------------------------------
55+
/// @name Creating a CCEffectDropShadow object
56+
/// -----------------------------------------------------------------------
57+
58+
/**
59+
* Initializes a CCEffectDropShadow object with the supplied parameters.
60+
*
61+
* @param shadowOffset A value of (5.0, -5,0) will place the drop shadow at the bottom right.
62+
* @param shadowColor Color of the shadow, a [CCColor blackColor] will result in an opaque black drop shadow.
63+
*
64+
* @return The CCEffectDropShadow object.
65+
*/
66+
+(id)effectWithShadowOffset:(GLKVector2)shadowOffset shadowColor:(CCColor*)shadowColor;
67+
68+
69+
@end
70+
71+

0 commit comments

Comments
 (0)