Event/Script solution for picture movement using Designate by Variable

So I have been experimenting with on map, turn-based movement for combat. I started by using pictures to represent the actors and I establish their pixel X and pixel Y coordinates. Since the tiles are 48x48 pixels, I then use variables called DestinationX and DestinationY to determine what the destination coordinates will be by adding or subtracting 48 and check those coordinates to make sure something isn't there already and the movement can happen.

This is working fine and I like the smooth movement of the actor pictures. However, I have run into a bit of an issue.

Early on I realized that my map is bigger than the playtest viewable area. This actually effects the pixel X and pixel Y values since I am using the Center option for placement of the pictures and as I move the pictures, I add or subtract 48 from the coordinates. But the starting coordinates of the pictures are not the same as the overall pixels of the map. The playtest viewable area width and height in pixels are not necessarily the same at the map width and height in pixels.

Meaning, when I first calculate the starting coordinates of any actor/picture on the screen, the pixel coordinates are based on the playtest viewable area and not the overall coordinates of the map. For example, for an X coordinate of 48 x 5 (plus 24 to center the picture in the middle of a tile) that would be the 6th tile in the viewable area in the playtest. However, that doesn't mean that is the 6th tile of the map because the map might extend beyond the viewable playtest area.

My current testing map is 17x17. So the entire width of the map is viewable in playtest, but the entire height isn't.

The problem I discovered is when I am trying to determine the Region ID of the Destination coordinates. When I am checking those coordinates moving left or right, I get the correct Region ID of the Map as if I was using the 0, 0 to 16, 16 coordinates and I can check for obstacles.

But, when I do the same thing moving up or down, the Region ID of the Map for the destination coordinates (which I divide the pixel values by 48) comes out to different actual coordinates.

So, moving left or right, my destination pixel coordinates divided by 48 show 5, 5 and the Region ID I want is the one for tile 5, 5. Cool. My map width and playtest view screen width are the same.

But if I move up or down, my destination pixel coordinates divided by 48 might show 3, 7 while the actual Region ID of the tile the picture would be moving to (center of tile) might be 3, 9. I believe it is off by the same number of tiles that DON'T show in the playtest viewable area.

I have tried all sorts of math to try to compensate/correct for this, but I am stumped.

Now, I can fix this by making sure the combat map is the same size as the viewable playtest area. But that also means my combat area is unnecessarily limited.

I also was just playing around with using Events and Set Event Location instead of pictures because that way I don't have to calculate the pixels for coordinates and movement. But the downside to that is I can only choose from assets that can be selected in the Event for displaying the actors. With the pictures, the actors/pictures can actually be scaled so they don't necessarily have to be squashed into the confines of the tile size. Also, the appearance of the event movement using Set Event Location is jerky. It doesn't look like the actor is moving, rather it just jumps from tile to tile.

I'm not sure if this makes sense. I will attach a few screenshots to show the pixel coordinate designation and some other stuff. These aren't the entire events because I have tested a bunch of stuff that seems to be working fine.

Maybe I am doing something wrong with the whole pixel stuff. I thought I was on the right track when I could move the picture exactly one tile at a time using the pixel coordinates and plus or minus 48, as appropriate.

But the whole pixel size of the viewable playtest area compared to the pixel size of the entire map is throwing me off.

Again, it seems like it works fine if the actual map fits perfectly in the playtest viewable area. But I would like to be able to let the player move the picture/actors anywhere on a larger map.

Maybe I will also get stuck with scrolling the map too. I haven't tested that yet because I sort of got stuck with the whole use Region ID to check to see if there is an obstacle that you can't move to.

Maybe I am missing another alternative because I am stuck on this path and can't seen any other options. Or maybe it is based on my lack of knowledge and experience.

If there is an entirely different way to approach this, without plugins, I would also love to hear about that too since I am trying to learn.

And again, the map and squashed Reid isn't pretty. I am just using this for quick proof of concept testing. LOL!

And again, the screenshots aren't the full events. They are just to show the relevant concepts of what I am trying to do. And you might be able to tell I also have tested a wide variety of things.

