Check a picture's pixel position (solved)

Hello. I asked about this on this forum before but didn't get the answer I was looking for. But I recieved some nice suggestions which I planned on carrying out. However I was too busy planning the story to test those out at that time. Now I see I really need to know how to check a picture's pixel position. I searched the whole internet! Got no solution for MV.

However, I got a solution for VX Ace which is this:
Code:
screen.pictures[index].x

Does anyone know what the equivalent is for MV?
if this is for the show picture, it can be really easy on 2 ways. But is this for using a script call or for destiantion to show?
The picture is already present. It's position is variable so I want to determine it with the conditional branch
the start point is mostly on the upper left corner.

so the X start posion in that point.

There is a way if using a mouse to locate the position around
if: Pict X >= 120
if: Pic X <=300
if: Pic Y >=300
if Pic Y<= 500
do correct stuff
Else
what happend if not met
end
end
end
end

around this (if the image is 180x200.
but I dont know what you want to achieve though.

I hope this makes sense, but for mouse or player is it do able, for alreasdy present, Im not sure otherwise.
I tried using the mouse coordinates. Doesn't work as expected as the mouse keeps moving all the time. I'll need the picture's x and y for this. Otherwise I'll need to scrap the system. I was making a slider and I got the image to slide along with the mouse but I need to get the position somehow like
If picture's X == 474,
Var a = 5
Or something like this
I tried this:
Code:
$gameScreen.picture(1).x()
and it returned the x coordinate for picture 1 in my test.
@GGZiron Thanks! I'll try this
I get an error if I use that script call :/
try to remove the () on the end of it and use ; to cloase, while x() is not a funtion and returned to an error.
I can figure it out later what the scriptcall might be.
Then why it would work to me? And yes, used x exactly as function.
I do not use it within conditional branch, but in alert function, as all I want to see is the x coordinate displayed.
Sure you didn't anything wrong in your usage of the call?

Edit:

◆Show Picture:#1, te, Upper Left (45,0), (79%,79%), 255, Normal
◆Script:alert($gameScreen.picture(1).x())
◆Erase Event
I do that for random picture, and g et 45 displayed on screen.

Did lil digging, x is indeed function:

Code:
Game_Picture.prototype.x = function() {
    return this._x;
};
I get an error if I use that script call :/
what is the error? Don't make us guess. Show a screenshot of your command.
[Edit: wait, no, I may have misinterpreted. Not sure what's being asked here. 😅]

You may experience complications if your picture is not at 100% scale and 0 rotation. In that case you'll need to "undo" those transforms when going from screen coordinate to picture coordinate. In case you're interested, I did something similar for one of my plugins to check the alpha/transparency of the clicked pixel; here's a link: view CaeX_YEPClickThruPic (Google Drive).
Spoiler: Relevant excerpt
Code:
	_.inputToPicCoord = function(inputX, inputY, sprite) {
		let sx = sprite.scale.x, sy = sprite.scale.y;
		let ax = sprite.anchor.x * sprite.width * sx;
		let ay = sprite.anchor.y * sprite.height * sy;
		let x = inputX - sprite.x + ax;					// Offset (pic-rel)
		let y = inputY - sprite.y + ay;
		let ro = sprite.rotation;
		let rx = (x - ax) * Math.cos(ro) + (y - ay) * Math.sin(ro);	// Rotate about anchor (LH)
		let ry = (y - ay) * Math.cos(ro) - (x - ax) * Math.sin(ro);
		x = rx + ax, y = ry + ay;
		x = Math.round(x / sx);						// Scale (retrospective)
		y = Math.round(y / sy);
		return { x: x, y: y };						// Output~
	};
First of all, @GGZiron I'm sorry for not being careful 🙁 The first time I actually wrote Picture instead of picture. Which is why I got the error. After that, I tested the right function in a parallel event. Since it's parallel, it should show the message as soon as the picture's x becomes 651, right? But nothing happens.
Spoiler: screenshot
Capture10.PNG

After that I tested it out from a normal event:
Spoiler: screenshot
Capture1.PNG
This one shows the message. Idk what's wrong in the parallel one, but thank you all for helping me 🙂
You are welcome (although I am sure it was matter on time someone else to come with that ). I just wanted to give you
the MV alternative of the Ace script call.

So from this event alone, can't understand how exacly you move that picture. As I see, the third value in show method is the pictures' x, which u set to variable 21. You change that variable in other event? Also, how many frames you move that picture at once? If by more than 1, then you might just skip that 651. For example, if you move it by 2 pixels, it could be 650, then go 652, and what you check is, if x is exactly 651. If picture x is increasing (what I guess it does), then I suggest you check instead with that :
Code:
>=
.

And I am not too confident with events, not done em from long 😀. Someone else may see better where the problem could be.
I managed to fix it. Though it's a parallel event, it's bound to yanflys picture common events which is why it only works when pressed and held. I had to make a different parallel event for this.

@GGZiron the variable 21 stores the mouse's x coordinate. So everytime I move my mouse, the picture moves too. Combine this concept with Yanfly's picture common events and whenever you press and hold onto the picture and drag, the picture moves too. When the mouse click is released, the picture stops moving and has a new position.
@Hyouryuu-Na When your query is fully resolved, please Report your post and ask for the thread to be closed. Mods might not see a post or change of title, but they will see a Report. As I am here now, I'll do it without you having to Report it.

Thread closed IgnoreMe
Temporarily re-opening this thread at the request of a member who wants to add to the discussion. Will close again after 24 hours of inactivity (or immediately at the request of the thread starter).
Thanks @Wavelength.

Hey there @Hyouryuu-Na I wanted to show you something about your first screenshot with the parallel event.

You see how your first condition says "if self switch A is on, then move the picture, otherwise show the picture"? Common events don't have self switches, so this will always evaluate to false which means it's just going to do the show picture command all the time. You won't see any difference, because it's just re-showing the picture, but at a different position. But in the background, it'll be doing a lot more processing as it'll go through the whole "load this picture, do I have this picture loaded, then get it from the cache, now set up all the picture settings" on every frame, which doesn't happen with a move picture command.

When a common event is called from a map event with the Common Event command, it acts as if the commands in the common event were actually executed from the map event. So in that case, using self switches is valid, because it's looking at the self switches of the map event. But when a common event is run as a parallel process or autorun, and is not being called by a map event, there is no self switch.

Just wanted to point this out - although it's not going to make much of a difference with this particular feature, it could leave you scratching your head if you make the same mistake with other things.
@Shaz Thanks a lot for pointing that out. While it didn't cause problems, I learnt something new 😀 Actually I didn't even think much about it. Archeia made a utility tool to check picture's coordinates (by checking mouse position) a while back. I just copy pasted the commands without thinking about what'll happen if I put it in a common event going through parallel process... Thanks again
Lol, just learned something new too. Always though common events have some sorta self-switch, just with different keys.

Original thread: https://forums.rpgmakerweb.com/threads/check-a-pictures-pixel-position-solved.112371/