brandmooffin/cocos2d-mono

CCSprite 加载图片白屏

Closed this issue · 4 comments

代码:
CCSprite remind = new CCSprite("RemindBG");
remind.Position = new CCPoint(0,0);
AddChild(remind,0);

remind 中Texture2D 已经加载成功了, 图像大小 都吻合, 但是显示的时候 是纯白的

补充:SavePng 得到的图片也是对的, 就是无法渲染

Hmm that doesn't sound like the expected behavior. I'm going to go ahead and take a look into this issue and see if I can reproduce it.

In the meantime, could you attach the RemindBG image? Would be better to test with that to make sure I'm reproducing the same scenario. Also which platform is this happening on?

Thanks & I'll add more details as soon as I can!

谢谢您的回复,
问题已经解决了
因为我需要用到网络加载资源
所以重做了资源加载器,
在CCTexture2D.cs 的 public bool InitWithFile(string file) 方法 最前面 使用了我自己的加载器,

public bool InitWithFile(string file)  {
            m_bManaged = false;  
            var _stream = ContentLoader.OpenStream(file);
            Texture2D texture = null;
            if (_stream != null)
            {
                texture = Texture2D.FromStream(ContentLoader.GraphicsDeviceManager.GraphicsDevice, _stream);
                return InitWithTexture(texture, PreserveSourceSurfaceFormat ? texture.Format : DefaultAlphaPixelFormat, false, true);  

            } 
......
}

由于没有设置 m_CacheInfo.CacheType = CCTextureCacheType.AssetFile;
m_CacheInfo.Data = file;
就返回了, 可能导致后面使用的时候 这两个参数异常导致的白屏
改成如下代码就好了:

public bool InitWithFile(string file)
        {
            m_bManaged = false; 
            m_CacheInfo.CacheType = CCTextureCacheType.AssetFile;//修改后
            m_CacheInfo.Data = file;//修改后
            var _stream = ContentLoader.OpenStream(file);
            Texture2D texture = null;
            if (_stream != null)
            {
                texture = Texture2D.FromStream(ContentLoader.GraphicsDeviceManager.GraphicsDevice, _stream);
                return InitWithTexture(texture, PreserveSourceSurfaceFormat ? texture.Format : DefaultAlphaPixelFormat, false, true); 

            }
..........
}

Thanks for the response! I will be closing the issue. I can add some comments around the code to improve the understanding here a bit more