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

Pages: [1]
1
Graphics / sf::view.zoom() sync with framerate...
« on: May 07, 2012, 06:34:03 am »
Anyone have a suggestion as how to do this? Similar to how you would keep a sprite moving at constistent speed independent of frametime. I'm trying something like this...

Code: [Select]
///CAMERA CONTROLS (main app update loop)
if (IsKeyDown[sf::Keyboard::Subtract])      mCamera.ZoomOut();


///Camera Class
Camera::ZoomOut(){
    mview.zoom(1 + mApp->GetFrameTime());
}

This wont quite cut it though. If the framerate is 1000 fps the factor is 1.001 or100.1% of original viewport size.
If it is 60 fps it is 101%.

Since a higher framerate means ZoomOut() gets called more often I was thinking that It would naturally appear to zoom at the same speed but It seems thats not the case.

So basically I'm not sure what kind of math to use here to get a consistent zoom factor across different framerates and my brain is hurting a little bit. Any thoughts?


2
General / SFML 2.0 : Missing DLL's
« on: January 19, 2012, 03:51:09 am »
sorry if this has been asked before as I'm sure it may have been, but I could not find anything.

Before I upgraded to 2.0 from 1.6 I was linking against the static libs which had a -s suffix ("libsfml-graphics-s.a" I believe) because if I tried any other way I would get this same problem and it just seemed easier. I'm now linking with the 2.0 libs which dont have the '-s' in the filename. I can get my project to compile but it says I'm missing the dlls.

Should I be linking with the DLL's until this version is finalized? Or am I missing something else?

3
Graphics / Create a line segment shape in sfml 2.0?
« on: January 18, 2012, 02:55:57 am »
Just upgraded to sfml 2.0 before I got too far in my project. I was updating my debug draw class for box 2d to match the new API when I noticed there is no line segment shape in 2.0. Should I just use a really skinny rectangle? :)

4
Graphics / Release SF::image resource
« on: October 04, 2011, 04:46:42 am »
Is their a way to release an sf::image without deleting it. Also without modifying the sfml source..

I'm trying to put together a resource manager that can cache certain resources depending on the game state and quickly load and release them. but I have my image resource inherit from sf::image and dont really see a public function that would allow that.

the only thing I can think of would be to have a sf::image member in my resource class like so...

Code: [Select]

class myImageResource{
    private:
        sf::image * mySFImage;
        std::string myFileName;
    public:

        myImageResource(std::string theFileName):
            myFileName(theFileName)
            mySFImage(new sf::image)   //<--- not really sure if thats legal but you get the idea...

        void Load(){
             mySFImage->LoadFromFile(mFileName
        }
       
        void Release(){
            delete mySFImage;
        }

};


this is just an example but it already feels hacky and unsafe. I dont want to have to create and delete the sf::image every time ya know? I really want the resource to inherit from sf::image to make things streamlined.

any thoughts, comments?

5
Graphics / Get rectangle of a sprite or image
« on: April 25, 2011, 03:37:21 am »
Just wondering if there was a function like sprite.getrect or image.getrect. similar to the method a view has. Well, I know there is no function but I guess is there a simple implementation? I'm trying to set a boundary for my camera by using the limits of a large level background sprite.

Isn't a sprite just a rectangle with an image?

heres what I've been trying to do currently with little success:

Pseudo code:

Here I try to create my own rectangle from the dimensions of a sprite. It will not compile though and says there is no matching function for call to sf::shape::rectangle. I assume its because an sf::shape is not at all an sf::rect.
Code: [Select]
Engine_Class{
    sf::Rect <float> CameraBounds = sf::Shape::Rectangle(0,sprite_width,0,sprite_height);  
    Cam1.SetBounds(CameraBounds);
}



This next part should (theoretically) work if I could just come up with a rectangle lol!
Code: [Select]

Camera_Class{
    sf::Rect <float> myBoundary;
   
    void Camera::SetBounds(sf::Rect <float> CameraBounds){
        myBoundary = CameraBounds;
    }

    bool Camera::Within_Bounds(){

        if (ViewPort.GetRect().Left < myBoundary.Left) return false;
        if (ViewPort.GetRect().Right > myBoundary.Right) return false;
        if (ViewPort.GetRect().Top < myBoundary.Top) return false;
        if (ViewPort.GetRect().Bottom > myBoundary.Bottom) return false;

        return true;
    }

}


any suggestions/thoughts/advice?

6
Graphics / sprite.move makes sprite disappear
« on: April 08, 2011, 02:55:19 am »
So i seem to be missing something with the sprite.move function. whenever i use the move function and then try to draw the sprite... nothing happens. If i use set position and then draw it appears no problem.

There are 2 classes; engine and object. Engine has the renderwindow, Object array element GameObject[0] has the sprite.

assume the sprite has already initially been drawn at its start location.

EVENT HANDLER
Code: [Select]

void Engine::EventHandler(){
    GameWindow.GetEvent(Event);
    if (Event.Type == sf::Event::KeyPressed){
        switch (Event.Key.Code) {

            case sf::Key::Right:
                GameObject[0].Move(6);
                break;
            case sf::Key::Return:
                GameObject[0].Sprite.SetPosition(200,200);
                break;
            case sf::Key::Space:
                GameWindow.Draw(GameObject[0].Sprite);
                GameWindow.Display();
                break;


OBJECT MOVE FUNCTION
Code: [Select]
bool Object::Move(char Direction){
    //direction 6 == right
    if (Direction == 6)    Sprite.Move(10,0);


}

[/b]

7
Graphics / Noob: pass &RenderWindow to constructor. Set as Public v
« on: March 26, 2011, 03:28:04 am »
So basically I'm trying to pass a reference to an sf::renderwindow to the class 'game_object' and then set that as a public referenced object within the class itself.

That way any of Game_objects members can draw to that window without the reference being explicitly passed to the member itself (thats no problem just seems inefficient).

Heres a snippet of what I'm trying to do.

Class Header
Code: [Select]
class Game_Object {
    public:

        // constructor / destructor
        Game_Object(sf::RenderWindow &Window);
        virtual ~Game_Object();
 
        //{ SFML stuff
        sf::RenderWindow Draw_target;
        sf::Sprite Sprite

};


.cpp Constructor

Code: [Select]
Game_Object::Game_Object(sf::RenderWindow &Window){
    Draw_target = &Window;
}


Main
Code: [Select]
int main{
   sf::RenderWindow GameWindow;
   Game::Object Ship(GameWindow);
}



I've tried making 'draw_target' a pointer and using the '->' operator to access the 'draw' member of the render window. But the compiler didn't like that. Didn't seem right to me either. I mean its a pointer TO an object not an object itself right?

So how is this normally done if at all?

Pages: [1]
anything