小编Ben*_*n91的帖子

在 C++ 中存储一组坐标集(成对向量的向量?)

首先,我对 C++ 很陌生,所以我可能不得不深入研究伪代码和/或 Python 来解释我想要做什么......

我正在尝试为多个精灵存储动画的每一帧的 X 和 Y 坐标对。我设想这类似于以下内容 - 假设 PLAIN == 1 (使用枚举):

animationFrames[PLAIN][0] = { 20, 50 }
animationFrames[PLAIN][1] = { 25, 55 }
Run Code Online (Sandbox Code Playgroud)

等等。我基本上希望能够使用相关精灵的 ID 查询 animationFrames 并接收一组 X、Y 坐标以进行迭代。我觉得这很棘手。这是我的尝试,但不起作用...

std::vector< std::vector< std::pair<int, int> > > frames = {
    {
        { 1, 1 }, { 2, 2 }  // two frames for sprite A
    },
    {
        { 3, 3 }, { 4, 4 }  // two frames for sprite B
    }
};
Run Code Online (Sandbox Code Playgroud)

这会导致以下错误消息:

prog.cpp: In …
Run Code Online (Sandbox Code Playgroud)

c++ arrays vector coordinates

5
推荐指数
1
解决办法
5370
查看次数

标签 统计

arrays ×1

c++ ×1

coordinates ×1

vector ×1