Welcome Guest! To enable all features please Login or Register.



Go to last post Go to first unread
#1 Posted : Friday, August 24, 2018 1:55:49 PM(UTC)

Rank: Newbie

Groups: Registered
Joined: 8/23/2018(UTC)
Posts: 0
Location: Jakarta

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');
    this.textarea.id = 'textHistory';
    this.textarea.readOnly = "true";
    this.textarea.disabled = "true";

  update: function() {
    videoPos = me.video.getPos();
    this.textarea.style = '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?

#2 Posted : Wednesday, August 29, 2018 10:26:25 AM(UTC)

Rank: Administration

Groups: Administrators
Joined: 8/7/2018(UTC)
Posts: 1


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 = me.video.getPos();
   self.textarea.style = 'width:' + (window.innerWidth - videoPos.width)  + 'px; height:' + videoPos.height + 'px;';

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

Is an exciting and highly creative company focusing around delivering games and services for the mobile and web platforms.

#3 Posted : Friday, September 20, 2019 3:39:59 AM(UTC)

Rank: Newbie

Groups: Registered
Joined: 9/20/2019(UTC)
Posts: 0

Thanks for sharing.....
Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.