I started off (not shown) by displaying a chess board and moving the Evil Teddy from square to square. I have tried menu driven movement choices, key press driven movement choices, and most recently (not shown) click on 8 directional arrows to move.

The biggest problem right now is trying to determine if the actor/picture can move to a tile with an obstacle where it shouldn't be able to move. Maybe there is a better/easier way to do that without Region ID.

If the whole using pixels for coordinates is just too problematic for maps that are bigger than the playable screen area, then that would be good to know so I can devote my time to another path.

I hope this Frankenstein Monster makes sense and thank you so much for taking the time to look at this and trying to decipher that ramblings of an old, RPG Maker newbie!

Spoiler: Screenshots
Movement by Pixel Coordinates 1.pngMovement by Pixel Coordinates 2.pngMovement by Pixel Coordinates 3.pngMovement by Pixel Coordinates 4.pngMovement by Pixel Coordinates 5.pngMovement by Pixel Coordinates Map.pngMovement by Pixel Coordinates Playtest Area.pngMovement by Pixel Coordinates Region ID.pngMovement by Pixel Coordinates Squashed Reid.png

EDIT: UPDATING WITH VIDEO OF PROBLEM:

Can I see your common event for moving left? I want to compare it to the move up event.

I think you are correct in that the taller map size is throwing the calculations off. I believe that for the purpose of rendering pictures, it would treat coordinates 0 0 as the 0 0 of the screen space, not the 0 0 of the total map area in pixels. That would explain why your vertical check is off but the horizontal check is fine.

Try moving the player start position to the first walkable row of the map and testing then. This will force the game to keep the top-most row fully on the screen. If I'm right about the screenspace vs total map area thing, with the topmost row fully on the screen, your up movement check should work. If it's still acting wonky, it means it's something else
@GBJackson Hey, thanks for the reply. I am attaching the screenshots of the full Common Events for Arrow Up and Arrow Left. Part of the event is just showing the X, Y coordinates for testing to see what it was doing.

I am pretty sure this has to do with the starting pixel X and Y values that I use to place the pictures on the screen in the spot I want. And how that is different from the total pixels on the map.

Not sure if the video helps clarify too.

Spoiler: Arrow Up & Arrow Left
Move Left 1.pngMove Left 2.pngMove Up 1.pngMove Up 2.png

Thanks for looking!
Yeah, I'm definitely leaning towards it being a screen space vs total map area in pixels issue. Try that test I edited my post above to include to see if it seems to work right. If it does, then it confirms this theory. If it doesn't, then it's something else.
Thanks for suggesting that simple way to test the problem!

I moved the Player starting position so it was closer to the top of the map and so the top of the map was visible on screen. And guess what? The Arrow Up event works fine and gets the right Region ID!

So I think that confirms what the problem is.

Now, the real question is can that problem be mitigated some way with math or something?

Or is the only solution to use a different method or make sure the map size and play screen size match?

Thanks!
I just skimmed your post lol, but yeah, doesn't the picture appear at screen coordinates instead of map coordinates and it also stays fixed at those screen coordinates when the player moves around the map. So just calculate the coordinates properly based on what portion of the map you see depending on your player starting position and then maybe every time you press those arrows have the map also scroll in that direction...I think? Ok thanks bye!
@rpgLord69 It is certainly worth a try. I was wondering if scrolling the map with each step would help, but I hadn't tried that yet because I didn't quite understand the logic of how the screen X & Y coordinates would update properly from just moving the map.

I will see if I can test that next and see if it helps.

Thanks!
It doesn't work as you expect because you are using the screen coordinates from the image to make tests with map coordinates.
To get the position of the image on the map you must sum the position of the image by the map scroll, like this:
JavaScript:
//pseudocode
let picMapX = pic.x + $gameMap.displayX() * $gameMap.tileWidth();
let picMapY = pic.y + $gameMap.displayY() * $gameMap.tileHeight();
That way you get approximately the position of the image on the map in pixels.
@JorgeMaker So I am still learning JS so I want to check before I go messing anything up.

Using what you provided above, I would use that script in 2 variables. One for X and one for Y to get the approximate correct values.

