GSI

Texture2DEx2.h
-------------------------------

#import <Foundation/Foundation.h>

#import "Texture2D.h"


@interface Texture2DEx2 : Texture2D {

CGPoint tileSize;

CGPoint frameSize;

int curIndex;

int Delay;

int Tick;

}


@property CGPoint tileSize;

@property CGPoint frameSize;

@property int curIndex;

@property int Delay;

@property int Tick;


- (void) TileSize:(CGPoint)ts FrameSize:(CGPoint)fs Delay:(int)delay;

- (void) drawAtPointTest:(CGPoint)point;


@end



Texture2DEx2.m
-------------------------------

#import "Texture2DEx2.h"



@implementation Texture2DEx2


@synthesize tileSize;

@synthesize frameSize;

@synthesize curIndex;

@synthesize Delay;

@synthesize Tick;


- (void) TileSize:(CGPoint)ts FrameSize:(CGPoint)fs Delay:(int)delay

{

self.tileSize = ts;

self.frameSize = fs;

self.Delay = delay;

self.Tick = 0;

}


- (void) drawAtPointTest:(CGPoint)point 

{

if( Tick > Delay )

{

Tick = 0;

curIndex++;

if( curIndex >= frameSize.x )

{

curIndex = 0;

}

}

Tick++;

GLfloat leftTc = tileSize.x * curIndex / _width;

GLfloat rightTc = tileSize.x * (curIndex+1) / _width;

GLfloat coordinates[] = { leftTc, _maxT,

rightTc, _maxT,

leftTc, 0,

rightTc, 0 };

// 넓이와 높이는 타일의 사이즈로 교체

GLfloat width = tileSize.x,

height = tileSize.y;

GLfloat vertices[] = { -width / 2 + point.x, -height / 2 + point.y, 0.0,

width / 2 + point.x, -height / 2 + point.y, 0.0,

-width / 2 + point.x, height / 2 + point.y, 0.0,

width / 2 + point.x, height / 2 + point.y, 0.0 };

glBindTexture(GL_TEXTURE_2D, _name);

glVertexPointer(3, GL_FLOAT, 0, vertices);

glTexCoordPointer(2, GL_FLOAT, 0, coordinates);

glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);

}


@end


/////////////////

Texture2DEx2 *bluePlaneEx;


@property (nonatomic, retain) Texture2DEx2 *bluePlaneEx;



if (bluePlaneEx == nil) {

self.bluePlaneEx = [[Texture2DEx2 alloc] initWithImage: [UIImage imageNamed:@"bluePlane2.png"]];

glBindTexture(GL_TEXTURE_2D, sprite.name);

// 타일 사이즈, 이미지 내부 프레임 개수, 딜레이 타임(호출타임)

[self.bluePlaneEx TileSize:CGPointMake(63.0, 55.0) FrameSize:CGPointMake(3, 1) Delay:10];

[bluePlaneEx drawAtPointTest:CGPointMake(Pos.x, Pos.y)];



Posted by gsi
: