Check a picture's pixel position (solved)

Status
Not open for further replies.

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
877
First Language
Bangla/Bengali
Primarily Uses
RMMV
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?
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
1,127
Reaction score
359
First Language
Dutch
Primarily Uses
RMMV
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?
 

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
877
First Language
Bangla/Bengali
Primarily Uses
RMMV
The picture is already present. It's position is variable so I want to determine it with the conditional branch
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
1,127
Reaction score
359
First Language
Dutch
Primarily Uses
RMMV
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.
 

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
877
First Language
Bangla/Bengali
Primarily Uses
RMMV
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
 

GGZiron

Veteran
Veteran
Joined
Nov 6, 2016
Messages
75
Reaction score
25
First Language
Bulgarian
Primarily Uses
RMVXA
I tried this:
Code:
$gameScreen.picture(1).x()
and it returned the x coordinate for picture 1 in my test.
 

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
877
First Language
Bangla/Bengali
Primarily Uses
RMMV
I get an error if I use that script call :/
 

ShadowDragon

Veteran
Veteran
Joined
Oct 8, 2018
Messages
1,127
Reaction score
359
First Language
Dutch
Primarily Uses
RMMV
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.
 

GGZiron

Veteran
Veteran
Joined
Nov 6, 2016
Messages
75
Reaction score
25
First Language
Bulgarian
Primarily Uses
RMVXA
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;
};
 
Last edited:

caethyril

^_^
Veteran
Joined
Feb 21, 2018
Messages
1,438
Reaction score
926
First Language
EN
Primarily Uses
RMMV
[Edit: wait, no, I may have misinterpreted. Not sure what's being asked here. :kaoswt2:]

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).
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~
	};
 

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
877
First Language
Bangla/Bengali
Primarily Uses
RMMV
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.
Capture10.PNG

After that I tested it out from a normal event:
Capture1.PNG
This one shows the message. Idk what's wrong in the parallel one, but thank you all for helping me :)
 

GGZiron

Veteran
Veteran
Joined
Nov 6, 2016
Messages
75
Reaction score
25
First Language
Bulgarian
Primarily Uses
RMVXA
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 :D. Someone else may see better where the problem could be.
 
Last edited:

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
877
First Language
Bangla/Bengali
Primarily Uses
RMMV
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.
 

Kes

Global Moderators
Global Mod
Joined
Aug 3, 2012
Messages
21,582
Reaction score
10,918
First Language
English
Primarily Uses
RMVXA
@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.

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.

 

Wavelength

Pre-Merge Boot
Global Mod
Joined
Jul 22, 2014
Messages
4,611
Reaction score
3,863
First Language
English
Primarily Uses
RMVXA
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).
 

Shaz

Veteran
Veteran
Joined
Mar 2, 2012
Messages
38,456
Reaction score
12,015
First Language
English
Primarily Uses
RMMV
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.
 

Hyouryuu-Na

Currently Inactive
Veteran
Joined
Jun 15, 2017
Messages
419
Reaction score
877
First Language
Bangla/Bengali
Primarily Uses
RMMV
@Shaz Thanks a lot for pointing that out. While it didn't cause problems, I learnt something new :D 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
 
Last edited:

GGZiron

Veteran
Veteran
Joined
Nov 6, 2016
Messages
75
Reaction score
25
First Language
Bulgarian
Primarily Uses
RMVXA
Lol, just learned something new too. Always though common events have some sorta self-switch, just with different keys.
 
Status
Not open for further replies.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Latest Threads

Latest Posts

Latest Profile Posts

I'm currently being attacked by the RPG Maker Hydra: fixing one problem only to have two more rise to take its place.
Hey you! Yeah YOU! Whatcha doin' not backing up your projects? You a masochist or sumthin'? GO BACK UP YOUR PROJECTS! Sheeesh... Didn't think I'd hafta spell it out for yas.
now I need to determine, how MV determines if an auto tile is complete or not.
Edit:From what I can tell it uses Autotile kinds to do that.
Edit 2: The editor determines it and packs picture data for the engine....
Finished with the ground work for my class system, using Ellye's Class Change Equipment and Yanfly's Class Change Core plugins to implement an equip based subclass feature!
Hi people! I was wondering... Here in Brazil, we have a whats app group for we talk about rpg maker and our projects. A more informal way for we meet each other. Is there any whats app group out there? :)

Forum statistics

Threads
94,281
Messages
919,643
Members
124,014
Latest member
pradeepkanojia
Top