How to get exact event sprite pixel location (not just tile location)

inqs

Villager
Member
Joined
Feb 28, 2019
Messages
15
Reaction score
1
First Language
English
Primarily Uses
RMMV
How do I get the exact pixel location of a given event in RPG Maker MV?

I know I can look at the x, y coordinates of an event but those just five the tile locations. When an event is moving from one tile to another, those are not accurate. So if I want to draw something on the screen pointing to the center of the sprite for an event, I need to know the exact pixel coordinates of the sprite as opposed to the tile.

Bonus question: what is the difference between things like x, realX, scrolledX that I see as properties of things in RMMV?

Thanks.
 

Andar

Veteran
Veteran
Joined
Mar 5, 2013
Messages
36,339
Reaction score
9,722
First Language
German
Primarily Uses
RMMV
there is no direct way unless you count the pixels of a sprite from its frame, or unless you change the engine to use pixel movement.

about the different coordinates: a map can be large than the screen, and if it is the map scrolls in the background.
and additionally you can move the camera off-center

that is where you need the different coordinates as in x on the screen, x on the map, x on a scrolled map and so on.
 

MushroomCake28

KAMO Studio
Global Mod
Joined
Nov 18, 2015
Messages
4,015
Reaction score
4,928
First Language
EN, FR
Primarily Uses
RMMZ
The solution is just to set the sprite's coordinate to the character's coordinate in the update method. That way, it will be on the player all along.

Also:
  • x: the x position.
  • realX: the x position, but without counting the between tiles value (I might be switching both x and realX, don't remember exactly).
  • scrolledX: I think it's the first visible tile on the x axis on screen.
 

caethyril

^_^
Global Mod
Joined
Feb 21, 2018
Messages
3,690
Reaction score
2,767
First Language
EN
Primarily Uses
RMMZ
As MushroomCake28 suggests you can access relevant properties via scripting, e.g. Control Variables > Set > Script:
Code:
($gameMap.event(5).scrolledX() + 0.5) * 48
I.e. get event 5's real x-value (i.e. fractional tile x-coordinate) adjusted relative to the current screen position, add 0.5 (offset from top-left to centre), then multiply by 48 px/tile.

If you want the coordinate without adjusting for screen position, refer directly to _realX, e.g.
Code:
($gameMap.event(5)._realX + 0.5) * 48

To get the y-coordinate, just swap scrolledX() or _realX for scrolledY() or _realY. ^_^
 

inqs

Villager
Member
Joined
Feb 28, 2019
Messages
15
Reaction score
1
First Language
English
Primarily Uses
RMMV
there is no direct way unless you count the pixels of a sprite from its frame,

Thanks for the answer. Can you clarify what you mean? How do I count pixels of a sprite from its frame? Or at a more basic level, if an event has an X and Y location of (5, 6) but is in the process of moving down to (5, 7) how do I even know that?

Thanks.
 

dragonhyle

*Ksn n DkWn disn*
Member
Joined
Mar 25, 2019
Messages
3
Reaction score
1
First Language
Spanish
Primarily Uses
RMMV
Heey Hello!
Sorry, I never came to this post to solve problems actually... I'd like to ask a question in relation to this post. This is actually my first activity as a member of the forum so thank you very much for all this amazing site. Years ago I was a lot into rpgmaker 2003 and XP, but I quit for a loooong time though I always wanted to finish what I started. The only thing that I'd like to change from rpgmaker2003 is actually the movement of the character, of all the characters (sorry if my terminology isn't correct 100%, again, I've been out of this business for a looooong time), so they can move pixel by pixel rather than tile by tile. That was something that I really wanted to change but my life brought me through diferent paths and I left this world lost in time, forgotten. I believe it is not hard to do at all using code and I believe that mv is the perfect one to develop anything you wish in this kind of levels that I am talking about (or trying to explain, hope you understand).
Thank you very much!
 

Kes

Veteran
Veteran
Joined
Aug 3, 2012
Messages
22,725
Reaction score
12,281
First Language
English
Primarily Uses
RMMZ
@dragonhyle Please do not use someone else's thread to ask your own query. That is hi-jacking.

I suggest you create a new thread , in JS Plugin Requests, and ask for links to pixel movement plugins.
 

dragonhyle

*Ksn n DkWn disn*
Member
Joined
Mar 25, 2019
Messages
3
Reaction score
1
First Language
Spanish
Primarily Uses
RMMV
Okay, thanks. I'll do!
 

Latest Threads

Latest Profile Posts

John 3:16 “For God so loved the world, that he gave his only Son, that whoever believes in him should not perish but have eternal life.
Happy treason day, Colonial friends <3

I am officially amused. One of the NPCs in my project is basically meant as the guy you check in with to point you where you should go next, including if you’ve been away for a bit and have forgotten.

I can conclusively say he does his job nicely. I was out of town over the weekend. I had forgotten what I was working on, so I checked what I had last done with him for a reminder. ^.^
While talking about anime with a friend got the idea of doing this. :kaopride:
4m6nhlF.jpg

Character: Mirajane Strauss from Fairy Tail.

Forum statistics

Threads
123,341
Messages
1,155,890
Members
161,769
Latest member
CrewMimo
Top