GMS0012

hello all..
i have a little problem..
i usw a 40*40 tile map. visible is a area of 12*15.
everything is working very well.. also the scrolling...
how can i calculate the world coordinate of the map... i do it this way....

else if (_Spieler.Aktiv.ScreenPos.X < 150)

{

// Der Panzer wurde weiter nach unten rechts (Drehwinkel im 1. oder 2. Quadranten

if ((_Drehwinkel >= (MathHelper.Pi)) && (_Drehwinkel < (MathHelper.Pi * 2)))

{

// Map scrollen

_Map.MapScrollen(_Spieler, _Map);

}

else

{

_Spieler.UpdateVorwarts(_Spieler, _SpeedVor);

}

}

this makes the player moving or the map scrolling...

if the map is scrolling i substract the new x value of the world position

worldpos.X -= math.abs( _Spieler.Aktiv.SpeedVor * (float)Math.Sin(((MathHelper.Pi / 2) - _Spieler.Aktiv.Drehwinkel)));

this is working..

but i get a different value if i am at the end of the map. the value depends on the angle of rotation !!

the longer the way to the end of the map is the bigger is the difference...

can anybody give me a hint how to calculate the world position on a scrollable tilemap`

i need the exact position of the map because i want to draw world coordinate objects on it...

please help me..

if you want more code. i can post it here



Re: XNA Game Studio Express world coordinates 2d tile map

Jim Perry

How I've done it in the past is kept the coordinates of the top left tile and use the coordinates of a tile in the viewable area along with this to calculate the real coordinates for the map.

I'm not sure what rotation has to do with it unless you've implemented a camera that allow this.






Re: XNA Game Studio Express world coordinates 2d tile map

GMS0012

the rotation is for the tank... you can rotate it with A and D and move it forwars with W...
i also use the top left tile..
but i do get little differences... i get eg 6.7 if a drive in a 270 degree angle.. but i get 7.2 if i drive in a 181 degree angle..
here is the code how i scroll the top left tile...

public void MapLogikScrollen(Map _Map)

{

//// Logik des Scrollens - logic

if (_Map.TilePixelPosX < 0) // nach links scrollen scroll map to the left

{

_Map.TilePixelPosX = 48;

_Map.MapOffsetX--;

}

if (_Map.TilePixelPosX > 48) // nach rechts scrollen to the right

{

_Map.TilePixelPosX = 0;

_Map.MapOffsetX++;

}

if (_Map.TilePixelPosY < 0) // nach oben scrollen up

{

TilePixelPosY = 48;

_Map.MapOffsetY--;

}

if (TilePixelPosY > 48) // nach unten scrollen down

{

TilePixelPosY = 0;

_Map.MapOffsetY++;

}

//// Am Rand wird nicht weiter gescrollt here is the border of the map reached

if (_Map.MapOffsetX < 0)

{

// Rand erreicht.. Map nicht weiter nach links scrollbar

_Map.MapWeiterScrollbarLinks = false;

_Map.MapOffsetX = 0; _Map.TilePixelPosX = 0;

}

if (_Map.MapOffsetX > MapBreiteMax - _Map.MapSichtbareBreite)

{

_Map.MapOffsetX = MapBreiteMax - _Map.MapSichtbareBreite;

_Map.TilePixelPosX = MapTileWidth;

_Map.MapWeiterScrollbarRechts = false;

}

if (_Map.MapOffsetY < 0)

{

_Map.MapOffsetY = 0; _Map.TilePixelPosY = 0;

}

if (_Map.MapOffsetY > MapHoeheMax - _Map.MapSichtbareHoehe)

{

_Map.MapOffsetY = MapHoeheMax - _Map.MapSichtbareHoehe;

_Map.TilePixelPosY = MapTileHeight;

}

i scroll the new tile by pixel..

here is the code

Vector2 MapVektor;

MapVektor.X = 0;

MapVektor.Y = 0 + StartPosY - TilePixelPosY;

for (int y = 0; y < MapSichtbareHoehe; y++)

{

MapVektor.X = 0 + StartPosX - TilePixelPosX; -

for (int x = 0; x < MapSichtbareBreite; x++)

{

_spritebatch.Draw(MapTiles[GroundMap[y + MapOffsetY, x + MapOffsetX]], MapVektor, Color.White);

MapVektor.X += 48;

}

MapVektor.Y += 48;

}

_spritebatch.End();

}

can anybody please help

is there an alternative for 2d if i dont want to use a tile map





Re: XNA Game Studio Express world coordinates 2d tile map

GMS0012

this is the way i calculate the new worldpos...
(if the map scrolls i add the new x position)

if (_Map.MapWeiterScrollbarRechts) _Map.MapWorldPos.X += Math.Abs((_Spieler.Aktiv.SpeedVor * (float)Math.Cos(((MathHelper.Pi / 2) - _Spieler.Aktiv.Drehwinkel))));

Debug.Print(_Map.MapWorldPos.X.ToString());

from the theory it is working.. but the final result differs..

if i go in a 90 degree angle to the RIGHT border i got (after 44 tiles) 1421.1233

if i go in a 179 degree angle i got 1452.94334

where is my problem





Re: XNA Game Studio Express world coordinates 2d tile map

GMS0012

do you have a little example for this
 
--
How I've done it in the past is kept the coordinates of the top left tile and use the coordinates of a tile in the viewable area along with this to calculate the real coordinates for the map--
 
 
do you need a viewport for this




Re: XNA Game Studio Express world coordinates 2d tile map

Jim Perry

I don't have an example at hand, but I can try to whip one up tonight. I also haven't usually done free roaming movement, just horizontal and vertical. If you're doing 2D and using a SpriteBatch for rendering it handles the viewport.




Re: XNA Game Studio Express world coordinates 2d tile map

GMS0012

thanks for your help
it did it so and it is working
i can rotate my tank and drive in every direction..
this is working

public void MapDraw(SpriteBatch _spritebatch)

{

_spritebatch.Begin();

Vector2 MapVektor;

MapVektor.X = 0;

MapVektor.Y = 0 + StartPosY - TilePixelPosY;

for (int y = 0; y < MapSichtbareHoehe; y++)

{

MapVektor.X = 0 + StartPosX - TilePixelPosX;

for (int x = 0; x < MapSichtbareBreite; x++)

{

// kontrolle ob dieses tile 48*48 beruhrt ------------------->>>>>>>>>>>>> here is the solution

if ((MapVektor.X <= 48) && (MapVektor.X + 48 > 48) && (MapVektor.Y <= 48) && (MapVektor.Y + 48 > 48))

{

MapWorldPosX = (MapOffsetX * 48) + (48 - MapVektor.X ); ---- 48 is tile width and height

MapWorldPosY = (MapOffsetY * 48) + (48 - MapVektor.Y);

Debug.Print("MapWorldPosX:" + MapWorldPosX.ToString());

Debug.Print("MapWorldPosY :" + MapWorldPosY.ToString());

}

_spritebatch.Draw(MapTiles[GroundMap[y + MapOffsetY, x + MapOffsetX]], MapVektor, Color.White);

MapVektor.X += 48;

}

MapVektor.Y += 48;

}

_spritebatch.End();

}

damn, now i am happy.. i thought about this since yesterday evening..now it works...

thanks