cocos2d CCScrollerLayer 放大镜 效果 算法 (越靠近中心点越变大)

定义一个 工具类,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],是要被放大的对象。




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值