Update Canvas when Browser resizes

34 views
Skip to first unread message

Oren Shvalb

unread,
Dec 25, 2015, 12:22:55 AM12/25/15
to CreateJS Discussion
Hi guys,

I've read some articles about resizing the canvas , but non of them worked for me...

Can some one direct me how to do it right with EaselJS?


My best attempt was this:

window.addEventListener('resize', resize, false);

init
() {
   createjs
.Ticker.addEventListener('tick', handleTick);
   resize
();
}

function handleTick(event) {
  stage
.update();
}

function resize() {
  stage
.canvas.width = window.innerWidth;
  stage
.canvas.height = window.innerHeight;
}


Any ideas?


Sebastian DeRossi

unread,
Dec 25, 2015, 4:30:03 AM12/25/15
to createjs-...@googlegroups.com
Have you created a stage?

--
You received this message because you are subscribed to the Google Groups "CreateJS Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to createjs-discus...@googlegroups.com.
To post to this group, send email to createjs-...@googlegroups.com.
Visit this group at https://groups.google.com/group/createjs-discussion.
For more options, visit https://groups.google.com/d/optout.



--
<u>Sebastian DeRossi</u>

Oren Shvalb

unread,
Dec 25, 2015, 9:03:22 AM12/25/15
to CreateJS Discussion
yes, I have a stage.

The code that gave as an example running fine in my browser, but doesn't do what it supposed to do.


On Friday, December 25, 2015 at 4:30:03 AM UTC-5, Sebastian DeRossi wrote:
Have you created a stage?
On Thu, Dec 24, 2015 at 10:22 PM, Oren Shvalb <oren....@gmail.com> wrote:
Hi guys,

I've read some articles about resizing the canvas , but non of them worked for me...

Can some one direct me how to do it right with EaselJS?


My best attempt was this:

window.addEventListener('resize', resize, false);

init
() {
   createjs
.Ticker.addEventListener('tick', handleTick);
   resize
();
}

function handleTick(event) {
  stage
.update();
}

function resize() {
  stage
.canvas.width = window.innerWidth;
  stage
.canvas.height = window.innerHeight;
}


Any ideas?


--
You received this message because you are subscribed to the Google Groups "CreateJS Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to createjs-discussion+unsub...@googlegroups.com.

To post to this group, send email to createjs-...@googlegroups.com.
Visit this group at https://groups.google.com/group/createjs-discussion.
For more options, visit https://groups.google.com/d/optout.

Lanny McNie

unread,
Dec 27, 2015, 9:48:09 PM12/27/15
to CreateJS Discussion
I answered this question on StackOverflow -- not sure if it was you who asked it.

Basically, resizing the canvas element will give you more pixels, but not reflow your contents.

Hope that helps.

Oren Shvalb

unread,
Dec 27, 2015, 10:34:02 PM12/27/15
to CreateJS Discussion
Thank you very much!

I think I know understand what I need to do.

I was under the impression that resizing the canvas would also rescale the content, but like you suggested - I should put all the assets inside a container and scale it.
Reply all
Reply to author
Forward
0 new messages