Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualMoBaT

Posted 09 February 2013 - 01:21 PM

Finally, I tried doing something similar but probably failed at it. I got it working with this code. Thanks for your hard work, I appreciate it. I have one more questions involving the camera. Since the code now works and draws the map around the character, how would I got by implementing the camera so the player stays on the middle of the screen at all times in my 800 x 600 windows. I thought of just going to my player render code and subtracting the offset the character was at it can stay in the middle, but that sounds like a dirty way.

 


                const int minX = 0;
		const int maxX = map->GetHeight();

		const int minY = 0;
		const int maxY = map->GetHeight();

		const int showWidth = 15;
		const int showHeight = 13;

		//Starting point of tiles.
		int startX = (MapX / (TILE_SIZE * ZOOMSCALE) - (showWidth / 2));
		if (startX <= 0) startX = 0;
		int startY = (MapY / (TILE_SIZE * ZOOMSCALE))- (showHeight / 2);
		if (startY <= 0) startY = 0;
	
		//Keep camera in bounds of the map.
		if(startX < minX) startX = minX;
		if((startX + showWidth) > maxX) startX = (maxX - showWidth);

		if(startY < minY) startX = minY;
		if((startY + showWidth) > maxY) startY = (maxY - showWidth);

		//Ending point of tiles.
		int endX = (startX + showWidth);
		int endY = (startY + showHeight); 

 

 

 

I can keep the map on my screen by replacing the offset in my loop from:

    

    offset2.x = x * TileZoom;
    offset2.y =y * TileZoom;
    offset2.w = TileZoom;
    offset2.h = TileZoom;

to

    offset2.x = (x - startX) * TileZoom;
    offset2.y =(y - startY) * TileZoom;
    offset2.w = TileZoom;
    offset2.h = TileZoom;

#4MoBaT

Posted 09 February 2013 - 01:21 PM

Finally, I tried doing something similar but probably failed at it. I got it working with this code. Thanks for your hard work, I appreciate it. I have one more questions involving the camera. Since the code now works and draws the map around the character, how would I got by implementing the camera so the player stays on the middle of the screen at all times in my 800 x 600 windows. I thought of just going to my player render code and subtracting the offset the character was at it can stay in the middle, but that sounds like a dirty way.

 


                const int minX = 0;
		const int maxX = map->GetHeight();

		const int minY = 0;
		const int maxY = map->GetHeight();

		const int showWidth = 15;
		const int showHeight = 13;

		//Starting point of tiles.
		int startX = (MapX / (TILE_SIZE * ZOOMSCALE) - (showWidth / 2));
		if (startX <= 0) startX = 0;
		int startY = (MapY / (TILE_SIZE * ZOOMSCALE))- (showHeight / 2);
		if (startY <= 0) startY = 0;
	
		//Keep camera in bounds of the map.
		if(startX < minX) startX = minX;
		if((startX + showWidth) > maxX) startX = (maxX - showWidth);

		if(startY < minY) startX = minY;
		if((startY + showWidth) > maxY) startY = (maxY - showWidth);

		//Ending point of tiles.
		int endX = (startX + showWidth);
		int endY = (startY + showHeight); 

 

 

 

I can keep the map on my screen by replacing the offset in my loop from:

    

    offset2.x = x * TileZoom;
    offset2.y =y * TileZoom;
    offset2.w = TileZoom;
    offset2.h = TileZoom;

 

to


    offset2.x = (x - startX) * TileZoom;
    offset2.y =(y - startY) * TileZoom;
    offset2.w = TileZoom;
    offset2.h = TileZoom;

#3MoBaT

Posted 09 February 2013 - 01:15 PM

Finally, I tried doing something similar but probably failed at it. I got it working with this code. Thanks for your hard work, I appreciate it. I have one more questions involving the camera. Since the code now works and draws the map around the character, how would I got by implementing the camera so the player stays on the middle of the screen at all times in my 800 x 600 windows. I thought of just going to my player render code and subtracting the offset the character was at it can stay in the middle, but that sounds like a dirty way.

 

                const int minX = 0;
		const int maxX = map->GetHeight();

		const int minY = 0;
		const int maxY = map->GetHeight();

		const int showWidth = 15;
		const int showHeight = 13;

		//Starting point of tiles.
		int startX = (MapX / (TILE_SIZE * ZOOMSCALE) - (showWidth / 2));
		if (startX <= 0) startX = 0;
		int startY = (MapY / (TILE_SIZE * ZOOMSCALE))- (showHeight / 2);
		if (startY <= 0) startY = 0;
	
		//Keep camera in bounds of the map.
		if(startX < minX) startX = minX;
		if((startX + showWidth) > maxX) startX = (maxX - showWidth);

		if(startY < minY) startX = minY;
		if((startY + showWidth) > maxY) startY = (maxY - showWidth);

		//Ending point of tiles.
		int endX = (startX + showWidth);
		int endY = (startY + showHeight);

#2MoBaT

Posted 09 February 2013 - 12:47 PM

Finally, I tried doing something similar but probably failed at it. I got it working with this code. Thanks for your hard work, I appreciate it.

 

                const int minX = 0;
		const int maxX = map->GetHeight();

		const int minY = 0;
		const int maxY = map->GetHeight();

		const int showWidth = 15;
		const int showHeight = 13;

		//Starting point of tiles.
		int startX = (MapX / (TILE_SIZE * ZOOMSCALE) - (showWidth / 2));
		if (startX <= 0) startX = 0;
		int startY = (MapY / (TILE_SIZE * ZOOMSCALE))- (showHeight / 2);
		if (startY <= 0) startY = 0;
	
		//Keep camera in bounds of the map.
		if(startX < minX) startX = minX;
		if((startX + showWidth) > maxX) startX = (maxX - showWidth);

		if(startY < minY) startX = minY;
		if((startY + showWidth) > maxY) startY = (maxY - showWidth);

		//Ending point of tiles.
		int endX = (startX + showWidth);
		int endY = (startY + showHeight);

#1MoBaT

Posted 09 February 2013 - 12:46 PM

Finally, I tried doing something similar but probably failed at it. I got it working with this code.

 

const int minX = 0;
		const int maxX = map->GetHeight();

		const int minY = 0;
		const int maxY = map->GetHeight();

		const int showWidth = 15;
		const int showHeight = 13;

		//Starting point of tiles.
		int startX = (MapX / (TILE_SIZE * ZOOMSCALE) - (showWidth / 2));
		if (startX <= 0) startX = 0;
		int startY = (MapY / (TILE_SIZE * ZOOMSCALE))- (showHeight / 2);
		if (startY <= 0) startY = 0;
	
		//Keep camera in bounds of the map.
		if(startX < minX) startX = minX;
		if((startX + showWidth) > maxX) startX = (maxX - showWidth);

		if(startY < minY) startX = minY;
		if((startY + showWidth) > maxY) startY = (maxY - showWidth);

		//Ending point of tiles.
		int endX = (startX + showWidth);
		int endY = (startY + showHeight);

PARTNERS