Game Development Community

Aspect ratio again

by natchooo · in Torque Game Builder · 07/14/2009 (1:45 pm) · 5 replies

Hello,

I know this question has been asked several times but i have not found a satisfying answer :
Is there a way to have black bands in full screen when the aspect ratio of the screen is different from the one of the scene ?
I have a scene in 1280x1024 and when the game runs on a 1920x1080 screen it is stretched in a bad way because the aspect ratio is different.

The solutions i found on this forum only concern GUI objects, but what about sprites ?
If anyone has an idea on how to fix this problem, please let me know.

Thank you very much in advance.

About the author

Recent Threads

  • Font issue : artefacts

  • #1
    07/14/2009 (1:51 pm)
    It's up to the graphics drivers to support things like stretching/scaling, really. Happens automatically on Mac, should be supported by ATI on Windows and is in a sorry state for nVidia on Windows.

    You can add support to your game by having scenes at various aspects (set width:height ratios to 4:3, 5:4, 16:10 and 16:9 for the variations). Search around the site for some threads on calculating and getting width/height in proper relations.
    #2
    07/14/2009 (2:37 pm)
    Ok thanks for your answer.
    #3
    07/15/2009 (2:57 pm)
    I've added the following script to our baseline to center the scene window when the resolution doesn't match our design resolution.

    $qInExtentChange = false;
    function sceneWindow2D::onExtentChange( %this, %data )
    {
      if( $qInExtentChange ) return;
      $qInExtentChange = true;
      setAcceptableScreenRatio();  
      $qInExtentChange = false;
    }
    
    function setAcceptableScreenRatio()
    {
      %screenWidth = getWord( Canvas.extent, 0 );
      %screenHeight = getWord( Canvas.extent, 1 );
    
      %screenRatio = %screenWidth / %screenHeight;
      %optimalRatio = 1024.0 / 768.0;  // WLS - Our Design resolution
      
      %newWidth = %screenWidth;
      %newHeight = %screenHeight;
      if( %screenRatio < %optimalRatio )
        %newHeight = %screenWidth / %optimalRatio;
      else if( %screenRatio > %optimalRatio )
        %newWidth = %screenHeight * %optimalRatio;
      %newX = (%screenWidth - %newWidth) / 2.0;
      %newY = (%screenHeight - %newHeight) / 2.0;
      sceneWindow2D.setPosition( %newX, %newY );
      sceneWindow2D.setExtent( %newWidth, %newHeight );
    }
    #4
    07/15/2009 (11:39 pm)
    Thank you very much, i will try that.
    #5
    07/16/2009 (12:37 am)
    That looks useful Wiliam, thanks for sharing.