iOS cocos2d 롤 넘 버 (디지털 스크롤 효과) 컨트롤 효과 원본 구현
csdn 블 로그:http://blog.csdn.net/RuShrooM
//
// UiNumRoll.h
// WheelScore
//
//
//
// :Jason's.Alex
//QQ:531401335
#import
#import "cocos2d.h"
#import "ResourceLoad.h"
#define NUM_HEIGHT 20
#define NUM_WIDTH 12
typedef enum{
NumStyleNormal,
NumStyleSameTime,
}NumStyle;
@interface UINumber : CCSprite {
NumStyle m_style; //
int m_number;//
int m_nPosCur; //
int m_nPosEnd; //
int m_nMoveLen; //
CCTexture2D *m_texture; // texture
float moveFactor;// , retina , 2
}
@property(nonatomic,retain) CCTexture2D *m_texture;
+(id)numberWithSprite:(NumStyle) style;
-(id)initWithStyle:(NumStyle) style ;
-(void) setNumber:(int) num;
-(void) onRollDown:(ccTime) dt;
-(void) onRollUP:(ccTime) dt;
-(void) setup;
@end
//
// UiNumRoll.m
// WheelScore
//
// :Jason's.Alex
//QQ:531401335
#import "UINumber.h"
@implementation UINumber
@synthesize m_texture;
+(id)numberWithSprite:(NumStyle) style
{
return [[[self alloc]initWithStyle:style]autorelease];
}
/*
* init
*/
-(id) init
{
if( (self=[super init])) {
m_texture = NULL;
m_style = NumStyleNormal;
m_nPosCur = 0;
m_nPosEnd = 0;
m_number=0;
moveFactor=1.0f;
[self setup];
}
return self;
}
/*
* initWithStyle
*/
-(id) initWithStyle:(NumStyle) style
{
if( (self=[super init]))
{
m_texture = NULL;
m_style = style;
m_nPosCur = 0;
m_nPosEnd = 0;
m_number=0;
moveFactor=1.0f;
[self setup];
}
return self;
}
/*
* setup texture
*/
-(void)setup
{
ResourceLoad* rl=[ResourceLoad shardResourceLoad];
if(rl.isRetina)// ,
{
moveFactor=0.5f;
[self setScaleX:rl.retinaScaleX*2.0f];
[self setScaleY:rl.retinaScaleY*2.0f];
}
UIImage *image = [UIImage imageNamed:@"number.png"];
m_texture = [[CCTexture2D alloc]initWithImage:image];
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:m_texture rect:CGRectMake(0, 0, NUM_WIDTH, NUM_HEIGHT*moveFactor)];
[self setDisplayFrame:frame];
}
/*
* setNumber
*/
-(void) setNumber:(int) num
{
[self unscheduleAllSelectors];
m_nPosCur =NUM_HEIGHT*m_number*moveFactor;
m_nPosEnd = NUM_HEIGHT * num*moveFactor;
if (NumStyleNormal == m_style) {
m_nMoveLen = 4*moveFactor;
}
else if (NumStyleSameTime == m_style) {
m_nMoveLen = (m_nPosEnd-m_nPosCur)/20*moveFactor;
}
if (m_number>num) {
[self schedule:@selector(onRollUP:) interval:0.01];
}
else {
[self schedule:@selector(onRollDown:) interval:0.01];
}
m_number=num;
}
/*
* onRollDown
*/
-(void) onRollDown:(ccTime) dt
{
m_nPosCur += m_nMoveLen;
if (m_nPosCur >= m_nPosEnd) {
m_nPosCur = m_nPosEnd;
[self unschedule:@selector(onRollDown:)];
}
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:m_texture rect:CGRectMake(0, m_nPosCur, NUM_WIDTH, NUM_HEIGHT*moveFactor)];
[self setDisplayFrame:frame];
}
/*
* onRollUP
*/
-(void) onRollUP:(ccTime) dt
{
m_nPosCur -= m_nMoveLen;
if (m_nPosCur <= m_nPosEnd) {
m_nPosCur = m_nPosEnd;
[self unschedule:@selector(onRollUP:)];
}
CCSpriteFrame *frame = [CCSpriteFrame frameWithTexture:m_texture rect:CGRectMake(0, m_nPosCur, NUM_WIDTH, moveFactor*NUM_HEIGHT)];
[self setDisplayFrame:frame];
}
-(void)dealloc
{
NSLog(@"~UINumber");
[self unscheduleAllSelectors];
[m_texture release];
[super dealloc];
}
@end
//
// UIRollNum.h
// WheelScore
//
//
// :Jason's.Alex
//QQ:531401335
#import
#import "cocos2d.h"
#import "UINumber.h"
#define NUM_SPACE 0 //
@interface UIRollNum : CCLayer {
int m_nNumber; //
int m_maxCol; //
NSMutableArray *numArray; //
CGPoint m_point; //
bool zeroFill; // 0
NumStyle style; //
float width;
float height;//
}
@property (nonatomic,retain) NSMutableArray *numArray;
@property (nonatomic) CGPoint m_point;
@property (nonatomic) NumStyle style;
@property(readonly) float width;
@property(readonly) float height;
+(id)numberWithRollNum;
-(void)initWithNumberSprite;//
-(void) rebuildEffect;
-(int) getNumber;
-(void) setNumber:(int)num;
@end
//
// UIRollNum.m
// WheelScore
//
// :Jason's.Alex
//QQ:531401335
#import "UIRollNum.h"
@implementation UIRollNum
@synthesize numArray,m_point,style;
@synthesize width;
@synthesize height;
+(id)numberWithRollNum
{
return [[[self alloc]init]autorelease];
}
/*
* init
*/
-(id) init
{
if (self = [super init]) {
m_nNumber = -1;
m_maxCol = 6;
numArray =[[NSMutableArray alloc] init];
zeroFill = YES;
style = NumStyleNormal;
width=(NUM_WIDTH+NUM_SPACE)*m_maxCol;
height=NUM_HEIGHT;
[self initWithNumberSprite];
}
return self;
}
-(void)initWithNumberSprite//
{
for (int i=0; i
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
View의 레이아웃 방법을 AutoLayout에서 따뜻한 손 계산으로 하면 성능이 9.26배로 된 이야기이 기사는 의 15 일째 기사입니다. 어제는 에서 이었습니다. 손 계산을 권하는 의도는 없고, 특수한 상황하에서 계측한 내용입니다 화면 높이의 10 배 정도의 contentView가있는 UIScrollView 레이아...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.