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

Show Posts

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.


Messages - Nibbler

Pages: [1]
1
Window / Re: SFML 2.0 and sf::view
« on: June 14, 2012, 04:12:58 pm »
Here is the function I call at the line you mentionned.

void Map::drawSprites()
{
  std::list<Object>::iterator it;
  int pos_x;
  int pos_y;

  for (it = _listObject.begin(); it != _listObject.end(); ++it)
    {
      sf::Vector2<unsigned int> vectorWinSize;
      sf::Vector2<unsigned int> vectorImageSize;

      vectorWinSize = _app->getSize();
      vectorImageSize = _imageMap["grass"].getSize();
      pos_x = ((*it).getX() - (*it).getY()) * (vectorImageSize.x / 2) + (vectorWinSize.x / 2);
      pos_y = ((*it).getX() + (*it).getY()) * (vectorImageSize.y / 2 - 4) + 50;

      sf::Sprite sprite;
      sprite.setTexture(_imageMap["grass"]);
      sprite.move(pos_x, pos_y);
      _app->draw(sprite);
    }
}

It's very simple, I iterate on a std::list of objects, and I draw them in the window.
I don't understand what do you mean by window.setView(_app->setView(_view));. I don't have any kind of window variable. My variable _app is the variable which initialize the screen.

Thank you for your help. :)

Edit:
I solved my problem.
Indeed, the _app->setView method was called at the wrong place. :)

2
Window / SFML 2.0 and sf::view
« on: June 14, 2012, 02:22:24 pm »
Hello,

I want to use the sf::view class in sfml 2.0 to be able to implement a kind of camera in my application.
I started to implement what I wanted in sfml 1.6 but for many reasons I switch to sfml 2.0. My implementation of views worked well with the sfml 1.6, but it doesn't in 2.0. I can't move the view, I don't know why.

Here is the piece of code :

  while (_app->isOpen())
    {
      while (_app->pollEvent(event))
        {
          if (event.type == sf::Event::Closed)
            _app->close();
          if (event.type == sf::Event::KeyPressed)
            {
              float Offset = 200.f; // I need to change that. I know :-)                                                                                                                                                    
              if (event.key.code == sf::Keyboard::Up) _view.move( 0,      -Offset);
              if (event.key.code == sf::Keyboard::Down)  _view.move( 0,       Offset);
              if (event.key.code == sf::Keyboard::Left)  _view.move(-Offset,  0);
              if (event.key.code == sf::Keyboard::Right) _view.move( Offset,  0);
            }
        }

      _app->clear();
     // Here come the function that draw my sprites...
      _app->display();
    }

With that kind of code, I am suppose to move the view. Apparently, the view move pretty well (I tested by getting the coordonates of the center of the view which is modified when I press a key), but on the window nothing happen.

Can you explain me why ?

Thank you.

Pages: [1]
anything