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

Pages: [1]
1
General / Re: Fps switches between 60 and 50
« on: May 10, 2014, 10:07:32 pm »
Thanks for your post, will try some solution with delta time instead.
I use new/delete out of habit I guess, no need to worry about about stack memory limit :)

2
General / Fps switches between 60 and 50
« on: May 10, 2014, 09:02:54 pm »
Hello.
Im trying to run my main loop at a static 60 fps, but sometimes it decides to limit the fps to 50. I guess this problem could be caused by many reasons, I have checked my cpu speed and seems to be running at full clockspeed. Any ideas?

#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include "model.h"
#include <iostream>
int main() {
    sf::RenderWindow window(sf::VideoMode(1024, 768), "Azyrium");

    Model * model = new Model();
    sf::Clock clock;
    sf::View view2;
    view2.setSize(1920,1080);
    view2.setCenter(960,540);
    window.setView(view2);
    while (window.isOpen()) {
        clock.restart();
        sf::Event event;
        while (window.pollEvent(event)) {
            if (event.type == sf::Event::Closed) {
                window.close();
            }
            else if (event.type == sf::Event::KeyPressed || event.type == sf::Event::KeyReleased ) {
                model->handleInput(event);
            }
        }
        model->updateGame();
        window.clear();
        model->drawGame(window);
        window.display();
        while (clock.getElapsedTime().asMicroseconds() < 16667) {
            sf::sleep(sf::microseconds(16667-clock.getElapsedTime().asMicroseconds()));
            std::cout << 1/((double)(clock.getElapsedTime().asMicroseconds())/1000000 ) << std::endl;
        }

    }
    delete model;
    return 0;
}
Main loop.

3
General / Problem when replacing sdl with sfml, kinda :)
« on: June 10, 2009, 12:05:54 pm »
Ye well thats probably true.

Anyway i have narrowed down the problem



Code: [Select]
#include "SDL.h"
#include <string>
#include "Gamestate.h"
#include "SDL_mixer.h"
#include "SDL_image.h"
#include <SFML/Graphics.hpp>
 #include <SFML/Audio.hpp>
#include <SFML/System.hpp>
using namespace std;

#ifndef SELECTSCREEN_H
#define SELECTSCREEN_H
//class Model;

class SelectScreen: public Gamestate{
      private:
      sf::Sprite background1;
      sf::Sprite startbutton1;
      sf::Sprite quitbutton1;
      sf::Sprite buttonunderline1;
      sf::Sprite optionsbutton1;
      sf::Sprite continuebutton1;

   





      public:

             SelectScreen(Model *lol);

            ~SelectScreen(){}

           void drawStagelow(sf::RenderWindow  *screenen);
           void handleinput(bool keys[10]);
           void updateStage();
           sf::Sprite getSprite(){return background1;}


      };





#endif
















Code: [Select]
            SelectScreen::SelectScreen(Model *lol) : Gamestate(lol){


                       sf::Image Image;
    Image.LoadFromFile("backgrounds/selectscreen.bmp");
     background1.SetImage(Image);

}










Code: [Select]
            void SelectScreen::drawStagelow(sf::RenderWindow  *screenen){
                 sf::Image Image;
    Image.LoadFromFile("backgrounds/selectscreen.bmp");
     sf::Sprite Sprite1;

     Sprite1.SetImage(Image);


               //dont work   screenen->Draw(background1);
               
               
               //work        screenen->Draw(Sprite1);




     

                       }

I find it weird that only one of them work.

4
General / Problem when replacing sdl with sfml, kinda :)
« on: June 09, 2009, 05:43:18 pm »
The events shouldnt effect the window?
Its not a global variable, im sending it as a parameter

model->drawAll(app);

5
General / Probably a noob error
« on: June 09, 2009, 05:41:06 pm »
Why am i hiding the problem? :D
I got it to work with codeblocks when i followed the tutorial.I just couldnt find the place to add SFML_DYNAMIC. in devc++.

6
General / Probably a noob error
« on: June 09, 2009, 04:32:31 pm »
I had to  switch form devc++ to code blocks to get it work =P

7
General / Problem when replacing sdl with sfml, kinda :)
« on: June 09, 2009, 04:21:00 pm »
Hello


First i create the app window, and then send the window to another class that are supposed to draw something on it.But the window is blank when i run the program.
I can see the image if I make some ugly code and draw an image in the main loop.

Code: [Select]
#include "SDL.h"
#include <string>
#include "Window.h"
#include "Model.h"
#include "SDL_mixer.h"
#include "SDL_ttf.h"
#include <SFML/Graphics.hpp>
 #include <SFML/Audio.hpp>
