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

Pages: [1]
1
Window / sf::Input and keypress repeat problem
« on: August 10, 2009, 05:17:27 pm »
I don't think there is anything exotic on my Ubuntu. I tried disabling Compiz, but it didn't change anything. If I think of something I'll let you know.

2
Window / sf::Input and keypress repeat problem
« on: August 10, 2009, 04:58:14 pm »
I upgraded to version 1.5, but the problem is still there.

3
Window / sf::Input and keypress repeat problem
« on: August 10, 2009, 01:49:21 am »
I'm using SFML 1.4 on Ubuntu 9.04.

It seems when I use this code:
Code: [Select]
if (Input.IsKeyDown(sf::Key::A))
        OffsetDirection(1);
if (Input.IsKeyDown(sf::Key::D))
        OffsetDirection(-1);

and press and hold the 'D' or 'A' key, it calls OffsetDirection once, pauses, then calls it continuously as if I was holding the key down (which I am). But I don't want it to pause. Is this normal behavior for sf::Input? If it is, is there something I can use as an alternative that doesn't pause?

By the way, if I configure my computer to have no delay between key press repeating through System>Preferences>Keyboard, then this problem goes away. But I don't want to have to have anybody that wants to use my program to have to toggle their system preferences.

I've tried doing this as an alternative:

Code: [Select]

// outside the main loop
struct KeysPressed {
        bool A;
        bool B;
} KeysPressed;
...
// inside the main loop
if (Event.Type == sf::Event::KeyPressed)
{
        switch (Event.Key.Code)
        {
        case sf::Key::A:
                KeysPressed.A = true;
                break;
        case sf::Key::D:
                KeysPressed.D = true;
                break;
        default:
                break;
        }
}
else if (Event.Type == sf::Event::KeyReleased)
{
        switch (Event.Key.Code)
        {
        case sf::Key::A:
                KeysPressed.A = false;
                break;
        case sf::Key::D:
                KeysPressed.D = false;
                break;
        default:
                break;
        }
}

if (KeysPressed.A == true)
        OffsetDirection(1);
if (KeysPressed.D == true)
        OffsetDirection(-1);


But the problem persists.

Any help would be appreciated.

Thanks,
Jordy

EDIT: I deleted this from System and reposted here, because I realized I posted in the wrong section. Sorry.

4
Graphics / When an sf::Shape::SetPosition is called, what is moved?
« on: August 04, 2009, 03:04:30 pm »
Quote from: "Laurent"
SetPosition sets the position of the center point of the drawable, which is the local point (0, 0) by default (upper-left corner), but can be changed with SetCenter.


OK, thank you. I think I'll have to make my own SetCenter in that case to make sure that the center of the sf::Rect is also being changed.

5
Graphics / When an sf::Shape::SetPosition is called, what is moved?
« on: August 04, 2009, 04:46:00 am »
Center? Upper-left corner? I was wondering because I'm trying to get sf::Rect and sf::Shape to play nice, meaning they would both move at the same time. So I've implemented a class like this:
Shape.h
Code: [Select]
/*
 * Shape.h
 *
 *  Created on: Aug 3, 2009
 *      Author: Jordy
 */

#ifndef SHAPE_H_
#define SHAPE_H_

#include <algorithm>
#include <SFML/Graphics/Shape.hpp>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/System/Vector2.hpp>

namespace Solids
{

class Shape : public sf::Shape, public sf::Rect<float>
{
public:
Shape();
virtual ~Shape();

virtual void Move(float OffsetX, float OffsetY);
virtual void Move(const sf::Vector2f &Offset);
virtual void SetPosition(float OffsetX, float OffsetY);
virtual void SetPosition(const sf::Vector2f &Offset);

void SetSpeed(float NewSpeedX, float NewSpeedY);
void SetSpeedX(float NewSpeedX);
void SetSpeedY(float NewSpeedY);

void Update(float FrameTime=1);

static Shape Rectangle(float X, float Y, float Width, float Height);
static Shape Triangle(float P1X, float P1Y, float P2X, float P2Y, float P3X, float P3Y);

private:
float SpeedX, SpeedY;
};

}

#endif /* SHAPE_H_ */

Shape.cpp
Code: [Select]
/*
 * Shape.cpp
 *
 *  Created on: Aug 3, 2009
 *      Author: Jordy
 */

#include "Shape.h"

