将图像加载到数组中

发布于 2024-07-20 04:32:23 字数 327 浏览 6 评论 0原文

我如何将某些图像加载到数组集中,就像

Map = ( ( 1, 1, 1 ), ( 2, 2, 2 ), ( 3, 3, 3 ) ) 

我可以将

图像放入变量中一样

one = oslLoadImageFile("one.png", OSL_IN_RAM, OSL_PF_5551);

那么我是否能够做类似 Map = ( ( one, one, one ) ) 之类的事情

,如果每个图像都是 32x32 ,它是否能够并排而不是前面的像素

抱歉,我仍在学习并尝试复习一些我心中的基础知识

How would I load certain images into an array set like

Map = ( ( 1, 1, 1 ), ( 2, 2, 2 ), ( 3, 3, 3 ) ) 

I can put

images into variables like so

one = oslLoadImageFile("one.png", OSL_IN_RAM, OSL_PF_5551);

so whould I be able to do something like Map = ( ( one, one, one ) )

and if each image was 32x32 would it be able to be side by side rather then a pixal ahead

Sorry im still learning and trying to go over some basics in my hea

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

安稳善良 2024-07-27 04:32:23

似乎您使用 C++ OldSchool Library for PSP。 根据其文档,您应该创建一个图像文件,其中应包含一组图像,然后您就可以用它创建地图。

//definition of the pointers towards our image
OSL_IMAGE *Zora_tileset;

//definition of the pointers towards our map
OSL_MAP *zora;


 Zora_tileset = oslLoadImageFile("tileset.png", OSL_IN_RAM, OSL_PF_5551);

 //check
 if (!Zora_tileset)
  oslDebug("Check if all the files are copied in the game folder.");

 //configuration of the map
 zora = oslCreateMap(
  Zora_tileset,     //Tileset
  Zora_map,     //Map
  16,16,      //Size of tiles
  64,65,      //Size of Map
  OSL_MF_U16);     //Format of Map

看起来这个库的用途非常有限,最好在其 论坛

Seems to be that you use C++ OldSchool Library for PSP. According to its documentation you should create one image file which should contain set of images and then you'll be able to create map with it.

//definition of the pointers towards our image
OSL_IMAGE *Zora_tileset;

//definition of the pointers towards our map
OSL_MAP *zora;


 Zora_tileset = oslLoadImageFile("tileset.png", OSL_IN_RAM, OSL_PF_5551);

 //check
 if (!Zora_tileset)
  oslDebug("Check if all the files are copied in the game folder.");

 //configuration of the map
 zora = oslCreateMap(
  Zora_tileset,     //Tileset
  Zora_map,     //Map
  16,16,      //Size of tiles
  64,65,      //Size of Map
  OSL_MF_U16);     //Format of Map

It looks like this library has a very limited usage and it will be a good idea to ask your question on its forum.

动次打次papapa 2024-07-27 04:32:23

听起来您想为 2D 游戏构建一个图块地图。 在这种情况下,您可能希望有一个包含所有图块的精灵。 然后,地图将包含特定图块的索引。

当需要绘制图块时,您可以根据图块索引复制精灵的部分内容。

如果您有一个精灵图像,其图块索引如下:

+---+---+---+---+
| 0 | 1 | 2 | 3 |
+---+---+---+---+
| 4 | 5 | 6 | 7 |
+---+---+---+---+
| 8 | 9 |
+---+---+

您可以使用类似这样的方法来计算要为每个图块索引复制的矩形:

const int TILE_SIZE = 32;
const int TILES_PER_ROW = 10;

int xCoordinate = TILE_SIZE * (tileIndex % TILES_PER_ROW);
int yCoordinate = TILE_SIZE * (tileIndex / 10);

Draw(tileSet, xCoordinate, yCoordinate, TILE_SIZE, TILE_SIZE);

It sounds like you're wanting to build a tile map for a 2D game. In that case, you would want to have a single sprite containing all of your tiles. The map would then contain indices for specific tiles.

When it comes time to drawing the tiles, you'd copy portions of the sprite based on the tile index.

If you had a sprite image with tiles indexed as follows:

+---+---+---+---+
| 0 | 1 | 2 | 3 |
+---+---+---+---+
| 4 | 5 | 6 | 7 |
+---+---+---+---+
| 8 | 9 |
+---+---+

You could use someting like this to calculate the rectagle to copy for each tile index:

const int TILE_SIZE = 32;
const int TILES_PER_ROW = 10;

int xCoordinate = TILE_SIZE * (tileIndex % TILES_PER_ROW);
int yCoordinate = TILE_SIZE * (tileIndex / 10);

Draw(tileSet, xCoordinate, yCoordinate, TILE_SIZE, TILE_SIZE);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文