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);
html5 animate-cc save-image
add a comment |
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);
html5 animate-cc save-image
add a comment |
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);
html5 animate-cc save-image
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
html5 animate-cc save-image
asked Nov 9 at 11:04
kkg
11
11
add a comment |
add a comment |
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);
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
add a comment |
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);
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
add a comment |
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);
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
add a comment |
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);
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);
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
add a comment |
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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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