namespace Solids
{

Shape::Shape()
{
}

Shape::~Shape()
{
}

void Shape::Move(float OffsetX, float OffsetY)
{
sf::Shape::Move(OffsetX, OffsetY);
Offset(OffsetX, OffsetY);
}

void Shape::Move(const sf::Vector2f &Offset)
{
Move(Offset.x, Offset.y);
}


void Shape::SetSpeed(float NewSpeedX, float NewSpeedY)
{
SpeedX = NewSpeedX;
SpeedY = NewSpeedY;
}

void Shape::SetSpeedX(float NewSpeedX)
{
SpeedX = NewSpeedX;
}

void Shape::SetSpeedY(float NewSpeedY)
{
SpeedY = NewSpeedY;
}

void Shape::Update(float FrameTime)
{
Move(SpeedX * FrameTime, SpeedY * FrameTime);
}

Shape Shape::Rectangle(float X, float Y, float Width, float Height)
{
Shape Rect;

Rect.Left   = X;
Rect.Top    = Y;
Rect.Right  = Rect.Left + Width;
Rect.Bottom = Rect.Top + Height;

Rect.AddPoint(Rect.Left,  Rect.Top);
Rect.AddPoint(Rect.Right, Rect.Top);
Rect.AddPoint(Rect.Right, Rect.Bottom);
Rect.AddPoint(Rect.Left,  Rect.Bottom);

return Rect;
}

Shape Shape::Triangle(float P1X, float P1Y, float P2X, float P2Y, float P3X, float P3Y)
{
Shape Tri;

// Find boundaries of enclosing sf::Rect
Tri.Left   = std::min(std::min(P1X, P2X), P3X);
Tri.Right  = std::max(std::max(P1X, P2X), P3X);
Tri.Top    = std::min(std::min(P1Y, P2Y), P3Y);
Tri.Bottom = std::max(std::max(P1Y, P2Y), P3Y);

Tri.AddPoint(P1X, P1Y);
Tri.AddPoint(P2X, P2Y);
Tri.AddPoint(P3X, P3Y);

return Tri;
}

}


As you can see, I've implemented a Shape::Move method, but not the Shape::SetPosition method. This is because I'm not sure whether I should be doing this:
Code: [Select]
void Shape::SetPosition(float PosX, float PosY)
{
sf::Shape::SetPosition(PosX, PosY);

float Width  = GetWidth();
float Height = GetHeight();

Left   = PosX;
Top    = PosY;
Right  = Left + Width;
Bottom = Top + Height;
}

or this:
Code: [Select]
void Shape::SetPosition(float PosX, float PosY)
{
sf::Shape::SetPosition(PosX, PosY);

float Width  = GetWidth();
float Height = GetHeight();

Left   = PosX - Width / 2;
Top    = PosY - Height / 2;
Right  = Left + Width;
Bottom = Top  + Height;
}


Note that there may be other errors in my code. I haven't tested it thoroughly yet.

Thanks,
Jordy

6
Feature requests / pkg-config support
« on: August 03, 2009, 05:22:48 pm »
Quote from: "Laurent"
Easier in which way? What configure.ac are you talking about?


Anjuta (an IDE) uses autotools and makefiles to build projects. In order to build a project it has to know what it depends on. Libraries that use pkg-config are easy to add through project properties. Anything that doesn't use pkg-config needs to be added manually by editing the configure.ac file, which is a part of autoconf.

Anyways, I've resolved the problem by using a different IDE, since I'm too lazy to learn how to edit configure.ac files. But it would still be nice to have.

7
Feature requests / pkg-config support
« on: August 03, 2009, 05:05:44 am »
It would make it much easier to use SFML. It would mean I don't have to manually edit configure.ac, too.

What do you say?

8
Graphics / error: cannot convert 'const float' to 'sf::Rect<float>
« on: July 24, 2009, 05:39:48 pm »
Quote from: "Laurent"
No, that's just copying 4 floats. And to properly return a pointer, you would have to allocate it using new, and make the caller delete it. Which is ugly ;)


Ah, OK. Thanks. Besides some logic errors, it seems to be working now.

9
Graphics / error: cannot convert 'const float' to 'sf::Rect<float>
« on: July 24, 2009, 05:26:03 pm »
Quote from: "Laurent"
Forget about pointers
Code: [Select]
sf::Rect<float> DeriveRect(sf::Shape* shape)
{
    sf::Rect<float> rect(shape->GetPointPosition(0).x,
                          shape->GetPointPosition(0).y,
                          shape->GetPointPosition(3).x,
                          shape->GetPointPosition(3).y); /* The errors bring me to this line */
    return rect;
}


Doesn't that mean I have to pass around an entire sf::Rect? Isn't that slow?

10
Graphics / error: cannot convert 'const float' to 'sf::Rect<float>
« on: July 24, 2009, 05:10:06 pm »
I'm getting two errors when trying to compile this function:

Code: [Select]
sf::Rect<float>* DeriveRect(sf::Shape* shape)
{
    sf::Rect<float>* rect(shape->GetPointPosition(0).x,
                          shape->GetPointPosition(0).y,
                          shape->GetPointPosition(3).x,
                          shape->GetPointPosition(3).y); /* The errors bring me to this line */
    return rect;
}


The errors:
Code: [Select]
error: initializer expression list treated as compound expression
error: cannot convert 'const float' to 'sf::Rect<float>*' in initialization


I get the feeling that these are simple errors, but I could be wrong.

More information:
OS: Mac OS X 10.5
Compiler: g++
IDE: XCode 3
I have not called this function anywhere in the other parts of the program yet.
This is my first time with SFML.

Could anybody help me out with this?

Thanks,
Jordy

Pages: [1]