MZ Detect part of a picture within specific coordinates

Hello. I'm making a combat system that involves shielding against projectiles that are fired towards your character in battle. Shields, projectiles, everything is run with pictures.

Long story short, I want to be able to run a conditional branch that checks if even a part of a picture is within a certain set of coordinates. As far as I'm concerned, the only coordinates I can refer to when doing this are the origin position coords, but that only makes up a singular position.

Any ideas?
I found this yesterday when I was looking for pictures related plugin
https://forums.rpgmakerweb.com/index.php?threads/phileass-pictures-collision.166705/

It checks picture's collision when part of image's pixel overlapping each other as it describe.
Haven't tried it so I don't know how it works well, but it should be what you needed.
I found this yesterday when I was looking for pictures related plugin
https://forums.rpgmakerweb.com/index.php?threads/phileass-pictures-collision.166705/

It checks picture's collision when part of image's pixel overlapping each other as it describe.
Haven't tried it so I don't know how it works well, but it should be what you needed.
Ah, it's funny you should mention this, I've tried this out. Unfortunately, the new MZ update broke it, and even before the update, it couldn't detect moving pictures. I guess that's the singular gripe I've got with it 🙁
Something like this?
Usage:
$gameScreen.isPicAt(x, y, pictureId, checkAlpha)

Check if picture #1 is at point (100, 200) - $gameScreen.isPicAt(100, 200, 1)
Check if any picture is at point (100, 200) - $gameScreen.isPicAt(100, 200)
Check with transparency - $gameScreen.isPicAt(100, 200, 1, true/false)
Check array with pictures - $gameScreen.isPicAt(100, 200, [1, 3, 5], true/false)

You can set pictureId to null then it will check any picture too if you need transparency check.
If you're going to use it in a parallel event or in some sort of loop, maybe add like a 10 frame wait just for performance reasons. It probably won't be a problem, but better to be safe.


Spoiler: code
JavaScript:
Sprite_Picture.prototype.isAtPoint = function(x, y, checkAlpha) {
    if (!this.visible || !this.bitmap || !this.bitmap.isReady()) return false;
    if (!this.getBounds().contains(x, y)) return false;
   
    if (checkAlpha) {
        const local = this.worldTransform.applyInverse({x: x, y: y});
        const px = Math.floor(local.x);
        const py = Math.floor(local.y);
        return this.bitmap.getAlphaPixel(px, py) > 0;
    }
    return true;
};

Game_Screen.prototype.isPicAt = function(x, y, picId = null, checkAlpha = false) {
    if (!SceneManager._scene._spriteset) return false;
   
    const picCont = SceneManager._scene._spriteset._pictureContainer;
   
    if (Array.isArray(picId)) {
        for (let i = 0; i < picId.length; i++) {
            const sprite = picCont.children[picId[i] - 1];
            if (sprite && sprite.isAtPoint(x, y, checkAlpha)) {
                return true;
            }
        }
        return false;
    }
   
    if (picId !== null) {
        const sprite = picCont.children[picId - 1];
        if (sprite && sprite.isAtPoint(x, y, checkAlpha)) {
            return true;
        }
        return false;
    }

    for (let i = 0; i < picCont.children.length; i++) {
        const sprite = picCont.children[i];
        if (sprite && sprite.isAtPoint(x, y, checkAlpha)) {
            return true;
        }
    }
    return false;
};
Something like this?
Usage:
$gameScreen.isPicAt(x, y, pictureId, checkAlpha)

Check if picture #1 is at point (100, 200) - $gameScreen.isPicAt(100, 200, 1)
Check if any picture is at point (100, 200) - $gameScreen.isPicAt(100, 200)
Check with transparency - $gameScreen.isPicAt(100, 200, 1, true/false)

You can set pictureId to null then it will check any picture too if you need transparency check.
If you're going to use it in a parallel event or in some sort of loop, maybe add like a 10 frame wait just for performance reasons. It probably won't be a problem, but better to be safe.


Spoiler: code
JavaScript:
Sprite_Picture.prototype.isAtPoint = function(x, y, checkAlpha) {
    if (!this.visible || !this.bitmap || !this.bitmap.isReady()) return false;
    if (!this.getBounds().contains(x, y)) return false;
   
    if (checkAlpha) {
        const local = this.worldTransform.applyInverse({x: x, y: y});
        const px = Math.floor(local.x);
        const py = Math.floor(local.y);
        if (px < 0 || py < 0 || px >= this.bitmap.width || py >= this.bitmap.height) {
            return false;
        }
        return this.bitmap.getAlphaPixel(px, py) > 0;
    }
    return true;
};

