当前位置: 首页>>代码示例>>C++>>正文


C++ TileMap::GetTileNumber方法代码示例

本文整理汇总了C++中TileMap::GetTileNumber方法的典型用法代码示例。如果您正苦于以下问题:C++ TileMap::GetTileNumber方法的具体用法?C++ TileMap::GetTileNumber怎么用?C++ TileMap::GetTileNumber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TileMap的用法示例。


在下文中一共展示了TileMap::GetTileNumber方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: RenderLine

void Window::RenderLine(Renderer &renderer, const TileSet &tileset, TileSet::Number tileset_number,
	const TileMap &tilemap, const Palette &window_palette, uint8_t current_line) const
{
	// When a new frame begins, reset to beginning of Window
	if (0 == current_line)
	{
		line_to_be_rendered_ = 0;
	}

	if (window_on_)
	{
		// There is nothing to draw for lines before the vertical position of the window
		if (current_line < window_position_y_)
		{
			return;
		}

		// The line (of the tiles) to be drawn, depending on the vertical scroll of the background and the current line being drawn (last 3 bits, 0-7)
		const uint8_t line_in_tile{ static_cast<uint8_t>(line_to_be_rendered_ & 0x07) };

		// There is nothing to draw for pixels before the horizontal position of the window
		size_t pixels_drawn = window_position_x_;
		while (pixels_drawn < screen_width_)
		{
			const auto tile_number = tilemap.GetTileNumber(line_to_be_rendered_, pixels_drawn);

			const auto& tile = tileset.GetTile(tileset_number, tile_number);

			for (auto x_in_tile = 0; (x_in_tile < tile.GetWidth()) && (pixels_drawn < screen_width_); x_in_tile++)
			{
				try
				{
					const auto color = window_palette.GetColor(tile.ReadPixel(x_in_tile, line_in_tile));
					renderer.RenderPixel(pixels_drawn, current_line, color);
				}
				catch (std::out_of_range &)
				{
					throw std::runtime_error("Trying to access invalid palette");
				}
				pixels_drawn += 1;
			}
		}

		// Only increase the line to be rendered if the window is enabled
		line_to_be_rendered_ += 1;
	}
}
开发者ID:idearcos,项目名称:GameboyEmuCPP,代码行数:47,代码来源:GPU_Window.cpp

示例2: RenderLine

void Background::RenderLine(Renderer &renderer, const TileSet &tileset, TileSet::Number tileset_number,
	const TileMap &tilemap, const Palette &bg_palette, uint8_t current_line) const
{
	if (background_on_)
	{
		// The pixel offset inside the first tile to be drawn, depending on the horizontal scroll of the background (last 3 bits, 0-7)
		size_t x_offset_in_tile = bg_scroll_x_ & 0x07;

		// The line (of the tiles) to be drawn, depending on the vertical scroll of the background and the current line being drawn (last 3 bits, 0-7)
		const uint8_t line_in_tile{ static_cast<uint8_t>((current_line + bg_scroll_y_) & 0x07) };

		size_t pixels_rendered = 0;
		while (pixels_rendered < screen_width_)
		{
			const auto tile_number = tilemap.GetTileNumber(current_line + bg_scroll_y_, pixels_rendered + bg_scroll_x_);

			const auto& tile = tileset.GetTile(tileset_number, tile_number);

			for (auto x_in_tile = x_offset_in_tile; (x_in_tile < tile.GetWidth()) && (pixels_rendered < screen_width_); x_in_tile++)
			{
				try
				{
					const auto color = bg_palette.GetColor(tile.ReadPixel(x_in_tile, line_in_tile));
					renderer.RenderPixel(pixels_rendered, current_line, color);
				}
				catch (std::out_of_range &)
				{
					throw std::runtime_error("Trying to access invalid palette");
				}
				pixels_rendered += 1;
			}

			// For all tiles except the first one, the whole tile is to be rendered, so there is no offset whatsoever
			x_offset_in_tile = 0;
		}
	}
}
开发者ID:idearcos,项目名称:GameboyEmuCPP,代码行数:37,代码来源:GPU_Background.cpp


注:本文中的TileMap::GetTileNumber方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。