Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Window  (Read 1425 times)

0 Members and 1 Guest are viewing this topic.

northLynx

  • Newbie
  • *
  • Posts: 9
    • View Profile
Window
« on: June 08, 2016, 10:13:19 pm »
I have got the new sfml game development by example book and I have been following the code for the snake program in chapter 3. When I get to the last part before running the program I get an error . In the void Game::Render() method i pass in the pointer *m_window.GetRenderWindow() to the m_world and m_snake but I get and error saying no operator "*" matches these operands type *Window. Also, I dont remember the book telling me to write a GetRenderWindow() method either. Can someone help me out please.

void World::Render(sf::RenderWindow &l_window)
{
   for (int i = 0; i < 4; ++i)
   {
      l_window.draw(m_bounds);
   }
   l_window.draw(m_appleShape);
}

void Snake::Render(sf::RenderWindow& l_window)
{
   if (m_snakeBody.empty()) { return; }

   auto head = m_snakeBody.begin();
   m_bodyRect.setFillColor(sf::Color::Yellow);
   m_bodyRect.setPosition(head->position.x * m_size, head->position.y * m_size);
   l_window.draw(m_bodyRect);

   m_bodyRect.setFillColor(sf::Color::Green);
   for (auto itr = m_snakeBody.begin() + 1; itr != m_snakeBody.end(); ++itr)
   {
      m_bodyRect.setPosition(itr->position.x * m_size, itr->poistion.y * m_size);
      l_window.draw(m_bodyRect);
   }
}


void Game::Render()
{
   m_window.BeginDraw(); // clear

   m_world.Render(*m_window.GetRenderWindow());
   m_snake.Render(*m_window.GetRenderWindow());

   m_window.EndDraw(); //display
}

my error occurs when I pass in the *m_window to the game render function. Also the book says to call those functions which I never made because the book never created those functions either
« Last Edit: June 09, 2016, 02:06:51 am by northLynx »

GameBear

  • Jr. Member
  • **
  • Posts: 73
    • View Profile
    • Email
Re: Window
« Reply #1 on: July 04, 2016, 06:50:55 pm »
Hey man. yea,I've got the book too, and indeed, there are some missing snips of code here and there.

The GetRenderWindow being one of them.
The book never tells you to do it or even mentions it.

The code that i made to solve it:

in the Window header as public i made:

sf::RenderWindow* getRenderWindow();


and in the Window cpp i made:

sf::RenderWindow* Window::getRenderWindow() {
   return &m_window;
}


This is working for me... but I don't know if that was the intended goal?
string message = "some random dude";
cout << "I'm just " << message;

 

anything