Sign in to follow this  

Code that runs on resize

Recommended Posts

Hey all, I want to resize an element but not as often as I currently do it.

Right now I have a project with an html element that gets resized on every frame and it runs on every update.

game.gui.TextArea = me.Renderable.extend({
  init: function() {
    this.textarea = document.createElement('textarea'); = 'textHistory';
    this.textarea.readOnly = "true";
    this.textarea.disabled = "true";;

  update: function() {
    videoPos =; = 'width:' + (window.innerWidth - videoPos.width)  + 'px; height:' + videoPos.height + 'px;';

I'm concerned about this, this code will run way more often than it needs. Not sure about the performance impact but it only needs to run when the window size is updated. Is there a way I can piggyback on any melonjs functions that resize the canvas and only run it then?

Share this post

Link to post
Share on other sites


you should be able to use the WINDOW_ONRESIZE event, that is triggered every time the display is resize, so for example  :

var self = this;

me.event.subscribe(me.event.WINDOW_ONRESIZE, function () {
   var videoPos =; = 'width:' + (window.innerWidth - videoPos.width)  + 'px; height:' + videoPos.height + 'px;';

also the size you can also directly use the default game camera/viewport ( and that is also automatically resize to match with the canvas size.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.