Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can I seek help with Sprite's containsPoint method here? #43

Open
crazyyi opened this issue Jan 6, 2017 · 2 comments
Open

Can I seek help with Sprite's containsPoint method here? #43

crazyyi opened this issue Jan 6, 2017 · 2 comments

Comments

@crazyyi
Copy link

crazyyi commented Jan 6, 2017

[Help Wanted] I have read the part of the book about the global position and local position. However I am stuck on using the containsPoint function of the PIXI.Sprite class. I can never get it to work correctly. Suppose I put everything into a parent container which is in stage. My player sprite is moving around using your camera centerOver function in GameUtilities. When I move it the player rotates towards the mouse position. I want to check if other sprite is intersecting with my sprite's rectangle clip. So I check if the anchor of other sprites are contained in my sprite's clip, which is also a rectangle sprite. The clip sprite is just next to my player sprite and facing to the mouse direction. If an examining sprite is contained in the clip I will change the color of the sprite. Sadly none of the sprites is contained in the clip sprite as I move my player sprite around the map.

I have also tried getBounds().contains(x, y), and getLocalBounds().contains(x, y). None of them works.

And I have tried your hitTestCircleRectangle() method in bump.js. This one does work, finally. However it is not very accurate. The color of the examining sprite changes but some of them are outside of the bound of my clip sprite, which is not far away but the distance is noticeable.

Any hint on this one?

@crazyyi
Copy link
Author

crazyyi commented Jan 7, 2017

I've put it on https://codepen.io/caymanbruce/pen/WoBJYg?editors=0010
if you are interested.

@kittykatattack
Copy link
Owner

@crazyyi Hi! containsPoint is something I never use, but you can find a discussion about it here:

http://www.html5gamedevs.com/topic/14536-hittest-in-v3/

Can anyone out there reading this give @crazyyi some help with his code?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants