Jump to content

Possible To Draw Off Of The Canvas?


JeZxLee
 Share

Recommended Posts

Hi,

Currently we stretch the game display to fill the Android screen which looks bad.
We want to maintain aspect ration and draw a joystick on the part of the Android screen that has nothing on it.
Is it possible to draw sprites off of the PixiJSv4 canvas?

Little confused about this, any help would be appreciated, thanks!

JeZxLee

Link to comment
Share on other sites

Here is the current resize code:

 

function CheckForBrowserResize(forceResize)
{
	if (DONTRESIZE == true)
	{
		renderer.resize( Math.floor(OriginalCanvasWidth), Math.floor(OriginalCanvasHeight) );
		renderer.view.style.position = 'absolute';
		renderer.view.style.left = 0;
		stage.scale.set( 1, 1 );
		
		return;
	}
	
	if (forceResize == false)
	{
		var oldBrowserWidth = CurrentBrowserWidth;
		var oldBrowserHeight = CurrentBrowserHeight;
	}
	
	if (window.innerWidth != OriginalCanvasWidth || window.innerHeight != OriginalCanvasHeight)
	{
		CurrentBrowserWidth = window.innerWidth;
		CurrentBrowserHeight = window.innerHeight;
		
		if (forceResize == true)
		{
			if (OriginalCanvasWidth > CurrentBrowserWidth)
			{
				widthScale = ( widthScale * (CurrentBrowserWidth / OriginalCanvasWidth) );
			}
			else if (OriginalCanvasWidth < CurrentBrowserWidth)
			{
				widthScale = ( widthScale * (CurrentBrowserWidth / OriginalCanvasWidth) );
			}
			
			if (OriginalCanvasHeight > CurrentBrowserHeight)
			{
				heightScale = ( heightScale * (CurrentBrowserHeight / OriginalCanvasHeight) );
			}
			else if (OriginalCanvasHeight < CurrentBrowserHeight)
			{
				heightScale = ( heightScale * (CurrentBrowserHeight / OriginalCanvasHeight) );
			}
		}
		else
		{
			if (oldBrowserWidth > CurrentBrowserWidth)
			{
				widthScale = ( widthScale * (CurrentBrowserWidth / oldBrowserWidth) );
			}
			else if (oldBrowserWidth < CurrentBrowserWidth)
			{
				widthScale = ( widthScale * (CurrentBrowserWidth / oldBrowserWidth) );
			}
			
			if (oldBrowserHeight > CurrentBrowserHeight)
			{
				heightScale = ( heightScale * (CurrentBrowserHeight / oldBrowserHeight) );
			}
			else if (oldBrowserHeight < CurrentBrowserHeight)
			{
				heightScale = ( heightScale * (CurrentBrowserHeight / oldBrowserHeight) );
			}
		}
		
//		if (isMobile == false)
		{
			if (widthScale < heightScale)
			{
				CurrentBrowserHeight = CurrentBrowserHeight * (widthScale / heightScale);
				heightScale = widthScale;
			}
			else if (widthScale > heightScale)
			{
				CurrentBrowserWidth = CurrentBrowserWidth * (heightScale / widthScale);
				widthScale = heightScale;
			}
		}

		renderer.resize( Math.floor(OriginalCanvasWidth*widthScale), 
        Math.floor(OriginalCanvasHeight*heightScale) );
		renderer.view.style.position = 'absolute';
		renderer.view.style.left = (  ( window.innerWidth - (renderer.width) ) >> 1  ) + 'px';
		stage.scale.set( widthScale, heightScale );
	}
}

 

Link to comment
Share on other sites

But you might find 1 big canvas (e.g. with containers to scale and position the parts separately), maybe would perform better for your target Android devices - I'd try both approaches before committing or trying to make it look nice

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...