コード例 #1
0
 public static void PurgeSharedTextureCache()
 {
     if (s_sharedTextureCache != null)
     {
         s_sharedTextureCache.Dispose();
         s_sharedTextureCache = null;
     }
 }
コード例 #2
0
        public void CreateStatsLabel()
        {
            CCTexture2D    texture;
            CCTextureCache textureCache = CCTextureCache.SharedTextureCache;

            try
            {
                if (!textureCache.Contains("cc_fps_images"))
                {
                    texture = textureCache.AddImage(CCFPSImage.PngData, "cc_fps_images", SurfaceFormat.Bgra4444);
                }
                else
                {
                    texture = textureCache.TextureForKey("cc_fps_images");
                }

                if (texture == null || (texture.ContentSize.Width == 0 && texture.ContentSize.Height == 0))
                {
                    m_bDisplayStats = false;
                    return;
                }
            }
            catch (Exception)
            {
                // MonoGame may not allow texture.fromstream, so catch this exception here
                // and disable the stats
                m_bDisplayStats = false;
                return;
            }
            float factor = m_obWinSizeInPoints.Height / 320.0f;
            var   pos    = CCDirector.SharedDirector.VisibleOrigin;

            m_pFPSLabel = new CCLabelAtlas();
            m_pFPSLabel.SetIgnoreContentScaleFactor(true);
            m_pFPSLabel.InitWithString("00.0", texture, 12, 32, '.');
            m_pFPSLabel.Scale = factor;

            m_pUpdateTimeLabel = new CCLabelAtlas();
            m_pUpdateTimeLabel.SetIgnoreContentScaleFactor(true);
            m_pUpdateTimeLabel.InitWithString("0.000", texture, 12, 32, '.');
            m_pUpdateTimeLabel.Scale = factor;

            m_pDrawTimeLabel = new CCLabelAtlas();
            m_pDrawTimeLabel.SetIgnoreContentScaleFactor(true);
            m_pDrawTimeLabel.InitWithString("0.000", texture, 12, 32, '.');
            m_pDrawTimeLabel.Scale = factor;

            m_pDrawsLabel = new CCLabelAtlas();
            m_pDrawsLabel.SetIgnoreContentScaleFactor(true);
            m_pDrawsLabel.InitWithString("000", texture, 12, 32, '.');
            m_pDrawsLabel.Scale = factor;

            m_pDrawsLabel.Position      = new CCPoint(0, 51 * factor) + pos;
            m_pUpdateTimeLabel.Position = new CCPoint(0, 34 * factor) + pos;
            m_pDrawTimeLabel.Position   = new CCPoint(0, 17 * factor) + pos;
            m_pFPSLabel.Position        = pos;
        }
コード例 #3
0
        private void game_Deactivated(object sender, EventArgs e)
        {
#if ANDROID
            CCTextureCache.PurgeSharedTextureCache();
#endif
            ApplicationDidEnterBackground();
#if !IOS
            CocosDenshion.CCSimpleAudioEngine.SharedEngine.RestoreMediaState();
#endif
        }
コード例 #4
0
ファイル: CCDirector.cs プロジェクト: krashman/cocos2d-xna
        protected void PurgeDirector()
        {
            // cleanup scheduler
            Scheduler.UnscheduleAll();

            // don't release the event handlers
            // They are needed in case the director is run again
            m_pTouchDispatcher.RemoveAllDelegates();

            if (m_pRunningScene != null)
            {
                m_pRunningScene.OnExitTransitionDidStart();
                m_pRunningScene.OnExit();
                m_pRunningScene.Cleanup();
            }

            m_pRunningScene = null;
            m_pNextScene    = null;

            // remove all objects, but don't release it.
            // runWithScene might be executed after 'end'.
            m_pobScenesStack.Clear();

            StopAnimation();

            // purge bitmap cache
            CCLabelBMFont.PurgeCachedData();

            // purge all managed caches
            CCAnimationCache.PurgeSharedAnimationCache();
            CCSpriteFrameCache.PurgeSharedSpriteFrameCache();
            CCTextureCache.PurgeSharedTextureCache();
            // CCFileUtils.PurgeFileUtils();
            // CCConfiguration.purgeConfiguration();

            // cocos2d-x specific data structures
            CCUserDefault.PurgeSharedUserDefault();
            // CCNotificationCenter.purgeNotificationCenter();

            CCDrawManager.PurgeDrawManager();

            m_NeedsInit = true;
        }
