Problem in getting pixel perfect collision in cocos2d 3.3 ver

Hi,

I used the tutorial from Pixel collision detection for v3.x in the following manner :-

1.) First of all I created the “PixelCollision.h” and “PixelCollision.cpp” file.

2.) After that I copy past the code from Pixel collision detection for v3.x

to both of the file.

3.) After that in my “GameScene.h” file I included the “PixelCollision.h”

like this- #include “PixelCollision.h”

4.) Then I added the SolidColorShader.vsh and the SolidColorShader.fsh in my resource folder.

5.) After that in “GameScene.cpp” I call the “collidesWithSprite( s1,s2,true)”

like this -

if (PixelCollision::getInstance()->collidesWithSprite(sprite_Up, PlaneSprite, true)){}

on the above line I’m getting the error
The program ‘[2716] TaskHost.exe’ has exited with code -1073741819 (0xc0000005) ‘Access violation’.

Please help me.

Do you have the SolidColorShader.vsh and the SolidColorShader.fsh in your project? You didn’t mention them in your post. So maybe you forgot to create those files?

Thanks for replay.

Yes I have included them in Resource folder.

Hi,

The path to the shaders file is defined as a constant in PixelCollision.cpp as follow:

static const auto kVertexShader = "Shaders/SolidColorShader.vsh";
static const auto kFragmentShader = "Shaders/SolidColorShader.fsh";

Make sure you have added the shaders into a Resources/Shaders directory or change the paths accordingly :wink:.

I hope it helps.

Hi sgleizes,

Thanks for your reply.

I have added the shaders into a Resources directory.

Please tell me what is the problem.

From your Resources folder, you need to add the shaders files into a new directory named Shaders.

You need to have Resources/Shaders/SolidColorShader.vsh and Resources/Shaders/SolidColorShader.fsh.

As I said the files are referenced in PixelCollision.cpp. You can also change the path if you don’t want a Shaders folder.

Thanks for your reply.

I have change the path in PixelCollision.cpp .

but same result.

no success.

If this is on iOS, make sure the files are also added in the Xcode project, otherwise they will not get copied into the bundle, even if they are in the resources folder.

Thanks for your reply

No it’s not on IOS.

It’ on windows.

I also encountered similar problems. As I see it seems cocos2dx not load shader file. This problem occurs only on windows phone. On normal ios and android. anyone suggest anything?

Yes. Unfortunately on windows phone you can’t use traditional OpenGL shaders. You have to precompile your customs shaders for DirectX…
See this post for more information on how to do it.
Maybe I should specify that in the heading post.

Will do.