question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Canvas extract blank during pointerdown event

See original GitHub issue

I’m trying to extract a canvas from a sprite when it has been clicked or tapped. For some reason when I use the renderer’s extract all I get is an empty canvas with the proper width and height.

Here’s the essence of my code, I can provide the actual code if neccessary.

sprite.on("pointerdown", function (e) {
    // results in the blank canvas with the dimensions of the sprite
    var canvas = app.renderer.extract.canvas(sprite);

    window.open(canvas.toDataUrl());
});

I from my tests, the extract will work on any other DisplayObject within the pointerdown event except for the DisplayObject that is the target of the event. The extract will also work on the sprite in question when I use it outside of the pointerdown event. I’m using v4.5.3 by the way.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
modjkecommented, Jul 20, 2017

@jordanhe2 Besides resetting sprite’s position you should also reset pivot, anchor, rotation and scale

1reaction
jordanhe2commented, Jun 29, 2017

Right now I can work around it by doing the following:

sprite.interactive = true;
sprite.on("pointerdown", function (e) {
	var x = sprite.x;
	var y = sprite.y;

	// Re-render sprite at 0,0 to prevent shifting on canvas
	sprite.x = 0;
	sprite.y = 0;
	app.renderer.render(sprite);

	window.open(extract.canvas(sprite).toDataURL());

	// Place sprite back to normal position and let autoRender re-render it
	sprite.x = x;
	sprite.y = y;
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Using Pointer Events - Web APIs | MDN
This guide demonstrates how to use pointer events and the HTML <canvas> element to build a multi-touch enabled drawing application.
Read more >
Pointer Events - W3C
The events for handling generic pointer input look a lot like those for mouse: pointerdown , pointermove , pointerup , pointerover , pointerout ......
Read more >
Incorrect mouse down states related to holding of multiple ...
If you hold left you get pointerdown, if you then press any other button no events are fired. Just if you release all...
Read more >
WPF: Canvas mouse events not firing on empty space
A control with no background color set (explicitly or through styles etc) will default to having a background color of null - making...
Read more >
CSS pointer-events property - W3Schools
The numbers in the table specify the first browser version that fully supports the property. Property. pointer-events, 2.0, 11.0, 3.6, 4.0, 9.0 ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found