Hello. I know there’re already some similiar topics in this forum, but none of them gives the actual answer to the problem. I’ve been struggling with pixel perfect collision for 2 weeks now and I have absolutely no idea how to make it work properly. I would add that I had never programmed anything in OpenGL before. So my question is: does anyone have working code for pixel perfect collision detection using latest Cocos2d-x version?
Isn’t the collision detection in cocos2d-x already pixel-perfect?
Are you looking to do Physics. if so even box2d clamed it’s not to be pixel perfect, But i find it to be perfect i don’t find any problem with it,. problem is of overheld thinking like speed distance next step and so on calculating if its just 2 simple object…
cocos2dx has its own detection you can use…
//Cocos 3 or 4
const auto& boundingBox = item → getBoundingBox ( );
boundingBox . intersectsRect(Rect(0,0,20,20)); // your other object
boundingBox . intersectsCircle(Vec2(20,20),20); //Because don’t know the shape your working with
I will add this as a demo in my programs so people can test it.
Hop this help you out.
Cpp-tests also demonstrates this many times.
Could you possibly tell me in which exact file can I find an implementation of this?
Any of the physics examples demonstrate this plus there are examples using containsPoint()
Thanks a lot, but is there any other way of achieving pixel perfect collision detection without using the physics engine? In cocos 3.x versions I was using custom shaders to color sprites red and blue, then rendered them with ADDITIVE BlendFunc and finally read pixels with glReadPixels. I know a lot has changed since then (e.g OpenGL end of life on IOS), hence my question, is it still possible to implement something similar in the latest cocos version?
Relatively using bounding box and containsPoint()