And for img.x in the script, the "img" is replaced by the name of my picture and you do use quotes for the picture name? So it would be "SF_Evilteddybear".

So the script box in the Variable would be "SF_Evilteddybear".x + THE REST OF THE SCRIPT UNCHANGED.

Thanks if you have time to confirm or for correcting me if I am interpreting this incorrectly!

EDIT: I see you edited your post above, but I am still not clear about how to identify which picture I am referencing since there will be multiple on the screen.
JavaScript:
$gameScreen.picture(picID).x() + $gameMap.displayX() * $gameMap.tileWidth();
$gameScreen.picture(picID).y() + $gameMap.displayY() * $gameMap.tileHeight();
You will put each line of this script into two different variables.
replace "picID" with the Id of your picture.

Example:

1679066639491.png
@JorgeMaker So there is progress! Thanks for continuing to help!

I got to your solution above before I saw your edit. However, here is what is happening.

When I start the playtest, the Map Y and the Screen Y are off by 2. When I move up the first time, I added a scroll map up by 1 with the movement. Then, the next time I say move up, the Map Y and Screen Y are only off by 1. And it stays like that.

Also, when the Map Scrolls, it shifts both the Evil Teddy and Squashed Reid up on the map, probably from recalculating the pixels.

I am attaching more screenshots. I don't quite understand why the tile Y coordinates are off by 1 when the Y pixels values are the same in the screenshots.

I don't know if it makes a difference, but I have the pictures set to Center for Origin instead of Upper Left.

Spoiler: Screenshots
Move Up First.pngMove Up Second.pngMove Up The Edge.pngMove Up Event.pngMove Up Event Map Scroll.png
Well, I could make a long answer explaining how to make all this work perfectly, but that would involve rewriting all the logic of your system and replicating it by the same logic that is used in events, player and followers.
But first of all, why exactly would it be necessary to make a system that does basically the same thing that events do instead of just using events? From what I see in your examples, pictures could easily be replaced by them. :awink:
@JorgeMaker I am actually exploring the Set Movement Route option right now and testing it. Originally I thought I would have to use Set Event Location, but that obviously isn't true.

Originally, I didn't want to be limited to just what was available in the Event Image folder. With the pictures, I could take any picture from any source and use it as long as it scales. And in the beginning, I didn't know how to make either pictures or the events move until I did some experiments.

With the Events, I need to figure out how to take any of those pictures and turn them into the sprite sheets, right?

But I am liking the Event movement option and I can always use the picture movement option if I just make the combat area map the same size as the play screen.

For me, this is a lot of learning by trial and error!

Please don't waste your time trying to come up with a complex solution. Especially when I'm not even sure this is what I will end up using for anything.

Again, I am just trying to learn by experimenting so I can figure out what will work best for what I want to ultimately do.

Thank you so much for all of your help!

EDIT: In case this helps anyone who finds this.

A YouTube user called RPG Martinius offered a possible solution in the comments on the YouTube video I posted about this. Here is the comment:

"The region detect 3,4 instead of 3,5. I think it is because the sprite detection point is on the top left and there is no pixel border whatsoever. Instead only divide by 48 when get the RegionIdY, try to add + 1 after divide by 48, so the point of detection is in the box not in the border. I think it will corect 3,4 to 3,5 region detection."

So I subtracted 1 from the Y coordinate calculation for checking the Region ID and it works!

Before the first move Up, the Y coordinates are off by 1 now. As soon as the first move up happens and the map scrolls by 1, the pictures shift up a bit (still an issue) and then the Y coordinates match perfectly and the Region ID check for obstacles works fine.

So the only thing left if I want to continue exploring this type of movement is to figure out how to make it so scrolling the map doesn't cause that visible shift of the pictures.

Very cool!

EDIT AGAIN: Ok, so I ended up giving up. The solution wasn't that simple. It worked when moving in the Up direction, but there were problems with moving down and diagonal. Plus, when the map scrolled, it made things worse. So I ended up abandoning this until I can either learn more or someone else sees this and says hey, I know how to do that...it's easy. 🙂

Original thread: https://forums.rpgmakerweb.com/threads/event-script-solution-for-picture-movement-using-designate-by-variable.155886/