コード例 #5
0
ファイル: CCDirector.cs プロジェクト: krashman/cocos2d-xna
        public void CreateStatsLabel()
        {
            if (m_pFPSLabel == null)
            {
                CCTexture2D    texture;
                CCTextureCache textureCache = CCTextureCache.SharedTextureCache;

                try
                {
                    if (!textureCache.Contains("cc_fps_images"))
                    {
                        texture = textureCache.AddImage(CCFPSImage.PngData, "cc_fps_images", SurfaceFormat.Bgra4444);
                    }
                    else
                    {
                        texture = textureCache.TextureForKey("cc_fps_images");
                    }

                    if (texture == null || (texture.ContentSize.Width == 0 && texture.ContentSize.Height == 0))
                    {
                        m_bDisplayStats = false;
                        return;
                    }
                }
                catch (Exception)
                {
                    // MonoGame may not allow texture.fromstream, so catch this exception here
                    // and disable the stats
                    m_bDisplayStats = false;
                    return;
                }

                try
                {
                    m_pFPSLabel = new CCLabelAtlas();
                    m_pFPSLabel.SetIgnoreContentScaleFactor(true);
                    m_pFPSLabel.InitWithString("00.0", texture, 12, 32, '.');

                    m_pUpdateTimeLabel = new CCLabelAtlas();
                    m_pUpdateTimeLabel.SetIgnoreContentScaleFactor(true);
                    m_pUpdateTimeLabel.InitWithString("0.000", texture, 12, 32, '.');

                    m_pDrawTimeLabel = new CCLabelAtlas();
                    m_pDrawTimeLabel.SetIgnoreContentScaleFactor(true);
                    m_pDrawTimeLabel.InitWithString("0.000", texture, 12, 32, '.');

                    m_pDrawsLabel = new CCLabelAtlas();
                    m_pDrawsLabel.SetIgnoreContentScaleFactor(true);
                    m_pDrawsLabel.InitWithString("000", texture, 12, 32, '.');

                    m_pMemoryLabel = new CCLabelAtlas();
                    m_pMemoryLabel.SetIgnoreContentScaleFactor(true);
                    m_pMemoryLabel.InitWithString("0", texture, 12, 32, '.');
                    m_pMemoryLabel.Color = new CCColor3B(0, 0, 255);

                    m_pGCLabel = new CCLabelAtlas();
                    m_pGCLabel.SetIgnoreContentScaleFactor(true);
                    m_pGCLabel.InitWithString("0", texture, 12, 32, '.');
                    m_pGCLabel.Color = new CCColor3B(255, 0, 0);
                }
                catch (Exception ex)
                {
                    m_pFPSLabel     = null;
                    m_bDisplayStats = false;
                    CCLog.Log("Failed to create the stats labels.");
                    CCLog.Log(ex.ToString());
                    return;
                }
            }

            float factor = CCDrawManager.DesignResolutionSize.Height / 320.0f;
            var   pos    = CCDirector.SharedDirector.VisibleOrigin;

            m_pFPSLabel.Scale        = factor;
            m_pUpdateTimeLabel.Scale = factor;
            m_pDrawTimeLabel.Scale   = factor;
            m_pDrawsLabel.Scale      = factor;
            m_pMemoryLabel.Scale     = factor;
            m_pGCLabel.Scale         = factor;

            m_pMemoryLabel.Position     = new CCPoint(0, 85 * factor) + pos;
            m_pGCLabel.Position         = new CCPoint(0, 68 * factor) + pos;
            m_pDrawsLabel.Position      = new CCPoint(0, 51 * factor) + pos;
            m_pUpdateTimeLabel.Position = new CCPoint(0, 34 * factor) + pos;
            m_pDrawTimeLabel.Position   = new CCPoint(0, 17 * factor) + pos;
            m_pFPSLabel.Position        = pos;
        }