定义一个 工具类,ScrollerLayer
.h文件中 内容
#import <Foundation/Foundation.h>
#import "cocos2d.h"
#import "CCScrollLayer.h"
#define scaleMax 1.6
@interface ScrollerLayer : CCLayer {
int _myIndex;
CCScrollLayer * superLayer;
}
@property(nonatomic,retain)CCScrollLayer * superLayer;
-(id)initWithIndex:(int)index;
@end
.m 文件内容
#import "ScrollerLayer.h"
@implementation ScrollerLayer
@synthesize superLayer;
-(id)initWithIndex:(int)index{
self=[super init];
if (self) {
_myIndex=index;
[selfscheduleUpdate];
}
return self;
}
-(void)update:(ccTime *)time{
float width=superLayer.contentSize.width -superLayer.pagesWidthOffset;
float super_positon_x =-superLayer.position.x;
if (super_positon_x >self.position.x-width && super_positon_x <self.position.x+width) {
if (super_positon_x >self.position.x) {
[[self getChildByTag:100]getChildByTag:50].scale=((self.position.x+width)-super_positon_x)/width*(1.6-1)+1 ;
}
if (super_positon_x <self.position.x) {
[[self getChildByTag:100]getChildByTag:50].scale= ( super_positon_x-(self.position.x-width))/width*(1.6-1)+1;
}
}else{
[[selfgetChildByTag:100]getChildByTag:50].scale=1;
}
}
@end
现在 代码 放大 的是1.6 倍,
现在就更简单了,在 CCScrollerLayer 初始化方法中 下下面代码写入
for (int i=0; i<[layers_count]; i++) {
ScrollerLayer * layer=(ScrollerLayer *)[layers_objectAtIndex:i];
layer.superLayer=self;
}
这样 只要是 使用 工具类 ScrollerLayer 创建的layer 都有这个功能了,上面代码中的 [[ self getChildByTag: 100] getChildByTag: 50],是要被放大的对象。