1
Graphics / Re: Trying to create a graphics engine
« on: November 21, 2017, 06:28:52 pm »
Wow thank you, didn't notice I was doing that
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
1>d:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\xmemory0(774): error C2528: 'pointer': pointer to reference is illegal
1>d:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\xmemory0(984): note: see reference to class template instantiation 'std::allocator<_Ty>' being compiled
1> with
1> [
1> _Ty=sf::Drawable &
1> ]
#ifndef GRAPHICS_ENGINE
#define GRAPHICS_ENGINE
class GraphicsEngine
{
public:
GraphicsEngine();
~GraphicsEngine();
int addToVector(sf::Drawable& drawableObject);
void deleteFromVector(int objectNumber);
void callObjectsDraw(sf::RenderWindow& window);
private:
std::vector<sf::Drawable&> vectorOfDrawableObjects;
};
#endif
#include "stdafx.h"
#include "graphicsEngine.h"
GraphicsEngine::GraphicsEngine()
{
}
GraphicsEngine::~GraphicsEngine()
{
}
int GraphicsEngine::addToVector(sf::Drawable& drawableObject)
{
vectorOfDrawableObjects.push_back(drawableObject);
int objectNumber = vectorOfDrawableObjects.size();
return objectNumber;
}
void GraphicsEngine::deleteFromVector(int objectNumber)
{
vectorOfDrawableObjects.erase(vectorOfDrawableObjects.begin() + objectNumber);
}
void GraphicsEngine::callObjectsDraw(sf::RenderWindow& window)
{
for (int i = 0; i < vectorOfDrawableObjects.size(); i++)
{
window.draw(vectorOfDrawableObjects[i]);
}
}
You try to use something called "Block" in containerOfBlocks.h. The compiler has no idea what "Block" is and complains. Now, you include block.h, which defines what "Block" is, in containerOfBlocks.h and the compiler is happy. You really don't understand why that fixed the problem?
error C2065: 'Block' : undeclared identifier c:\users\dylan\documents\visual studio 2013\projects\pong\containerofblocks.h 10 1 Pong
error C2923: 'std::vector' : 'Block' is not a valid template type argument for parameter '_Ty' c:\users\dylan\documents\visual studio 2013\projects\pong\containerofblocks.h 10 1 Pong
error C2065: 'Block' : undeclared identifier c:\users\dylan\documents\visual studio 2013\projects\pong\containerofblocks.h 17 1 Pong
error C2923: 'std::vector' : 'Block' is not a valid template type argument for parameter '_Ty' c:\users\dylan\documents\visual studio 2013\projects\pong\containerofblocks.h 17 1 Pong
The important part to keep it at consistent speed is the time - multiplying any motion by the time passed. Notice in eXpl0it3r's example that the velocity was multiplied by dt (delta time - time taking since the previous frame).
The simplest solution is to do:
while(window.isOpen()) {
sf::Time dt = clock.restart();
// ...
pos += velocity * dt.asSeconds();