• <tfoot id='Tgz66'></tfoot>

    <small id='Tgz66'></small><noframes id='Tgz66'>

        <bdo id='Tgz66'></bdo><ul id='Tgz66'></ul>
    1. <legend id='Tgz66'><style id='Tgz66'><dir id='Tgz66'><q id='Tgz66'></q></dir></style></legend>

        <i id='Tgz66'><tr id='Tgz66'><dt id='Tgz66'><q id='Tgz66'><span id='Tgz66'><b id='Tgz66'><form id='Tgz66'><ins id='Tgz66'></ins><ul id='Tgz66'></ul><sub id='Tgz66'></sub></form><legend id='Tgz66'></legend><bdo id='Tgz66'><pre id='Tgz66'><center id='Tgz66'></center></pre></bdo></b><th id='Tgz66'></th></span></q></dt></tr></i><div id='Tgz66'><tfoot id='Tgz66'></tfoot><dl id='Tgz66'><fieldset id='Tgz66'></fieldset></dl></div>

        iOS 和 Cocos2d - 更改 CCSprite 的图像和新尺寸 = FAIL

        iOS and Cocos2d - Changing CCSprite#39;s image AND new dimensions = FAIL(iOS 和 Cocos2d - 更改 CCSprite 的图像和新尺寸 = FAIL)
        <i id='0s4fW'><tr id='0s4fW'><dt id='0s4fW'><q id='0s4fW'><span id='0s4fW'><b id='0s4fW'><form id='0s4fW'><ins id='0s4fW'></ins><ul id='0s4fW'></ul><sub id='0s4fW'></sub></form><legend id='0s4fW'></legend><bdo id='0s4fW'><pre id='0s4fW'><center id='0s4fW'></center></pre></bdo></b><th id='0s4fW'></th></span></q></dt></tr></i><div id='0s4fW'><tfoot id='0s4fW'></tfoot><dl id='0s4fW'><fieldset id='0s4fW'></fieldset></dl></div>

        <tfoot id='0s4fW'></tfoot>
        • <bdo id='0s4fW'></bdo><ul id='0s4fW'></ul>

                  <tbody id='0s4fW'></tbody>

                <small id='0s4fW'></small><noframes id='0s4fW'>

                <legend id='0s4fW'><style id='0s4fW'><dir id='0s4fW'><q id='0s4fW'></q></dir></style></legend>

                  本文介绍了iOS 和 Cocos2d - 更改 CCSprite 的图像和新尺寸 = FAIL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我的游戏中的一个增强功能是减小主要精灵的大小.因此,为了记忆起见,我没有在每一帧循环 sprite.scale,而是以低于原始 sprite 的百分比大小重新保存了 sprite,并且只想替换它.然后一旦死亡"发生或计时器用完,原始精灵就会返回.

                  One of the powerups in my game is a decrease in size of the main sprite. So for memory sake, instead of looping a sprite.scale through each frame, I resaved the sprite at a percentage size lower than the original sprite, and just wish to replace it. Then once "death" occurs or timer runs out, the original sprite returns.

                  所以,我正在使用此代码使其变小:

                  So, I am using this code for making it small:

                  [player setTexture:[[CCTextureCache sharedTextureCache] addImage:@"player-small.png"]];

                  还有这段代码用于恢复正常:

                  and this code for resetting back to normal:

                  [player setTexture:[[CCTextureCache sharedTextureCache] addImage:@"player-orig.png"]];

                  但是,原始图像(在初始化和重置时)看起来正常.但是当我将它更改为新精灵(其尺寸正好是原始精灵的 75%)时,它会改变它,但只显示新精灵的一个象限,但具有原始尺寸.

                  however, the orignal image (both in the init and when reset) looks normal. But when I change it to the new sprite (which has dimensions exactly 75% of the original), it changes it, but shows only a quadrant of the new sprite, but with the original dimensions.

                  我尝试在重新纹理精灵之前修改 sprite.contentsize,但所做的只是改变大小,但不会影响图像混乱的问题.

                  I tried modifying the sprite.contentsize before retexturing the sprite, but all that did was change the size, but not affect the issue with the image messing up.

                  以下是一些视觉示例:

                  原文:

                  带有 contentSize 修改的纹理图像:

                  Retextured Image with contentSize modification:

                  将图像重新纹理化为原始图像,而 contentSize 未正确重置(哎呀,但这根本不是问题 - 我只是忘记读取尺寸代码):

                  Retextured image to the Original image with the contentSize not reset properly (oops, but this isn't a problem at all - i just forgot to readd the size code):

                  PS——我的所有精灵都有-hd.png"版本,所以我只想补充一点,以防有人想知道(到目前为止,图像和测试只在nonretina"模拟器上进行).

                  PS -- I do have "-hd.png" versions of all of my sprites, so i just wanted add that incase anyone wanted to know (the images and testing so far has only been on "nonretina" simulator).

                  谢谢!

                  在视网膜模拟器上进行测试时也会出现问题.

                  Issue occurs during testing on retina simulator as well.

                  推荐答案

                  由于您主要关心的是内存,我建议简单地使用纹理图集.

                  Since your main concern is about memory, I recommend to simply use a texture atlas.

                  我将您的原始图像复制到图像编辑程序中以查看其尺寸.图像大小为 73x71 像素,这意味着它作为尺寸为 128x128 的纹理存储在内存中,因为纹理将具有二维的幂.这将使纹理占用 64 KB 的内存(假设为 32 位颜色深度).使用纹理图集,您将能够更紧密地打包纹理,并且您可以使用 CCSprite setDisplayFrame 方法.

                  I copied your original image into an image editing program to see what its dimensions are. The image is 73x71 pixels in size, that means it's stored in memory as a texture with dimensions 128x128 since textures will have power of two dimensions. This will have the texture use up 64 KB of memory (assuming 32-bit color depth). With a texture atlas you'll be able to pack your textures more tightly, and you can change the frame that is displayed more easily with the CCSprite setDisplayFrame method.

                  此外,您正在使用纹理缓存:

                  Furthermore, you are using the texture cache:

                  [CCTextureCache sharedTextureCache] addImage:@"player-small.png"]
                  [CCTextureCache sharedTextureCache] addImage:@"player-orig.png"]
                  

                  除非您明确释放该纹理的内存,否则这两个纹理都将保留在内存中.如果您确实释放了您当前不使用的纹理的内存,并经常交换这些纹理,您的游戏将花费大量时间释放内存并从设备的闪存重新加载图像 - 即使图像相对较小.

                  Unless you explicitly free the memory of that texture, both textures will remain in memory anyway. If you do free the memory of the texture you're not currently using, and exchange these texture often, your game will spend a great deal of time releasing memory and reloading the image from the device's flash memory - even if the image is relatively small.

                  如果有多个精灵使用任一纹理,则尝试卸载/重新加载纹理将没有任何意义,因为会出现两个或多个精灵将使用任一纹理的情况.

                  And if there's more than one sprite using either texture it wouldn't make any sense to try and unload/reload the textures because there will be occurrences where two or more sprites will use either texture.

                  最后,我们说的是最多 64 KB 的内存.如果您担心内存使用和性能,您应该做的是加载 PVR 纹理,它在内存和磁盘上都是 PNG 文件大小的一小部分(但会失去一些色彩活力).

                  Finally, we're talking about 64 KB of memory at most. If you're concerned about memory usage AND performance, the thing you should do is to load PVR textures instead, which are a fraction of the size of a PNG file both in memory and on disk (but losing some color vibrancy).

                  查看 TexturePacker 以创建纹理图集和 PVR 图像.

                  Have a look at TexturePacker for creating texture atlases and PVR images.

                  这篇关于iOS 和 Cocos2d - 更改 CCSprite 的图像和新尺寸 = FAIL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Hardware Volume buttons change in app volume(硬件音量按钮更改应用程序音量)
                  Cocos2d - How to check for Intersection between objects in different layers(Cocos2d - 如何检查不同层中对象之间的交集)
                  Resume game cocos2d(恢复游戏 cocos2d)
                  Highlight Read-Along Text (in a storybook type app for iPhone)(突出显示朗读文本(在 iPhone 的故事书类型应用程序中))
                  Cocos2D + Disabling only Retina iPad Graphics(Cocos2D + 仅禁用 Retina iPad 图形)
                  Proper cocos2d scene restart?(正确的 cocos2d 场景重启?)
                1. <small id='colOo'></small><noframes id='colOo'>

                    <tbody id='colOo'></tbody>

                    • <bdo id='colOo'></bdo><ul id='colOo'></ul>
                    • <legend id='colOo'><style id='colOo'><dir id='colOo'><q id='colOo'></q></dir></style></legend>

                          1. <tfoot id='colOo'></tfoot>

                            <i id='colOo'><tr id='colOo'><dt id='colOo'><q id='colOo'><span id='colOo'><b id='colOo'><form id='colOo'><ins id='colOo'></ins><ul id='colOo'></ul><sub id='colOo'></sub></form><legend id='colOo'></legend><bdo id='colOo'><pre id='colOo'><center id='colOo'></center></pre></bdo></b><th id='colOo'></th></span></q></dt></tr></i><div id='colOo'><tfoot id='colOo'></tfoot><dl id='colOo'><fieldset id='colOo'></fieldset></dl></div>