紋理地圖集被設計爲與Cocos2D一起運行,與其他組件有很多依賴關係。所以我認爲這對你來說不是一個好選擇。
您發佈的教程很好,否則。它可能最容易使用,但它提供了一個非常好的切入點。此代碼的主要部分是- display
和- (void)displayLayer:
方法:
顯示方法是在圖層需要其內容時調用。動畫將(間接)調用顯示方法,在這裏我們調用displayLayer,它將改變圖像顯示(我希望我已經清楚:!)。
在這裏你可以如何重構的顯示方法,如果你想使用zwooptex文件(或其他)與非固定大小:
// Implement displayLayer: on the delegate to override how sample rectangles are calculated; remember to use currentSampleIndex, ignore sampleIndex == 0, and set the layer's bounds
- (void)display;
{
static const CGRect sampleRects[11] = {
{ 0, 0, 38, 47 }, // run
{ 0, 47, 46, 47 },
{ 82, 0, 40, 47 },
{ 122, 0, 30, 47 },
{ 152, 0, 36, 47 },
{ 38, 0, 44, 47 },
{ 188, 0, 42, 47 },
{ 230, 0, 26, 47 },
{ 46, 47, 28, 47 },
{ 74, 47, 28, 47 },
{ 102, 47, 28, 47 },
};
unsigned int idx = [self currentSampleIndex];
if (idx == 0)
return;
self.bounds = CGRectMake(0, 0, sampleRects[idx-1].size.width, sampleRects[idx-1].size.height);
self.contentsRect = CGRectMake(sampleRects[idx-1].origin.x/256.0f, sampleRects[idx-1].origin.y/128.0f, sampleRects[idx-1].size.width/256.0f, sampleRects[idx-1].size.height/128.0f);
}
@end
如果您有任何問題,請不要猶豫。 ;)