CCRect CalculateResolutionRatio(CCRect resolutionRect, CCSceneResolutionPolicy resolutionPolicy) { var width = resolutionRect.Size.Width; var height = resolutionRect.Size.Height; if (width == 0.0f || height == 0.0f) { return(exactFitRatio); } var designResolutionSize = resolutionRect.Size; var viewPortRect = CCRect.Zero; float resolutionScaleX, resolutionScaleY; var screenSize = Scene.Window.WindowSizeInPixels; resolutionScaleX = screenSize.Width / designResolutionSize.Width; resolutionScaleY = screenSize.Height / designResolutionSize.Height; if (resolutionPolicy == CCSceneResolutionPolicy.NoBorder) { resolutionScaleX = resolutionScaleY = Math.Max(resolutionScaleX, resolutionScaleY); } else if (resolutionPolicy == CCSceneResolutionPolicy.ShowAll) { resolutionScaleX = resolutionScaleY = Math.Min(resolutionScaleX, resolutionScaleY); } else if (resolutionPolicy == CCSceneResolutionPolicy.FixedHeight) { resolutionScaleX = resolutionScaleY; designResolutionSize.Width = (float)Math.Ceiling(screenSize.Width / resolutionScaleX); } else if (resolutionPolicy == CCSceneResolutionPolicy.FixedWidth) { resolutionScaleY = resolutionScaleX; designResolutionSize.Height = (float)Math.Ceiling(screenSize.Height / resolutionScaleY); } // calculate the rect of viewport float viewPortW = designResolutionSize.Width * resolutionScaleX; float viewPortH = designResolutionSize.Height * resolutionScaleY; viewPortRect = new CCRect((screenSize.Width - viewPortW) / 2, (screenSize.Height - viewPortH) / 2, viewPortW, viewPortH); var viewportRatio = new CCRect( ((viewPortRect.Origin.X) / screenSize.Width), ((viewPortRect.Origin.Y) / screenSize.Height), ((viewPortRect.Size.Width) / screenSize.Width), ((viewPortRect.Size.Height) / screenSize.Height) ); DesignResolutionSize = designResolutionSize; return(viewportRatio); }
public CCScene(CCWindow window, CCViewport viewport, CCDirector director = null) #endif { IgnoreAnchorPointForPosition = true; AnchorPoint = new CCPoint(0.5f, 0.5f); Viewport = viewport; Window = window; Director = (director == null) ? window.DefaultDirector : director; if (window != null && director != null) { window.AddSceneDirector(director); } #if USE_PHYSICS _physicsWorld = physics ? new CCPhysicsWorld(this) : null; #endif resolutionPolicy = DefaultDesignResolutionPolicy; DesignResolutionSize = DefaultDesignResolutionSize; UpdateResolutionRatios(); }
public void SetDefaultDesignResolution(CCSceneResolutionPolicy policy = CCSceneResolutionPolicy.ShowAll) { // This will set the world bounds to be (0,0, w, h) // CCSceneResolutionPolicy.ShowAll will ensure that the aspect ratio is preserved CCScene.SetDefaultDesignResolution(DESIRED_WIDTH, DESIRED_HEIGHT, policy); // Determine whether to use the high or low def versions of our images // Make sure the default texel to content size ratio is set correctly // Of course you're free to have a finer set of image resolutions e.g (ld, hd, super-hd) application.ContentSearchPaths.Remove("hd"); application.ContentSearchPaths.Remove("ld"); if (DESIRED_WIDTH < Width) { application.ContentSearchPaths.Add("hd"); CCSprite.DefaultTexelToContentSizeRatio = 2.0f; } else { application.ContentSearchPaths.Add("ld"); CCSprite.DefaultTexelToContentSizeRatio = 1.0f; } }
public void SetDesignResolutionSize(float width, float height, CCSceneResolutionPolicy resolutionPolicy) { designResolutionSize = new CCSize(width, height); DesignResolutionPolicy = resolutionPolicy; }
public void SetDesignResolutionSize(float width, float height, CCSceneResolutionPolicy resolutionPolicy) { CCScene.SetDefaultDesignResolution(width, height, resolutionPolicy); }
public static void SetDefaultDesignResolution(float width, float height, CCSceneResolutionPolicy resPolicy) { CCScene.DefaultDesignResolutionSize = new CCSize(width, height); CCScene.DefaultDesignResolutionPolicy = resPolicy; }
public void SetDesignResolutionSize(float width, float height, CCSceneResolutionPolicy resolutionPolicy) { CCScene.SetDefaultDesignResolution (width, height, resolutionPolicy); }
CCRect CalculateResolutionRatio(CCRect resolutionRect, CCSceneResolutionPolicy resolutionPolicy) { var width = resolutionRect.Size.Width; var height = resolutionRect.Size.Height; if (width == 0.0f || height == 0.0f) { return exactFitRatio; } var x = resolutionRect.Origin.X; var y = resolutionRect.Origin.Y; var designResolutionSize = resolutionRect.Size; var viewPortRect = CCRect.Zero; float resolutionScaleX, resolutionScaleY; // Not set anywhere right now. var frameZoomFactor = 1; var screenSize = Scene.Window.WindowSizeInPixels; resolutionScaleX = screenSize.Width / designResolutionSize.Width; resolutionScaleY = screenSize.Height / designResolutionSize.Height; if (resolutionPolicy == CCSceneResolutionPolicy.NoBorder) { resolutionScaleX = resolutionScaleY = Math.Max(resolutionScaleX, resolutionScaleY); } if (resolutionPolicy == CCSceneResolutionPolicy.ShowAll) { resolutionScaleX = resolutionScaleY = Math.Min(resolutionScaleX, resolutionScaleY); } if (resolutionPolicy == CCSceneResolutionPolicy.FixedHeight) { resolutionScaleX = resolutionScaleY; designResolutionSize.Width = (float)Math.Ceiling(screenSize.Width / resolutionScaleX); } if (resolutionPolicy == CCSceneResolutionPolicy.FixedWidth) { resolutionScaleY = resolutionScaleX; designResolutionSize.Height = (float)Math.Ceiling(screenSize.Height / resolutionScaleY); } // calculate the rect of viewport float viewPortW = designResolutionSize.Width * resolutionScaleX; float viewPortH = designResolutionSize.Height * resolutionScaleY; viewPortRect = new CCRect((screenSize.Width - viewPortW) / 2, (screenSize.Height - viewPortH) / 2, viewPortW, viewPortH); var viewportRatio = new CCRect( ((x * resolutionScaleX * frameZoomFactor + viewPortRect.Origin.X * frameZoomFactor) / screenSize.Width), ((y * resolutionScaleY * frameZoomFactor + viewPortRect.Origin.Y * frameZoomFactor) / screenSize.Height), ((width * resolutionScaleX * frameZoomFactor) / screenSize.Width), ((height * resolutionScaleY * frameZoomFactor) / screenSize.Height) ); return viewportRatio; }
public static void SetDefaultDesignResolution(float width, float height, CCSceneResolutionPolicy resPolicy) { CCScene.DefaultDesignResolutionSize = new CCSize (width, height); CCScene.DefaultDesignResolutionPolicy = resPolicy; }
public CCScene(CCWindow window, CCViewport viewport, CCDirector director = null) #endif { IgnoreAnchorPointForPosition = true; AnchorPoint = new CCPoint(0.5f, 0.5f); Viewport = viewport; Window = window; Director = (director == null) ? window.DefaultDirector : director; if (window != null && director != null) window.AddSceneDirector(director); #if USE_PHYSICS _physicsWorld = physics ? new CCPhysicsWorld(this) : null; #endif resolutionPolicy = DefaultDesignResolutionPolicy; DesignResolutionSize = DefaultDesignResolutionSize; UpdateResolutionRatios(); }