RMMZ [Solved] TypeError - Failed to execute 'getImageData' on 'CanvasRenderingContext2D': Value is not of type 'long'.

Status
Not open for further replies.

GamesOfShadows

♥ Gamer/Games ♥
Veteran
Joined
Jan 31, 2017
Messages
79
Reaction score
60
First Language
German
Primarily Uses
RMMZ
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:

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:
1660675647897.png

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?
 

GamesOfShadows

♥ Gamer/Games ♥
Veteran
Joined
Jan 31, 2017
Messages
79
Reaction score
60
First Language
German
Primarily Uses
RMMZ
Okay I fixed it. ^^ I just added some ' Math.round() ' and also instead of storing the alpha value in the variable "alpha", I query the value directly, additionally beforehand whether "sprite" = true.

No idea what it was exactly, but it works:

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 && Math.round(BallX) >= 0 && Math.round(BallX) <= 620 && Math.round(BallY) >= 0 && Math.round(BallY) <= 1008) {
            const pt = sprite.worldTransform.applyInverse(new Point(Math.round(BallX), Math.round(BallY)));
            if (sprite && sprite.bitmap.getAlphaPixel(Math.round(pt.x + ax), Math.round(pt.y + ay) > 150) {
                //do something
                $gameSwitches.setValue(CollisionChecked, true);
            };
        };
        //do '$gameSwitches.setValue(CollisionChecked, true);' at some point
    };
    //do '$gameSwitches.setValue(BallCanMove, true);' at some point
};
 

slimmmeiske2

Little Red Riding Hood
Global Mod
Joined
Sep 6, 2012
Messages
9,944
Reaction score
6,305
First Language
Dutch
Primarily Uses
RMXP

This thread is being closed, due to being solved. If for some reason you would like this thread re-opened, please report this post and leave a message why. Thank you.

 
Status
Not open for further replies.

Latest Threads

Latest Profile Posts

Tried something. Little sneak peak of Unity AD.
M42S7Us.gif

It's the little things. Lengthened the time the bar fades in and out to be a bit more comfortable.
3 days until release!

Forum statistics

Threads
125,736
Messages
1,173,114
Members
164,883
Latest member
rayli1107
Top