我正在制作一个简单的基于重力的粒子系统,因此我制作了三个类:
ParticleManager
ParticleSystem
,包含具有更新功能的粒子的VertexArray
Particle
,一个从sf :: Transformable继承的顶点。
实际上,我在ParticleSystem
更新功能时遇到了代码:
ParticleSystem()
{
particles.setPrimitiveType(PrimitiveType::Points);
int indexX = 0, indexY = 0;
for (int i = 1; i < CHUNK_SIZE; i++)
{
Particle particle;
particle.position = Vector2f(indexX, indexY);
particles.append(particle);
if (indexX < 100)
indexX++;
else
{
indexX = 0;
indexY++;
}
force.push_back(0);
}
}
void Update()
{
for (int i = 0; i < particles.getVertexCount(); i++)
{
particles[i].Update();
}
}
编译器在调用particles[i].Update()
时出错,因为VertexArray只能包含sf :: Vertex;
有关实施该功能的任何建议吗?
答案 0 :(得分:0)
制作自己的矢量。
std::vector<Particle> particles;