Oke so a litle summary of wat I dit. The script isn't going to work in a normal enviorment like Firefox or internet Explorer if it isn't compiled through a server. Safari and Chrome I dont now I dident try this. But if you use Firefox or Explorer it will give you the Security error" code: "1000. If you are using getImageData and setInterval in combination you need to compile the code on a server. What I use now is "WampServer" (Can be google't) that just makes a virtual server on your computer for the time being. I also posted a nother topic where "Kyle Jones" told me to put this in the script:
netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
To ignore the error but it made a break out of the error. Not a real break but the code behind getImageData wassent being compiled anymore. So the thing to do is just compile your code on a Virtual or a real server to look if it works.
The HTML5 Javascript Perfect Pixel collision code:
var FPS = 30;
setInterval(onEnterFrame, 1000 / FPS);
function onEnterFrame()
{
collisionCheck();
}
function collisionCheck()
{
// Get pixel Data
var imgData = context2D.getImageData(x_position, y_position, 1, 1);
var imgPixelData = imgData.data;
// Look if there is any Collision (3 is the alpha channel (RGBA))
if (imgPixelData[3] >= 1)
{
if (window.console)
{
console.log("You go a Hit!!");
}
}
}
And thats it run this on a server and you got pixel collision.
I searched arround on the internet and dident find any site geving a good instruction about this so I hope this helps somebody out:).