AtlasTest简单总结

来源:互联网 发布:户户通定位破解软件 编辑:程序博客网 时间:2024/05/11 04:16
AtlasTest简单总结  

/**************************************************************************


typedef struct _ccV3F_C4B_T2F_Quad
{
//! top left
ccV3F_C4B_T2F tl;
//! bottom left
ccV3F_C4B_T2F bl;
//! top right
ccV3F_C4B_T2F tr;
//! bottom right
ccV3F_C4B_T2F br;
} ccV3F_C4B_T2F_Quad;
 



typedef struct _ccV3F_C4B_T2F
{
//! vertices (3F)
ccVertex3F vertices; // 12 bytes
// char __padding__[4];
 
//! colors (4B)
ccColor4B colors; // 4 bytes
// char __padding2__[4];
 
// tex coords (2F)
ccTex2F texCoords; // 8 byts
} ccV3F_C4B_T2F;
 
 
******************************************************************************/

/*下面的ccV3F_C4B_T2F_Quad(四边形)结构数组定义了三张图片的不同显示,运行看效果
ccV3F_C4B_T2F_Quad结构上边注释中可以看到,他是一个结构,里面有4个ccV3F_C4B_T2F成员
每个成员也都是结构,这个结构的成员是ccVertex3F(定点)ccColor4B(颜色)ccTex2F(不清楚,好像跟gl有关了)*/
ccV3F_C4B_T2F_Quad quads[] = {
{
{{0,0,0},{0,0,255,255},{1.0f,1.0f},},// bottom left(左下角)
{{s.width,0,0},{0,0,255,0},{1.0f,1.0f},},// bottom right
{{0,s.height,0},{0,0,255,0},{0.0f,0.0f},},// top left
{{s.width,s.height,0},{0,0,255,255},{1.0f,0.0f},},// top right
},
{
{{40,40,0},{255,255,255,255},{0.0f,0.2f},},// bottom left
{{120,80,0},{255,0,0,255},{0.5f,0.2f},},// bottom right
{{40,160,0},{255,255,255,255},{0.0f,0.0f},},// top left
{{160,160,0},{0,255,0,255},{0.5f,0.0f},},// top right
},


{
{{s.width/2,40,0},{255,0,0,255},{0.0f,1.0f},},// bottom left
{{s.width,40,0},{0,255,0,255},{1.0f,1.0f},},// bottom right
{{s.width/2-50,200,0},{0,0,255,255},{0.0f,0.0f},},// top left
{{s.width,100,0},{255,255,0,255},{1.0f,0.0f},},// top right
},

};


for( int i=0;i<3;i++) {
[textureAtlas updateQuad:&quads[i] atIndex:i];
}

// [textureAtlas removeQuadAtIndex:0];


return self;
}




-(id) init
{
if( (self=[super init] )) {

/*label集,需要一个指定宽度,高度的一张图片,它的开始位置需要一个字符参数,但实际的开始值是字符的ascii码值
我这里指定的是空格的ascii码值32,根据我提供的图片系统会按照提供的值去图片上截取一段出来,因为图片的开始
位置为空格,所以它会按照顺序去图片上截取,需要注意的是,图片上的字符间的大小一定要固定,要不然取出来的值就
会对应不上,就是说不官你指定的字符是多少,它都是把图片上的第一个位置当做是开始位置,如果你指定的字符是“!”
那么系统就把图片上第一个位置看成是从33开始的,以后每取出来的值,都会串一位,跟实际的ascii表就对应不上
所以根据这个,我们活学活用,可以把图片上的对应位置换成其他任何图片,只要用在这个方法里,都会根据ascii值取
截取相应的图片*/
CCLabelAtlas *label1 = [CCLabelAtlas labelAtlasWithString:@"123 Test" charMapFile:@"tuffy_bold_italic-charmap.png" itemWidth:48 itemHeight:64 startCharMap:' '];
[self addChild:label1 z:0 tag:kTagSprite1];
label1.position = ccp(10,100);
label1.opacity = 200;


CCLabelAtlas *label2 = [CCLabelAtlas labelAtlasWithString:@"0123456789" charMapFile:@"tuffy_bold_italic-charmap.png" itemWidth:48 itemHeight:64 startCharMap:' '];
[self addChild:label2 z:0 tag:kTagSprite2];
label2.position = ccp(10,200);
label2.opacity = 32;


[self schedule:@selector(step:)];
}
return self;
}


// 每侦都执行的函数,在这里可以从新设置label显示的内容
-(void) step:(ccTime) dt
{
time += dt;
NSString *string = [NSString stringWithFormat:@"%2.2f Test", time];
CCLabelAtlas *label1 = (CCLabelAtlas*) [self getChildByTag:kTagSprite1];
[label1 setString:string];


CCLabelAtlas *label2 = (CCLabelAtlas*) [self getChildByTag:kTagSprite2];
[label2 setString: [NSString stringWithFormat:@"%d", (int)time]];
}




// Upper Label

// CCBitmapFontAtlas 高级label它使用fnt文件,能够让字体以不同的样式显示出来
// 这个文件可以到网上下载,也可以自己写
/*由于CCBitmapFontAtlas是继承CCSpriteSheet,CCSpriteSheet又是继承ccnode的
所以我们可以把CCBitmapFontAtlas对象中的字符单个取出,取出后每个都是一个ccsprite对象
然后我们就可以使用精灵类的一些方法来对字符进行操作
索引位置是从0开始*/


/*************************了解更多的信息就得看CCBitmapFontAtlas的代码了******************************/

CCBitmapFontAtlas *label = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"Bitmap Font Atlas" fntFile:@"bitmapFontTest.fnt"];
[self addChild:label];

CGSize s = [[CCDirector sharedDirector] winSize];

label.position = ccp(s.width/2, s.height/2);
label.anchorPoint = ccp(0.5f, 0.5f);


CCSprite *BChar = (CCSprite*) [label getChildByTag:0];
CCSprite *FChar = (CCSprite*) [label getChildByTag:7];
CCSprite *AChar = (CCSprite*) [label getChildByTag:12];


id rotate = [CCRotateBy actionWithDuration:2 angle:360];
id rot_4ever = [CCRepeatForever actionWithAction:rotate];

id scale = [CCScaleBy actionWithDuration:2 scale:1.5f];
id scale_back = [scale reverse];
id scale_seq = [CCSequence actions:scale, scale_back,nil];
id scale_4ever = [CCRepeatForever actionWithAction:scale_seq];

id jump = [CCJumpBy actionWithDuration:0.5f position:CGPointZero height:60 jumps:1];
id jump_4ever = [CCRepeatForever actionWithAction:jump];

id fade_out = [CCFadeOut actionWithDuration:1];
id fade_in = [CCFadeIn actionWithDuration:1];
id seq = [CCSequence actions:fade_out, fade_in, nil];
id fade_4ever = [CCRepeatForever actionWithAction:seq];

[BChar runAction:rot_4ever];
[BChar runAction:scale_4ever];
[FChar runAction:jump_4ever];
[AChar runAction:fade_4ever];


// Bottom Label
CCBitmapFontAtlas *label2 = [CCBitmapFontAtlas bitmapFontAtlasWithString:@"00.0" fntFile:@"bitmapFontTest.fnt"];
[self addChild:label2 z:0 tag:kTagBitmapAtlas2];
label2.position = ccp(s.width/2.0f, 80);

CCSprite *lastChar = (CCSprite*) [label2 getChildByTag:3];
[lastChar runAction: [[rot_4ever copy] autorelease]];

[self schedule:@selector(step:) interval:0.1f];
}

return self;
}
0 0
原创粉丝点击