• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Buttons stay visible false despite changing to true

Explorer ,
Aug 02, 2017 Aug 02, 2017

Copy link to clipboard

Copied

I have two functions who are supposed to make a couple of buttons on the stage invisible, capture a part of the canvas and then make some of those buttons visible again so the user can keep playing the game and save multiple pictures. However I cannot get the buttons to automatically become visible again. This is what I have:

this.Savepicbutton.addEventListener("click", savePartImage2.bind(this));

function savePartImage2()

{

this.Savepicbutton.visible = false;

this.Savepicbutton2.visible = false;

this.Savepicbutton3.visible = false;

this.Linkbutton4.visible = false;

this.Linkbutton3.visible = false;

this.Linkbutton2.visible = false;

setTimeout(savePartImage, 300);

}

function savePartImage()

{

var c=document.getElementById("canvas");

var backCanvas = document.createElement('canvas');

backCanvas.width = 700;

backCanvas.height = 900;

var backCtx = backCanvas.getContext('2d');

backCtx.drawImage(c, -500, 0, 1200, 900);

var d=backCanvas.toDataURL("image/jpeg");

    var w=window.open('about:blank','image from canvas');

    w.document.write("<img src='"+d+"' alt='from canvas'/>");

this.Savepicbutton.visible = true;

this.Savepicbutton2.visible = true;

this.Savepicbutton3.visible = true;

this.Linkbutton2.visible = true;

}

Without the setTimeout, the canvas is drawn before the buttons are turned invisible. I tried setting the selected buttons to true in the savePartImage2 function after the setTimeout but that caused the buttons to become visible before the canvas was drawn so they were visible in the captured image.

Any clue of what I'm doing wrong?

Views

295

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Aug 02, 2017 Aug 02, 2017

The first function has 'this' binded to it. The setTimeout doesn't. You could use this approach:

// in an early line in the script:

var self = this;

//then in your savePartImage function:

self.Savepicbutton.visible = true; 

self.Savepicbutton2.visible = true; 

self.Savepicbutton3.visible = true; 

self.Linkbutton2.visible = true;

Votes

Translate

Translate
LEGEND ,
Aug 02, 2017 Aug 02, 2017

Copy link to clipboard

Copied

The first function has 'this' binded to it. The setTimeout doesn't. You could use this approach:

// in an early line in the script:

var self = this;

//then in your savePartImage function:

self.Savepicbutton.visible = true; 

self.Savepicbutton2.visible = true; 

self.Savepicbutton3.visible = true; 

self.Linkbutton2.visible = true;

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Aug 02, 2017 Aug 02, 2017

Copy link to clipboard

Copied

LATEST

That worked out. Thank you kindly!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines