Dec 6, 2013 at 3:20pm UTC
for(std::vector<GameObject*>::size_type i = 0;
i != m_gameObjects.size(); i ++)
I am getting the error message: 'm_gameObjects' : attribute not found. With regards to this slither of code.
Dec 6, 2013 at 3:26pm UTC
It sounds like m_gameObjects isn't defined. Perhaps you misspelled it, or declared it in a scope outside of where you're trying to access it.
Dec 6, 2013 at 4:09pm UTC
I assumed that was the problem also. But another instance of m_gameObjects compiles successfully earlier in the same source file.
Dec 6, 2013 at 4:10pm UTC
I may have defined it incorrectly...
std::vector<GameObject*> m_gameObjects;
Dec 6, 2013 at 4:11pm UTC
You haven't shown us nearly enough code for us to be able to answer this.
Dec 6, 2013 at 4:14pm UTC
It might be a scope issue.
m_gameObjects is defined in your class... but is the problematic for loop inside a class method? Is it in a static class method?
MikeyBoy is right, we're going to need to see more code. Specifically where and how m_gameObjects is defined... and where that for loop is.
Dec 6, 2013 at 4:18pm UTC
#include "game.h"
#include "TextureManager.h"
#include <vector>
#include "GameObject.h"
typedef TextureManager TheTextureManager;
bool Game::init(const char* title, int xpos, int ypos, int width, int height, int flags)
{
if(SDL_Init(SDL_INIT_EVERYTHING) == 0)
{
m_pWindow = SDL_CreateWindow(title, xpos, ypos, width, height, flags);
if(m_pWindow != 0)
{
m_pRenderer = SDL_CreateRenderer(m_pWindow, -1, 0);
if(m_pRenderer != 0)
{
SDL_SetRenderDrawColor(m_pRenderer, 255,255,255,255);
}
else
{
return false;
}
}
else
{
return false;
}
}
else
{
return false;
}
m_go = new GameObject();
m_player = new player();
m_go->load(100, 100, 128, 82, "animate");
m_player->load(300, 300, 128, 82, "animate");
m_gameObjects.push_back(m_go);
m_gameObjects.push_back(m_player);
if(!TheTextureManager::Instance()->load("assets/animate.png", "animate", m_pRenderer))
{
return false;
}
m_bRunning = true;
return true;
}
void Game::render()
{
SDL_RenderClear(m_pRenderer);
for(std::vector<GameObject*>::size_type i = 0;
i != m_gameObjects.size(); i ++)
[
m_gameobjects[i]->draw(m_pRenderer);
}
SDL_RenderPresent(m_pRenderer);
}
void Game::update()
{
for(std::vector<GameObject*>::size_type i = 0; i != m_gameObjects.size(); i ++)
{
m_gameObjects[i]->update();
}
}
void Game::handleEvents()
{
SDL_Event event;
if(SDL_PollEvent(&event))
{
switch (event.type)
{
case SDL_QUIT:m_bRunning = false;
break;
default:
break;
}
}
}
void game::draw()
{
for(std::vector<GameObject*>::size_type i = 0; i != m_gameObjects.size(); i ++)
{
m_gameObjects[i]->draw(m_pRenderer);
}
}
void Game::clean()
{
SDL_DestroyWindow(m_pWindow);
SDL_DestroyRenderer(m_pRenderer);
SDL_Quit();
}
;
Dec 6, 2013 at 4:19pm UTC
std::vector<GameObject*> m_gameObjects;
is in game.h
Dec 6, 2013 at 4:19pm UTC
sorry I'm new to programming.
Dec 6, 2013 at 4:21pm UTC
This is the contents of game.h
#include "GameObject.h"
#include "player.h"
#include <vector>
GameObject* m_go;
GameObject* m_player;
std::vector<GameObject*> m_gameObjects;
class Game {
public:
Game(){}
~Game(){}
bool init(const char* title, int xpos, int ypos, int width, int height, int flags);
void render();
void update();
void handleEvents();
void clean();
bool running() {
return m_bRunning; }
private:
SDL_Window* m_pWindow;
SDL_Renderer* m_pRenderer;
int m_currentFrame;
bool m_bRunning;
};
#endif /*
defined (__Game__) */
Dec 6, 2013 at 4:23pm UTC
Thanks Disch you nailed it. Really appreciate the help.