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 - GarryS

Pages: [1]
1
General / Re: Resolved ( I think )
« on: January 07, 2012, 04:54:53 am »
Quote from: "Lee R"
Code: [Select]

moveHero(dave.location,dave.location = dave.location -= X_TILES);


Don't do that. The C++ standards does not specify the order of evaluation for function arguments.


Thanks for the info.  Fixing that now!

2
General / Resolved ( I think )
« on: January 07, 2012, 04:40:45 am »
This seems to be a much better way to accomplish what I was attempting.

Code: [Select]

   while (window.PollEvent(event)) {
      processEvents(window, event);
      switch (event.Type) {
        case sf::Event::KeyReleased:
        if (event.Key.Code == sf::Keyboard::Up) {
          moveHero(dave.location,dave.location = dave.location -= X_TILES);
          break;
        }
        if (event.Key.Code == sf::Keyboard::Down) {
          moveHero(dave.location,dave.location = dave.location += X_TILES);
          break;
        }
        if (event.Key.Code == sf::Keyboard::Left) {
          moveHero(dave.location,dave.location = dave.location -= 1);
          break;
        }
        if (event.Key.Code == sf::Keyboard::Right) {
          moveHero(dave.location,dave.location = dave.location += 1);
          break;
        }
        default:
        break;
      }
    }


Thanks

3
General / Restricting Sprite Movement in Loop
« on: January 06, 2012, 11:16:47 pm »
I am using SFML 2.0...

I am confident that there is a better way but I have been banging my head on the wall for hours here.  

Basically, I have a character (sprite) that needs to move in an array but only 1 time per key press.  The code shows up and down "movement".  Left and Right would need to be additionally coded.

Here is what I have cobbled together but I know that this can't be "right":

Code: [Select]


bool keyUp = false;
bool keyDown = false;

while (window.IsOpened()) {
  while (window.PollEvent(event)) {
    if ((keyUp == false)&& sf::Keyboard::IsKeyPressed(sf::Keyboard::Up))) {
      keyUp = true;
      moveHero(dave.location,dave.location = dave.location -= X_TILES);
    }
    if ((keyUp == true)&&(!sf::Keyboard::IsKeyPressed(sf::Keyboard::Up)))
        keyUp = false;
      if ((keyDown == false)&&(sf::Keyboard::IsKeyPressed(sf::Keyboard::Down))) {
          keyDown = true;
          moveHero(dave.location,dave.location = dave.location += X_TILES);
      }
      if ((keyDown == true)&&(!sf::Keyboard::IsKeyPressed(sf::Keyboard::Down)))
          keyDown = false;
    }
  }
}


Anyone have a moment to help a noob out?

Thanks

4
Graphics / Drawing Multiple Sprites
« on: January 02, 2012, 10:07:51 pm »
Thanks Mario.  That is where the error was:

Code: [Select]

  if(!texture.LoadFromFile("cobblestone.png"))
    // return error
    for(int i = 0; i < sizeof(sprite) / sizeof(sprite[0]); i++) {
      sprite[i].SetTexture(texture);
    }


The version that was not working is was using
Code: [Select]

 i < sizeof(sprite);

 :roll:

I am going to implement your other suggestions now.  Thanks again!

5
Graphics / Drawing Multiple Sprites
« on: January 02, 2012, 09:18:23 pm »
Hello.  I am new to SFML and using version 2.  I am able to create and texture a sprite but when I try to create any more than 1,  I get an segmentation fault.  Here is how I am trying to display the sprites:

Code: [Select]

int i, x, tile = 0;
  for(i = 0; i < WINDOW_W; i += TILE_W) {
    for(x = 0; x < WINDOW_H; x += TILE_H) {
      sprite[tile].SetPosition(i, x);
      window.Draw(sprite[tile]);
    }
  }


Thank you for any suggestions!

Pages: [1]