#Updating Position relative to map information for connecting maps

1 messages · Page 1 of 1 (latest)

ashen phoenix
#

I have been working on a connected room system that acts similar to how maps in the Pokemon series are displayed. I have the general connectivity of the maps working, however the issue I am having is trying to set entity positions to their position for their map. This is going to be somewhat hard to explain but I will try my best.

An entity has the following:

#macro  TILE_SIZE    16

// Cell Position
cell_x = floor(x) div TILE_SIZE;
cell_y = floor(y) div TILE_SIZE;

// Target Cell Position
target_x = cell_x;
target_y = cell_y;

// True Cell Position
real_x = cell_x;
real_y = cell_y;

// Starting Position
world_x = xstart;
world_y = ystart;

// World Offset
offset_x = 0;
offset_y = 0;

// Step Movement

// Original Position is stored
var _ox = real_x;
var _oy = real_y;

// Before Moving, target_x and target_y are cell to the next cell position so 23,4 if moving right becomes 24,4 while cell_x and cell_y remain 23,4
// Movement is calculated using the following
real_x = lerp(cell_x, target_x, move_timer);
real_y = lerp(cell_y, target_y, move_timer);

// The Offset is used to keep track of the entities movement relative to their starting position
var _offset_x = real_x - _ox;
var _offset_y = real_y - _oy;

world_x += _offset_x * TILE_SIZE;
world_y += _offset_y * TILE_SIZE;

The world_x and world_y variables are treated as if the map they are on is at 0,0

However, in the case where the map they are located on is for example -480, 0 as opposed to 0,0, I need a way to recalculate the positions for cell_x, cell_y, target_x, target_y, real_x, real_y, x and y

I have tried multiple times to create something but anytime, the real_x, real_y value ends up being off and resulting in the entity moving backwards due to the strange logic.

I have this code to get the correct position on the x and y in the new map but I cannot simply apply this to cell_x, cell_y as it causes jumping.

ashen phoenix
#

Maps are stored as a struct that contain a variety of information, but what is important for this are the following


map = {
  x: 0, // Position of the Map in World Space
  y: 0, // Position of the Map in World Space
  width: 480, // Width of the Map in Pixels
  height: 240, // Height of the Map in Pixels
  tWidth: 30, // Width of the Map in Cells
  tHeight: 15, // Height of the Map in Cells
}

map.x and map.y are set based on their connections so if the above map was to the west of a map at 0, 0 its x and y would be set to -480, 0

ashen phoenix
#

nevermind... I found a fix