本文整理汇总了C++中EntityManager::attachComponent方法的典型用法代码示例。如果您正苦于以下问题:C++ EntityManager::attachComponent方法的具体用法?C++ EntityManager::attachComponent怎么用?C++ EntityManager::attachComponent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类EntityManager
的用法示例。
在下文中一共展示了EntityManager::attachComponent方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main() {
ResourceManager resourceManager = ResourceManager();
resourceManager.addResourceDirectory("res/");
sf::RenderWindow window(sf::VideoMode(WINDOW_X, WINDOW_Y), "ECS Test");
EntityManager entityManager = EntityManager(&window, 100);
for (int i = 1; i < 10000; ++i) {
int temp = entityManager.createEntity(sf::Vector2f(WINDOW_X * float(rand()) / RAND_MAX, WINDOW_Y * float(rand()) / RAND_MAX));
entityManager.attachComponent(temp, RenderComponent(resourceManager.getTexture("player.png")));
entityManager.attachComponent(temp, PhysicsComponent(sf::Vector2f(100 * (float(rand()) / RAND_MAX - 0.5), 100 * (float(rand()) / RAND_MAX - 0.5))));
}
// Remove some entities.
for (int i = 1; i < 3; ++i) {
entityManager.destroyEntity(i);
}
// Remove some components.
for (int i = 3; i < 10; ++i) {
entityManager.detachComponent(i, RENDER);
}
sf::Clock clock;
while (window.isOpen()) {
// Handle events.
sf::Event event;
while (window.pollEvent(event)) {
if(event.type == sf::Event::Closed) {
window.close();
}
}
float frametime = clock.restart().asSeconds();
std::cout << (1 / frametime) << std::endl;
window.clear(sf::Color::White);
entityManager.update(frametime);
window.display();
}
}