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.

pointerdown not working on text

See original GitHub issue

The alert below never gets called, I have tried registering the pointer event using both the text object and its bounds.

<html>
<head>
	<title>MelonJS Text pointerdown not working</title>
	<script src="https://cdn.jsdelivr.net/npm/melonjs@7.1.1/dist/melonjs.js"></script>
	<script>
		let menu=me.Stage.extend({
			init:function(){
				this._super(me.Stage,'init');
			},
			onResetEvent:function(){
				this.text=new me.Text(me.game.viewport.getWidth()/2,me.game.viewport.getHeight()/2,{
					font:'sans-serif',
					size:72,
					text:'test',
					anchorPoint:new me.Vector2d(0.5,0.5),
					fillStyle:'#ffffff',
					strokeStyle:'#ffffff'
				});
				me.input.registerPointerEvent('pointerdown',this.text,function(){alert('pointerdown')});
				me.input.registerPointerEvent('pointerdown',this.text.getBounds(),function(){alert('pointerdown')});
				me.game.world.addChild(this.text);
			}
		});
		me.device.onReady(function(){
			me.video.init(document.body.clientWidth,document.body.clientHeight,{
				wrapper:'screen',
				scale:'auto',
				scaleMethod:'flex'
			});
			me.loader.preload([],function(){
				me.state.set(me.state.MENU,new menu());
				me.state.change(me.state.MENU);
			});
		});
	</script>
	<style>
		#screen{
			position:absolute;
			left:0;
			top:0;
			width:100%;
			height:100%;
		}
	</style>
</head>
<body>
<div id="screen"></div>
</div>
</body>
</html>

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
customautosyscommented, May 5, 2020

Yup! Text click working. Thanks for attending to my queries!

0reactions
obiotcommented, May 5, 2020

sure, good idea ! so it’s working ?

by the way I’m still working on your example, I’m in the process of rewriting some of the canvas resizing related function of melonJS to be more robust, testing and using your example along to debug it 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mousedown, pointerdown events not working when keep ...
pointerdown / mousedown events do not fire continuously while the button is held. So, you'll need detect two events: when button was pressed ......
Read more >
Pointer events - Web APIs | MDN
Note: Pointer events are not available in Web Workers. Pointer events are DOM events that are fired for a pointing device.
Read more >
Prevented default in onPointerDown does not trigger ... - GitHub
Hmm, I'll take a look at this today. It looks like using mousedown instead of pointerdown is also causing some issues with newer...
Read more >
How does the .on('pointerdown') listener work? [Possible Bug]
The problem is that after the first press, if you do not move your cursor out of the sprite, you have to click...
Read more >
Pointer events - The Modern JavaScript Tutorial
Pointer events are a modern way to handle input from a variety of pointing devices, such as a mouse, a pen/stylus, a touchscreen,...
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