#include <SFML/System.hpp>



using namespace std;


int main( int argc, char* args[] )
{
        if( SDL_Init( SDL_INIT_EVERYTHING ) == -1 )
    {
        return 1;
    }


    //Initialize SDL_ttf
    if( TTF_Init() == -1 ){
         return false;
         }
    Mix_OpenAudio( 44000, MIX_DEFAULT_FORMAT, 2, 4096 );
    sf::RenderWindow *app;
    app = new sf::RenderWindow(sf::VideoMode(800, 600), "SFML window");
     //(sf::VideoMode(800, 600), "SFML window");

    Model *model = new Model();
 //   Window *theWindow = new Window(800,600,model);
    SDL_Event event;
    bool keysHeld[10] = {false};
  //  bool keyPulses[10];
  //  keyPulses[4] = true;
    long start;
 //   SDL_ShowCursor(SDL_DISABLE);


    sf::Image Image;
    Image.LoadFromFile("backgrounds/selectscreen.bmp");
     sf::Sprite Sprite1;

     Sprite1.SetImage(Image);

     // Sprite(Image);




    while( model->quitcheck() == false )
    {

        //If there's an event to handle
        if( SDL_PollEvent( &event ) )
        {
            //If a key was pressed
            if( event.type == SDL_KEYDOWN )
            {
           switch(event.key.keysym.sym) {
            case SDLK_LEFT:
        keysHeld[0] = true;
                 break;
            case SDLK_RIGHT:
        keysHeld[1] = true;
        break;
            case SDLK_UP:
        keysHeld[2] = true;
        break;
            case SDLK_DOWN:
        keysHeld[3] = true;
                 break;
           case SDLK_RETURN:
           //     if (keyPulses[4] == true){
                keysHeld[4] = true;
            //    keyPulses[4] = false;
          //      }

                break;
           case SDLK_ESCAPE:
                keysHeld[5]= true;
                break;
                 }


            }
            if( event.type == SDL_KEYUP )
            {
           switch(event.key.keysym.sym) {
            case SDLK_LEFT:
        keysHeld[0] = false;
                 break;
            case SDLK_RIGHT:
        keysHeld[1] = false;
        break;
            case SDLK_UP:
        keysHeld[2] = false;
        break;
            case SDLK_DOWN:
        keysHeld[3] = false;
                 break;
           case SDLK_RETURN:
                keysHeld[4] = false;
             //   keyPulses[4] = true;
                break;
           case SDLK_ESCAPE:
                keysHeld[5] = false;
                break;
                 }

                 }

        }

       start = SDL_GetTicks();
       model->handleinput(keysHeld);
       model->updateGame();
       model->drawAll(app);
     //  app->Draw(Sprite1);
       app->Display();


    //   theWindow->draw();
       while((start + 16.67) > SDL_GetTicks()){

                   }

        }


    SDL_Quit();

    return 0;
}





Code: [Select]
void Model::drawAll(sf::RenderWindow *screenen){


                 gamestate->drawStagelow(screenen);

}





// Selectscreen is a subclass to gamestate
Code: [Select]
            void SelectScreen::drawStagelow(sf::RenderWindow  *screenen){
                 screenen->Draw(background1);




          //      apply_surface(offsetbackground.x,offsetbackground.y,background,screenen,&test);
          //      apply_surface(offsetstart.x - test.x,offsetstart.y, startbutton,screenen,&test);
           //     apply_surface(offsetquit.x - test.x,offsetquit.y, quitbutton,screenen,&test);
           //     apply_surface(offsetunderline.x - test.x,offsetunderline.y, buttonunderline,screenen,&test);
           //     apply_surface(offsetcontinue.x - test.x,offsetcontinue.y, continuebutton,screenen,&test);
           //     apply_surface(offsetoptions.x - test.x,offsetoptions.y, optionsbutton,screenen,&test);

                       }



8
General / Probably a noob error
« on: June 07, 2009, 08:13:17 pm »
Hello

When i try to add the following to my program

Code: [Select]
sf::Sprite test;

It replies

  variable 'vtable for sf::Sprite' can't be auto-imported. Please read the documentation for ld's --enable-auto-import for details.

What am I doing wrong.

I can use the following without a problem(that i know of)

Code: [Select]
sf::RenderWindow App(sf::VideoMode(800, 600), "SFML window");

 sf::Image Image;
 Image.LoadFromFile("backgrounds/selectscreen.bmp");

Pages: [1]
anything