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

Pages: [1] 2
1
Window / Re: "Empty" Window is slow
« on: August 30, 2018, 03:50:13 pm »
Try calling window.setFramerateLimit(60) or window.setVerticalSyncEnabled(true).

But not both!!

2
No problem  :D

3
Hmm. Try this:

Text Game::createText(Font &f, const String &string) {
        Text text;
        text.setFont(f);
        text.setString(string);
        return text;
}

// lines more

        Font font;
        font.loadFromFile("fonts/ARCADECLASSIC.ttf");

        Text text1 = createText(font, "PLAY");
 

(Pass the font by reference instead of by value)
Not sure if this will fix it, but again, I think it's worth a shot :)

4
Graphics / Re: Rendering 2D tiled map
« on: August 03, 2018, 06:56:23 pm »
Have you seen this tutorial?

5
Try creating the font outside of your function and passing it in as a parameter.

SFML has a theme of internally storing pointers to graphical objects instead of copying them. I suspect that perhaps when you call setFont, the text object stores a pointer to the font object. This font object is then destroyed when the function ends (because you declared it in the function), causing a crash when SFML tries to draw it.

This is all purely speculative, but I think it would be worth a shot.

EDIT:
Yep; look at line 439 here

and the setFont function at line 129 here

The text object stores a pointer to its font. This pointer becomes invalid when the font is destroyed in your case.

6
General / Re: Where is the value for the Snake size? Snake Game
« on: August 03, 2018, 03:06:21 pm »
I'm not sure what you mean. Are you saying that it doesn't ever get filled?

void Snake::Reset() {
        m_snakeBody.clear();
        m_snakeBody.push_back(SnakeSegment(5, 7));
        m_snakeBody.push_back(SnakeSegment(5, 6));
        m_snakeBody.push_back(SnakeSegment(5, 5));

        SetDirection(Direction::None); // Start off still.
        m_speed = 15;
        m_lives = 3;
        m_score = 0;
        m_lost = false;
}
 

Upon reset, 3 SnakeSegments are inserted into m_snakeBody.

7
General / Re: Where is the value for the Snake size? Snake Game
« on: August 02, 2018, 03:15:09 pm »
Is it here?
SnakeContainer m_snakeBody; // Segment vector.

I think the size of the snake can be obtained like this:
m_snakeBody.size()

8
SFML projects / Super Litefite
« on: August 01, 2018, 02:39:31 am »
Super Litefite is a local (for now) multiplayer top down fighting game that uses light and perspective as core mechanics.

I'm writing my own game engine and using SFML for graphics/sound/input etc. It's my first time writing a game engine, so I'm learning a lot as I go!

Current progress: 25% (maybe ???)

Some gifs demonstrating the light:
   

You can see some more detailed stuff about it (and more pictures!) on my website: http://www.dogspluspl.us/games/

I'm also developing this as open source. You can see/download the code here: https://github.com/verdog/super-litefite

9
Graphics / Re: reset Transform?
« on: July 25, 2018, 03:27:48 pm »
As far as I know, that's not the proper way to use a transform. I think you should be doing it like this:
state.transform.translate(sf::Vector2f(10, 0));

And to reset it, I think you could do
state.transform = sf::Transform::Identity;

10
I think I know what's going on. See this.

When you call setTexture, the texture you use needs to live as long as the thing using it. You're declaring a texture locally in a member function, which means the texture gets destroyed when the function is completed.

To fix this, load the texture into memory separately from the button's method, and the set the button's texture with a reference to that texture.

11
Graphics / Re: Color and alpha blending.
« on: July 19, 2018, 01:45:06 am »
I think I got it!  :D

You were very close. All you had to do was draw the very final mask on with a blend mode of Multiply.
// change this:
window.draw(maskSprite);
// to this:
window.draw(maskSprite, sf::RenderStates(sf::BlendMultiply));
 

12
General / Re: player.move() sends player into wal
« on: July 18, 2018, 06:37:14 pm »
So you mean it gets stuck in the wall because your collision detection doesn't allow it to move out of the wall again?

I tend to check whether the next move would cause a collision and if it does, I'd resolve it by moving it as close to the wall as allowed. That way you never move the character beyond the allowed boundary and thus it can't get stuck.
This is how I do it too. Pseudocode:
// this moves the player to where he would be next frame
player.move(player.velocity);

// check for collision on next frame's position
if (player.collidesWithWall(wall)) {
  // move player back to position he was in (that is; not colliding with the wall)
  player.move(-player.velocity); // note the negative sign

  // slowly move player towards wall until they hit it
  while (!player.collidesWithWall(wall)) {
    player.move({tiny distance towards wall, maybe one pixel});
  }

  // player is now inside the wall, move them out
  player.move(-{same tiny distance as above}); // note the negative sign

  // player is now right up next to the wall. stop movement.
  player.velocity = Vector(0, 0);
}
 

13
General / Re: SFML Keybinds
« on: July 18, 2018, 06:24:27 pm »
Hapax what about mouse or joystick events?
For mouse you can use Mouse::Button (Documentation).
For joystick events you can use button indexes (which are just numbers) (Documentation)

14
Graphics / Re: Color and alpha blending.
« on: July 18, 2018, 06:11:49 pm »
In the first image, is the background an opaque black, or transparent (with nothing behind it)?

Can you post code necessary to reproduce this?

15
General / Re: SFML slows down over time
« on: July 18, 2018, 02:31:18 am »
I ran your code for 5 minutes and the framerate stayed more or less constant.

Pages: [1] 2
anything