Hello,
I have a little problem with a script-call. It's quite long, so I should probably think about making a plugin out of it, but I'd like to have the base finished/successful testing first.
I have a while-loop to move a ball one pixel at a time and another while-loop in it that checks every pixel around the ball, if there is a collision.
The script short and simplified:
It's working fine the first 1-5 seconds but then I get a crash with this error message:
TypeError - Failed to execute 'getImageData' on 'CanvasRenderingContext2D': Value is not of type 'long'.
Console-Log:
I've commented out a few lines to be sure and it's always crashing after some time at the setting of the variable "alpha".
So the issue is ' const alpha = sprite.bitmap.getAlphaPixel(pt.x + ax, pt.y + ay); ' ?
Does anyone have an idea why and a solution / work-around or idea what I can do?
I have a little problem with a script-call. It's quite long, so I should probably think about making a plugin out of it, but I'd like to have the base finished/successful testing first.
I have a while-loop to move a ball one pixel at a time and another while-loop in it that checks every pixel around the ball, if there is a collision.
The script short and simplified:
JavaScript:
const COLLISION_Picture_ID = 1;
const sprite = SceneManager._scene._spriteset._pictureContainer.children[COLLISION_Picture_ID - 1];
const ax = sprite.anchor.x * sprite.width;
const ay = sprite.anchor.y * sprite.height;
while (!$gameSwitches.value(BallCanMove)) {
//move ball 1 pixel to x & y
while (!$gameSwitches.value(CollisionChecked)) {
//get a pixel and check for collision
if (sprite) {
const pt = sprite.worldTransform.applyInverse(new Point(BallX, BallY));
const alpha = sprite.bitmap.getAlphaPixel(pt.x + ax, pt.y + ay);
if (alpha > 150) {
//do something
$gameSwitches.setValue(CollisionChecked, true);
};
};
//do '$gameSwitches.setValue(CollisionChecked, true);' at some point
};
//do '$gameSwitches.setValue(BallCanMove, true);' at some point
};
It's working fine the first 1-5 seconds but then I get a crash with this error message:
TypeError - Failed to execute 'getImageData' on 'CanvasRenderingContext2D': Value is not of type 'long'.
Console-Log:
I've commented out a few lines to be sure and it's always crashing after some time at the setting of the variable "alpha".
So the issue is ' const alpha = sprite.bitmap.getAlphaPixel(pt.x + ax, pt.y + ay); ' ?
Does anyone have an idea why and a solution / work-around or idea what I can do?