Jump to content

Sprite height relative to stage / container


Fovi
 Share

Recommended Posts

Hi,

Is there any function for relative sprite height / width (%) ?

I need sprite with 50% height of stage, now i keep tracking height of root stage and re-calculate height's. Is there better way to do it ? Like:

stage{
position:relative;
}
sprite{
position:absolute;
height:50%;
width:100%;
}

 

Link to comment
Share on other sites

I think the closest thing is stage scaling. That way no matter how many sprites you add, on resize you only have to set the stage's scale instead of each sprite's.

Here's a little Code Pen that does this to keep the sprite sized at 100% by 50% of the stage dimensions (you have to open on CodePen to see it resize).

 

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...