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.


Topics - keyforge

Pages: [1]
1
General discussions / Creating a new sf::Event object in each loop?
« on: October 23, 2011, 04:19:03 am »
Hello, everyone! I have a question about most SFML code I see. Why are they redeclaring an sf::Event object after while(Window.IsOpened()). Wouldn't this cause the sf::Event constructor to be called each time creating a new object and hurting performance slightly? Is there any difference in declaring sf::Event before the main window loop?

2
General discussions / Runtime error when closing app via console...
« on: August 20, 2011, 07:58:39 pm »
Hello everyone, I'm having an issue with an app I wrote. when I close the window through the window's close button, it closes fine with no errors, but when I close the window through the console it gives me a runtime error. Normally I wouldn't care about the console but it makes me weary that there might be a memory leak somewhere. Does anyone know how I could fix this? If you need my code I can give it to you.

3
General discussions / Mouse Coordinate scaling?
« on: July 05, 2011, 01:38:19 am »
Hello :)

I have a 3D rendering in the background and a 2D GUI drawn on top. When I resize the Window it resizes the GUI objects and 3D objects like it should, but when I hover it only works if I put my mouse over the original coordinates and not the resized or scaled ones. Does anyone know how to fix this? I'm using OpenGL for 3D rendering and drawing the GUIs.

4
General discussions / Only getting 16 FPS?
« on: June 23, 2011, 03:07:54 am »
Hello, I'm only getting like 16 FPS with this game loop. When I move the render outside of the loop I'm getting like 800 FPS. Is this an issue with my code or SFML 2? I have SetFramerateLimit() at 60 and my computer is pretty new.

When I cout 1.f / myWindow.GetFrameTime() it says like 0.0######.
When I cout myWindow.GetFrameTime() it says 16 or 15.

Help please?

Code: [Select]
void Game::Tick() {
while(myWindow.IsOpened() && myRunning) {
sf::Uint32 elapsedTime = myLoopClock.GetElapsedTime();
myLoopClock.Reset();

       while(elapsedTime > myLoopClock.GetElapsedTime()) {
       sf::Event tmpEvent;
       while(myWindow.PollEvent(tmpEvent)) {
        HandleEvents(tmpEvent);
                        }
}

myStateManager.Update();

myStateManager.Render();
myWindow.Display();
myStateManager.Cleanup();

std::cout << 1.f / myWindow.GetFrameTime() << std::endl;
}
}

5
General discussions / How to handle GUI Events Correctly?
« on: June 16, 2011, 07:05:11 pm »
Hello, SFML Community!

My project I'm working on is http://www.mediafire.com/?12wf6lfvjwc3n6g. (You need MSVC++ 2010 Runtime to run it, Windows only ATM, sorry Mac and Linux!)

A little about my project: This is my first time writing a GUI and a game. I've written 95% of the engine by myself so I'm pretty happy how my first games turning out. It's only about 10% done at it's current state though. I wrote a game engine for it and most of my code is pretty clean other than a few hacks put in for testing. Please excuse my bad code if there's any. Game developing is exciting!

My Text Button Widget works OK but mess around with it with holding down and stuff and it has messed up hovering and `activation`. When held down or clicked it should be the darker gold color and when hovering only it should be selective yellow (the yellow on the Asteroids logo).

All widget events are handled by a Widget interface with virtual event functions and the widget event function is as follows:

Code: [Select]
void HandleEvents(sf::Event eEvent) {
if(eEvent.Type == sf::Event::MouseMoved) {
if(myGame->GetInput().GetMouseX() >= myPosition.x && myGame->GetInput().GetMouseX() <= myPosition.x + myDimensions.x && myGame->GetInput().GetMouseY() >= myPosition.y && myGame->GetInput().GetMouseY() <= myPosition.y + myDimensions.y) {
OnMouseOver(eEvent.MouseMove);
myHover = true;
}

if(myHover == true && myGame->GetInput().GetMouseX() <= myPosition.x || myHover == true && myGame->GetInput().GetMouseX() >= myPosition.x + myDimensions.x || myHover == true && myGame->GetInput().GetMouseY() <= myPosition.y || myHover == true && myGame->GetInput().GetMouseY() >= myPosition.y + myDimensions.y) {
OnMouseOff(eEvent.MouseMove);
myHover = false;
}
}

if(eEvent.Type == sf::Event::MouseButtonPressed) {
OnClickPressed(eEvent.MouseButton);
}

if(eEvent.Type == sf::Event::MouseButtonReleased) {
OnClickReleased(eEvent.MouseButton);
}

if(eEvent.Type == sf::Event::KeyPressed) {
OnKeyPressed(eEvent.Key.Code);
}

if(eEvent.Type == sf::Event::KeyReleased) {
OnKeyReleased(eEvent.Key.Code);
}
}


And my Text Button virtual function implementations are:

Code: [Select]

void Button_Widget::OnMouseOver(const sf::Event::MouseMoveEvent& bMove) {
if(!IsActivated()) {
myText.SetColor(sf::Color(255, 186, 0));
SetActivated(false);
} else {
myText.SetColor(sf::Color(218, 165, 32));
}
}

void Button_Widget::OnMouseOff(const sf::Event::MouseMoveEvent& eMove) {
myText.SetColor(sf::Color(192, 192, 192));

if(IsActivated()) {
SetActivated(false);
}
}

void Button_Widget::OnClickPressed(const sf::Event::MouseButtonEvent& eButton) {
if(IsHovering() && eButton.Button == sf::Mouse::Left) {
myText.SetColor(sf::Color(218, 165, 32));
}
}

void Button_Widget::OnClickReleased(const sf::Event::MouseButtonEvent& eButton) {
if(IsHovering() && eButton.Button == sf::Mouse::Left) {
myText.SetColor(sf::Color(255, 186, 0));
SetActivated(true);
}
}

void Button_Widget::OnKeyPressed(sf::Key::Code kKey) {
if(kKey == sf::Key::Return) {
SetActivated(true);
}
}

void Button_Widget::OnKeyReleased(sf::Key::Code kKey) {
if(kKey == sf::Key::Return) {
SetActivated(false);
}
}


If any of you know a better way to handle the events and hovering and activation please let me know! Thank you!

6
Network / TCP or UDP for a simple pong game, and help designing loop?
« on: June 02, 2011, 09:08:38 pm »
Hello everyone, just thought I would introduce myself. I am new here at the SFML Forums. I'm a beginning game programmer and have a small amount of experience with C++ and I know the basics of networking.

Which would be more suitable for a simple online pong game with a chat, UDP or TCP? And UDP or TCP for the chat too? Setting up multiple streams would probably be wise if I were to do so.

I'm lost with networking with my game loop. What I'm thinking is a design like:  

main
  engine::network::setup();
  engine::game::run();
 
And for my Update method within my engine, and please note this is not real code and is just a design document:

Code: [Select]

engine::game::tick() {
  while(myWindow.IsOpened()
    while(myWindow.GetEvent())
      currentState.HandleEvents();
      engine::network::SendData();
      myWindow.Clear();
      currentState.Draw();
      myWindow.Display();
    }
  }
}


Criticism is welcome :)

Also, should my server and client be separate programs? Or should I just assign a server to the person who starts the game? How would that implement into the loop?

Also, anyone with articles to share please share them :)

Pages: [1]