将图像加载到数组中

时间:2009-05-16 04:08:53

标签: c++ playstation-portable

如何将某些图像加载到像

这样的数组中
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,它可以并排而不是前面的像素

对不起我还在学习并尝试在我的hea中查看一些基础知识

2 个答案:

答案 0 :(得分:1)

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

//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

看起来这个图书馆的使用非常有限,最好在forum上提出你的问题。

答案 1 :(得分:0)

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

当绘制图块时,你会根据图块索引复制部分精灵。

如果您的精灵图像的图块索引如下:

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

您可以使用这样的方法计算每个图块索引要复制的rectagle:

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);
相关问题