如何正确加载精灵在cocos2d? [英] How to load sprites in cocos2d correctly?

查看:170
本文介绍了如何正确加载精灵在cocos2d?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题是:
我使用cocos2d制作一个iOS游戏,这个游戏有很多层次,所以我必须创建一个加载场景来加载每个级别的精灵。 (像新的背景,怪物和其他东西)
但是我不知道,我添加了所有的纹理包装器文件(.plist和.pvr.ccz)
在sharedStyleFrameCache在GameData m。
有没有人知道一个很好的教程为此或可以帮助我解决这个?
谢谢!

my problem is: I'm making a game for iOS using cocos2d and this game has lots of levels, so I'll have to create a loading scene to load my sprites for each level. ( like new backgrounds, monsters and other stuff ) But I have no idea about this, I'm adding all the Texture Packer Files (.plist and .pvr.ccz) on the sharedSpriteFrameCache in the GameData.m. Does anyone knows a good tutorial for this or can help me solve this? Thanks!

推荐答案

所以基本上你想知道如何加载和卸载图像,如何

So basically you want to know how to load and unload images as you see fit. How about

@implementation Level1

- (void) loadLevel
{
    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    CCTextureCache* textureCache = [CCTextureCache sharedTextureCache];

    // Add the sprite frames. This will load the texture as well
    [frameCache addSpriteFramesWithFile:@"monkey.plist"];
    [frameCache addSpriteFramesWithFile:@"player.plist"];
    [frameCache addSpriteFramesWithFile:@"enemy.plist"];

    // Load other textures that are going to be used
    _myBackgroundTexture = [textureCache addImage:@"background.png"];
}

- (void) unloadLevel
{
    CCSpriteFrameCache* frameCache = [CCSpriteFrameCache sharedSpriteFrameCache];
    CCTextureCache* textureCache = [CCTextureCache sharedTextureCache];

    // Remove textures
    [textureCache removeTexture:_myBackgroundTexture];

    // Remove sprite frames. This will load the texture as well
    [frameCache removeSpriteFramesFromFile:@"monkey.plist"];
    [frameCache removeSpriteFramesFromFile:@"player.plist"];
    [frameCache removeSpriteFramesFromFile:@"enemy.plist"];

    // Though normally, id use frameCache removeUnusedSpriteFrames and
    // textureCache removeUnusedTextures
}

...
@end

... @end

这篇关于如何正确加载精灵在cocos2d?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