Jump to content

Mousedown not recognized


RetardVeverca
 Share

Recommended Posts

Hi!

 

I have developed many demos with Panda.js, but today I tried one of them and mousedown event (on sprite) suddenly stopped working. It works in browser but not in CocoonJS launcher or cocoonJS packaged APK. I did not changed CocoonJS launcher, I also built the APK with same (1.4.7) version nor did I changed Panda.js. There are no errors shown in Chrome debug window nor in CocoonJS debug mode.

Because I couldnt find any errors and I stripped the code entirely I updated Panda.js to new version and now I get an error in CocoonJS launcher debug mode:

 

Javascript Exception (Tag: 'touchend'):

TypeError: Cannot read property '70' of undefined

   at PIXI.InteractionManager.onTouchEnd(src/engine/renderer.js:3757:33)

   at HTMLCanvasElement. <anonymous> (src/engine/core.js:572:18)

 

My source code:

game.module(      'game.main'  )  .require(      'engine.core')  .body(function() {  game.addAsset('media/backi.png', 'start');    game.addAsset('media/countdown.png', 'menu');  SceneStart = game.Scene.extend({ 	backgroundColor: 0x000000,     init: function() { 	        this.ozadje = new game.Sprite('start');  		this.ozadje.anchor.set(0, 0);		this.ozadje.position.set(0,0);		this.ozadje.interactive = true;		this.ozadje.mousedown = function(){			game.system.setScene(SceneMenu);		};        this.stage.addChild(this.ozadje); 				 		         }});SceneMenu = game.Scene.extend({ 	backgroundColor: 0x000000,     init: function() {         this.ozadje2 = new game.Sprite('menu');		this.ozadje2.position.set(0,0);				this.ozadje2.anchor.set(0, 0);        this.stage.addChild(this.ozadje2); 		    } }); game.System.idtkScale = 'ScaleAspectFill';  game.start(SceneStart, 480, 800);    });   

And you can download .zip for uploading to CocoonJS here: http://89.212.238.92/Journey/chick_debug.zip

Link to comment
Share on other sites

And if I remove the mousedown event from sprite in first scene and instead make whole scene interactive:

SceneStart = game.Scene.extend({ 	backgroundColor: 0x000000,     init: function() { 	        this.ozadje = new game.Sprite('start');  		this.ozadje.anchor.set(0, 0);		this.ozadje.position.set(0,0);		this.ozadje.interactive = true;        this.stage.addChild(this.ozadje); 		    },	mousedown: function() { 		game.system.setScene(SceneMenu);	}});

everything works. So there is really a problem in my mousedown event only for sprite!  :(

Link to comment
Share on other sites

Hi!

 

I just pushed new version to master branch, it should fix that error.

 

Mobile devices uses touch events instead of mouse events, so that's why it is not working.

var sprite = new game.Sprite('sprite.png');sprite.interactive = true;sprite.mousedown = function() {    // Mouse event};sprite.touchstart = function() {    // Touch event};

Scene's touch event's are automatically binded to mouse events, so that's why mousedown on scene works.

 

I know that's a little confusing, sprite's should autobind touch events too, or then remove autobind from scene?

Link to comment
Share on other sites

Thank you, your fix works :D

 

I think if there is no difference regarding mobile use (like with DOM, which waits for doubleclick and touch is not the same as click in some engines), I think it should autobind. If there are differences, then not ;)

 

Also I just figured it out, it works (without updating your fix from master branch) if I set my sprite with shorthand version like so:

this.ozadje = new game.Sprite('start', 0,0, {   anchor: {x:0, y:0},   interactive: true,   mousedown: function() {	game.system.setScene(SceneMenu);   }			});		this.stage.addChild(this.ozadje); 

Why is that?

Link to comment
Share on other sites

Mouse and touch events are different things, but afaik, there is no device that uses both.

Most of mobile devices uses touch events (Windows Phone uses mouse events).

 

So if you want to support desktop and mobile devices, you should bind both events.

 

Shorthand version also autobinds touch events.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...