append link in-game of saved image











up vote
0
down vote

favorite












I made a dress up game in Animate CC using HTML5 Canvas. And at the end, the user can save the character as an image.



My problem has been how to append this image on the game.



At first, i simply created a link, which would appear below the game (solo, the person would need to scroll down to see the link; if it was embeded, I'm not sure how it would work, so i tried alternatives). And because it could confusing to find it, i also created an alert box.



I've now managed to get this image to automatically open in a new window, which is better - however, this doesn't work in Chrome, as it opens a blank window.



So I wonder if there is a another/better way to do this..?



Ideally, it would be great to trigger an object in-game that would appear near the save image button, that could contain the link (or as many as the user saves). But I don't know enough about programming to do that...



This is the current code:



    var hiddenCanvas = document.createElement('canvas');
hiddenCanvas.width = canvas.width * 0.388;
hiddenCanvas.height = canvas.height;
var canvasContext = hiddenCanvas.getContext('2d');
canvasContext.drawImage(
canvas,
0,
0,
canvas.width * 0.388,
canvas.height,
0,
0,
canvas.width * 0.388,
canvas.height);

var aTag = document.createElement('a');
aTag.setAttribute('href', hiddenCanvas.toDataURL("image/png"));

aTag.innerHTML = "Criámos uma imagem do teu Doutor. Salva-a aqui! :O)";

aTag.download = "ONV_oTeuDoutor.png";

window.open(aTag);









share|improve this question


























    up vote
    0
    down vote

    favorite












    I made a dress up game in Animate CC using HTML5 Canvas. And at the end, the user can save the character as an image.



    My problem has been how to append this image on the game.



    At first, i simply created a link, which would appear below the game (solo, the person would need to scroll down to see the link; if it was embeded, I'm not sure how it would work, so i tried alternatives). And because it could confusing to find it, i also created an alert box.



    I've now managed to get this image to automatically open in a new window, which is better - however, this doesn't work in Chrome, as it opens a blank window.



    So I wonder if there is a another/better way to do this..?



    Ideally, it would be great to trigger an object in-game that would appear near the save image button, that could contain the link (or as many as the user saves). But I don't know enough about programming to do that...



    This is the current code:



        var hiddenCanvas = document.createElement('canvas');
    hiddenCanvas.width = canvas.width * 0.388;
    hiddenCanvas.height = canvas.height;
    var canvasContext = hiddenCanvas.getContext('2d');
    canvasContext.drawImage(
    canvas,
    0,
    0,
    canvas.width * 0.388,
    canvas.height,
    0,
    0,
    canvas.width * 0.388,
    canvas.height);

    var aTag = document.createElement('a');
    aTag.setAttribute('href', hiddenCanvas.toDataURL("image/png"));

    aTag.innerHTML = "Criámos uma imagem do teu Doutor. Salva-a aqui! :O)";

    aTag.download = "ONV_oTeuDoutor.png";

    window.open(aTag);









    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I made a dress up game in Animate CC using HTML5 Canvas. And at the end, the user can save the character as an image.



      My problem has been how to append this image on the game.



      At first, i simply created a link, which would appear below the game (solo, the person would need to scroll down to see the link; if it was embeded, I'm not sure how it would work, so i tried alternatives). And because it could confusing to find it, i also created an alert box.



      I've now managed to get this image to automatically open in a new window, which is better - however, this doesn't work in Chrome, as it opens a blank window.



      So I wonder if there is a another/better way to do this..?



      Ideally, it would be great to trigger an object in-game that would appear near the save image button, that could contain the link (or as many as the user saves). But I don't know enough about programming to do that...



      This is the current code:



          var hiddenCanvas = document.createElement('canvas');
      hiddenCanvas.width = canvas.width * 0.388;
      hiddenCanvas.height = canvas.height;
      var canvasContext = hiddenCanvas.getContext('2d');
      canvasContext.drawImage(
      canvas,
      0,
      0,
      canvas.width * 0.388,
      canvas.height,
      0,
      0,
      canvas.width * 0.388,
      canvas.height);

      var aTag = document.createElement('a');
      aTag.setAttribute('href', hiddenCanvas.toDataURL("image/png"));

      aTag.innerHTML = "Criámos uma imagem do teu Doutor. Salva-a aqui! :O)";

      aTag.download = "ONV_oTeuDoutor.png";

      window.open(aTag);









      share|improve this question













      I made a dress up game in Animate CC using HTML5 Canvas. And at the end, the user can save the character as an image.



      My problem has been how to append this image on the game.



      At first, i simply created a link, which would appear below the game (solo, the person would need to scroll down to see the link; if it was embeded, I'm not sure how it would work, so i tried alternatives). And because it could confusing to find it, i also created an alert box.



      I've now managed to get this image to automatically open in a new window, which is better - however, this doesn't work in Chrome, as it opens a blank window.



      So I wonder if there is a another/better way to do this..?



      Ideally, it would be great to trigger an object in-game that would appear near the save image button, that could contain the link (or as many as the user saves). But I don't know enough about programming to do that...



      This is the current code:



          var hiddenCanvas = document.createElement('canvas');
      hiddenCanvas.width = canvas.width * 0.388;
      hiddenCanvas.height = canvas.height;
      var canvasContext = hiddenCanvas.getContext('2d');
      canvasContext.drawImage(
      canvas,
      0,
      0,
      canvas.width * 0.388,
      canvas.height,
      0,
      0,
      canvas.width * 0.388,
      canvas.height);

      var aTag = document.createElement('a');
      aTag.setAttribute('href', hiddenCanvas.toDataURL("image/png"));

      aTag.innerHTML = "Criámos uma imagem do teu Doutor. Salva-a aqui! :O)";

      aTag.download = "ONV_oTeuDoutor.png";

      window.open(aTag);






      html5 animate-cc save-image






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 11:04









      kkg

      11




      11
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote













          You can capture a screenshot of your Canvas at any instant using the following:



          var src = canvas.toDataURL();
          var image = document.createElement('img');
          image.src = src;


          You can then add it to your DOM using :-



          document.body.appendChild(image);





          share|improve this answer





















          • Yes, "document.body.appendChild(image);" was how I did it first. But I wasn't sure if the link would be very noticeable. I was trying to come up with an alternative to this.
            – kkg
            Nov 12 at 12:37











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224514%2fappend-link-in-game-of-saved-image%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          You can capture a screenshot of your Canvas at any instant using the following:



          var src = canvas.toDataURL();
          var image = document.createElement('img');
          image.src = src;


          You can then add it to your DOM using :-



          document.body.appendChild(image);





          share|improve this answer





















          • Yes, "document.body.appendChild(image);" was how I did it first. But I wasn't sure if the link would be very noticeable. I was trying to come up with an alternative to this.
            – kkg
            Nov 12 at 12:37















          up vote
          0
          down vote













          You can capture a screenshot of your Canvas at any instant using the following:



          var src = canvas.toDataURL();
          var image = document.createElement('img');
          image.src = src;


          You can then add it to your DOM using :-



          document.body.appendChild(image);





          share|improve this answer





















          • Yes, "document.body.appendChild(image);" was how I did it first. But I wasn't sure if the link would be very noticeable. I was trying to come up with an alternative to this.
            – kkg
            Nov 12 at 12:37













          up vote
          0
          down vote










          up vote
          0
          down vote









          You can capture a screenshot of your Canvas at any instant using the following:



          var src = canvas.toDataURL();
          var image = document.createElement('img');
          image.src = src;


          You can then add it to your DOM using :-



          document.body.appendChild(image);





          share|improve this answer












          You can capture a screenshot of your Canvas at any instant using the following:



          var src = canvas.toDataURL();
          var image = document.createElement('img');
          image.src = src;


          You can then add it to your DOM using :-



          document.body.appendChild(image);






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 18:00









          thirstyClouds

          1245




          1245












          • Yes, "document.body.appendChild(image);" was how I did it first. But I wasn't sure if the link would be very noticeable. I was trying to come up with an alternative to this.
            – kkg
            Nov 12 at 12:37


















          • Yes, "document.body.appendChild(image);" was how I did it first. But I wasn't sure if the link would be very noticeable. I was trying to come up with an alternative to this.
            – kkg
            Nov 12 at 12:37
















          Yes, "document.body.appendChild(image);" was how I did it first. But I wasn't sure if the link would be very noticeable. I was trying to come up with an alternative to this.
          – kkg
          Nov 12 at 12:37




          Yes, "document.body.appendChild(image);" was how I did it first. But I wasn't sure if the link would be very noticeable. I was trying to come up with an alternative to this.
          – kkg
          Nov 12 at 12:37


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53224514%2fappend-link-in-game-of-saved-image%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          這個網誌中的熱門文章

          Hercules Kyvelos

          Tangent Lines Diagram Along Smooth Curve

          Yusuf al-Mu'taman ibn Hud