Jump to content

[solved] Sprites


George3D
 Share

Recommended Posts

I'm working with Sprites and using "pickSprite" and "pickedSprite" in this code:
  spriteManager.isPickable = true;
  player.isPickable = true;	
  var pickResult = scene.pickSprite(event.clientX, event.clientY);
  pickResult.pickedSprite.cellIndex = 1;

It's part of a program with a crawling bug you have to hit with a mouse click. But there is no hit possible. Only if the bug doesn't move I can hit it with the mouse.

 

Link to comment
Share on other sites

I found another (longer-winded) way:

function pickIntersect (point, pos, diff) {
  if ((point.x > pos.x-diff) && (point.x < pos.x+diff) 
  &&  (point.z > pos.z-diff) && (point.z < pos.z+diff))
    return true;
  return false;
}

if (pickIntersect(pickResult.pickedPoint, player.position, 2))
  player.cellIndex = 1;

 

Link to comment
Share on other sites

Even without the image, you can just console.log when hit to see that it is working.

But one thing: you should not add the click event on the window because you will capture all clicks event outside the canvas. You should instead use the scene.onPointerObservable:

http://doc.babylonjs.com/classes/2.5/scene#onpointerobservable-observable-classes-2-5-observable-lt-pointerinfo-classes-2-5-pointerinfo-gt-

Example here:

http://www.babylonjs-playground.com/#10OY8W#5

To get the correct X and Y for the mouse you can use scene.pointerX / Y

Link to comment
Share on other sites

Thank you your efforts,
in the meantime I found out: the picking is working. It's my problem, I hit the bug very rarely.
Thanks also for the "click-hints".
And a new question: What ist the difference between clientX/Y and pointerX/Y?
Both seem to work equally.
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...