Game_Screen.prototype.isPicAt = function(x, y, picId = null, checkAlpha = false) {
    if (!SceneManager._scene || !SceneManager._scene._spriteset) return false;
   
    const picCont = SceneManager._scene._spriteset._pictureContainer;
    if (!picCont) return false;
   
    if (picId !== null) {
        const sprite = picCont.children[picId - 1];
        return sprite ? sprite.isAtPoint(x, y, checkAlpha) : false;
    }
   
    for (let i = 0; i < picCont.children.length; i++) {
        const sprite = picCont.children[i];
        if (sprite && sprite.isAtPoint(x, y, checkAlpha)) {
            return true;
        }
    }
    return false;
};
Hoooooly, you godsend of a person. What do you want me to refer to you as in the credits!?

I've been trying to figure this out for weeks... I can't actually believe it. This works exactly as I envisioned it. Thank you SO much!
Something like this?
Usage:
$gameScreen.isPicAt(x, y, pictureId, checkAlpha)

Check if picture #1 is at point (100, 200) - $gameScreen.isPicAt(100, 200, 1)
Check if any picture is at point (100, 200) - $gameScreen.isPicAt(100, 200)
Check with transparency - $gameScreen.isPicAt(100, 200, 1, true/false)

You can set pictureId to null then it will check any picture too if you need transparency check.
If you're going to use it in a parallel event or in some sort of loop, maybe add like a 10 frame wait just for performance reasons. It probably won't be a problem, but better to be safe.


Spoiler: code
JavaScript:
Sprite_Picture.prototype.isAtPoint = function(x, y, checkAlpha) {
    if (!this.visible || !this.bitmap || !this.bitmap.isReady()) return false;
    if (!this.getBounds().contains(x, y)) return false;
 
    if (checkAlpha) {
        const local = this.worldTransform.applyInverse({x: x, y: y});
        const px = Math.floor(local.x);
        const py = Math.floor(local.y);
        if (px < 0 || py < 0 || px >= this.bitmap.width || py >= this.bitmap.height) {
            return false;
        }
        return this.bitmap.getAlphaPixel(px, py) > 0;
    }
    return true;
};

Game_Screen.prototype.isPicAt = function(x, y, picId = null, checkAlpha = false) {
    if (!SceneManager._scene._spriteset) return false;
 
    const picCont = SceneManager._scene._spriteset._pictureContainer;
 
    if (picId !== null) {
        const sprite = picCont.children[picId - 1];
        return sprite ? sprite.isAtPoint(x, y, checkAlpha) : false;
    }
 
    for (let i = 0; i < picCont.children.length; i++) {
        const sprite = picCont.children[i];
        if (sprite && sprite.isAtPoint(x, y, checkAlpha)) {
            return true;
        }
    }
    return false;
};
I've been playing around with this and it works splendidly. Currently trying to streamline my events and was wondering if it would be possible for one scriptcall to check for a determined set of pictures?

I'm currently running numerous instances of this scriptcall:
$gameScreen.isPicAt(x, y, id)

I tried rephrasing it by using the "||" sign, making it look something like this:
$gameScreen.isPicAt(x, y, (id || id2 || id3 || id4 || id5))

It only checks for the first number named, which I figured it would do, but is it just my phrasing that's wrong, or is this a limitation of the plugin?

I understand that I could simply utilize the fact that "null" makes it check for any picture; however, this would cause the scriptcall to trigger from the shield graphic hovering in the same position.
ofc it won't work like that.
I’ve updated the code. Now you can pass an array of picture IDs, like this:
$gameScreen.isPicAt(100, 200, [1, 3, 5], true)

Or you can save the array to a variable and then use it in a conditional branch:
bf37570c263ce02691d12060028e91e0.png
ofc it won't work like that.
I’ve updated the code. Now you can pass an array of picture IDs, like this:
$gameScreen.isPicAt(100, 200, [1, 3, 5], true)

Or you can save the array to a variable and then use it in a conditional branch:
bf37570c263ce02691d12060028e91e0.png
This looks really promising. Playing around with it, and this is really cool! Although I think my idea for the minigame might be a bit flawed, I'll be sure to repurpose this. Thanks 😀

Original thread: https://forums.rpgmakerweb.com/threads/detect-part-of-a-picture-within-specific-coordinates.182343/