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

Pages: 1 [2] 3 4
16
Graphics / Collision with FloatRect
« on: February 26, 2012, 02:30:35 pm »
I'm having difficulties with getting 2 FloatRects to react to each other.

Can someone write a simple sample showing how to to del with this? Having 2 FloatRects on the screen (displayed with RectangleShapes), one of them movable with WASD keys, the other stationary. The movable one needs to collide with the stationary one and not be able to move through it.

This would be very helpful so I can inspect how this is handled.

Thanks

17
Graphics / Collision with FloatRect
« on: February 24, 2012, 02:33:17 pm »
Thanks everyone, all the answer were insightful.

I do have another question though. Should my main player's object be checking for collisions with all intrects in my scene? Or should all colliderable objects be checking for collisions with the main player?

If it's the former then what happens if I have 500+ colliderable "tiles" in my scene? Every frame my main player would have to loop around ALL the tiles and do it's collision checking.

How do people go about doings this?

18
Graphics / Collision with FloatRect
« on: February 21, 2012, 05:42:48 pm »
Sometimes because my movement is timed by deltatime the box doesn't move by 1px and could intersect by 3-4 pixels.

19
Graphics / Collision with FloatRect
« on: February 21, 2012, 01:16:09 pm »
Hello, I need some advice on collisions. I have setup 2 RectangleShapes and setup up 2 FloatRect around them. One of the shapes is moved around using this code

Code: [Select]

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::W )) {
      this->velocity.y -= this->deltatime;
   }

   if (sf::Keyboard::IsKeyPressed( sf::Keyboard::S )) {
      this->velocity.y += this->deltatime;
   }

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::A )) {
      this->velocity.x -= this->deltatime;
   }

   if (sf::Keyboard::IsKeyPressed( sf::Keyboard::D )) {
      this->velocity.x += this->deltatime;
   }


(Thanks Laurent!).

The FloatRect also move with the moveable box. I've modified the code so that when the 2 boxes intersect the movable box is no longer movable in that direction. The problem is that this code is only run once the boxes intersect, meaning I'm already inside the box and cannot get out.

This must be an obvious issue, but how would one go about fixing it?

20
Window / Moving a shape along both axis using sf::Vector2f
« on: February 20, 2012, 05:13:20 pm »
Hello, I read here a couple of days ago about using a Vector2f to process my movement, this seemed an obvious thing once I read it. However, I'm getting a little confused by it.

I have an Update() method which gets run every frame, I also have a ManageInput() method as well, which also get's run every frame.

The Update() method also runs this code

Code: [Select]

this->shape.Move( this->velocity );


this->velocity is obviously the Vector2f in question. The ManageInput() method is just a series of IF statements checking for W,A,S and D keyPresses. Here's a sample of this code

Code: [Select]

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::W )) {
this->velocity = sf::Vector2f(0, -1) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::S )) {
this->velocity = sf::Vector2f(0, 1) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::A )) {
this->velocity = sf::Vector2f(-1, 0) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::D )) {
this->velocity = sf::Vector2f(1, 0) * this->deltatime;
}


However, using this code I can only move along 1 axis at a time.

If I modify this code to look like this

Code: [Select]

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::W )) {
this->shape.Move(sf::Vector2f(0, -1)) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::S )) {
this->shape.Move(sf::Vector2f(0, 1)) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::A )) {
this->shape.Move(sf::Vector2f(-1, 0)) * this->deltatime;
}

if (sf::Keyboard::IsKeyPressed( sf::Keyboard::D )) {
this->shape.Move(sf::Vector2f(1, 0)) * this->deltatime;
}


It works as expected, allows me to both on both axis. How would I modify the top code to work as I want it to.

21
Window / Can i pass a RenderWindow to another class
« on: February 16, 2012, 11:57:19 pm »
Ok, that makes sense. How would I get that to work in something like this

Code: [Select]


#include <SFML/Graphics.hpp>

class MyClass {
public:
    MyClass(sf::RenderWindow& window);
    void Draw();
private:
    sf::RenderWindow& m_window;
    sf::Text m_text;
};

MyClass::MyClass(sf::RenderWindow& window){
this->m_window = window;
this->m_text = sf::Text("Hello World");
}

void MyClass::Draw(){
m_window.Draw(m_text);
}



int main(int argc, char* argv[])
{
    sf::RenderWindow window(sf::VideoMode(800, 600), "Test");

    MyClass myObject(window);

    while(window.IsOpen())
    {
        sf::Event ev;
        while(window.PollEvent(ev))
        {
            if(ev.Type == sf::Event::Closed)
                window.Close();
        }

        window.Clear();
        myObject.Draw();
        window.Display();
    }

    return 0;
}


22
Window / Can i pass a RenderWindow to another class
« on: February 16, 2012, 09:13:06 pm »
Could you expand that. I'm defining sf::RenderWindow& win in the my class, and when I try to set it to a RenderWindow reference I'm getting a "noncopyable" error.

23
Window / Can i pass a RenderWindow to another class
« on: February 16, 2012, 02:24:57 pm »
Can I pass a RenderWindow object to another class and use it's method (like .Draw()) inside the other class, rather having to run Draw a million times in my main.cpp file?

24
Graphics / checking circular collisions
« on: February 15, 2012, 08:19:11 pm »
Hello, I know I can use IntRect() which have some decent methods for working out collisions between them. How would I go about doing this with circular shapes?

25
General / Key press.
« on: February 13, 2012, 12:42:14 pm »
Code: [Select]

w_pressed = false

if w is held
if w_pressed is false
do something while W is pressed (not held)
w_pressed = true
else
do something while W is held
else
w_pressed = false

26
Graphics / What's a decent file size for a single sprite sheet?
« on: February 05, 2012, 12:00:16 am »
As the subject implies, what's a decent file size for single sprite sheet? kbs? mbs? What filesize should I not be exceeding?

27
System / IsKeyPressed seems to not fire all the time.
« on: January 27, 2012, 09:29:37 am »
Thanks for the reply, that makes sense! Didn't realise it was a limitation of my keyboard.

28
System / IsKeyPressed seems to not fire all the time.
« on: January 26, 2012, 11:31:08 pm »
Hello, I have a strange thing going on. I've wrote this block of code which monitors the W,A,S and D keys. If the key is up then the state is set to 0, if it's pressed it's 1 and if it's held it's 2. Now, the problem comes if I press all 4 keys at the same time, none of the states change. Also if I hold the keys one by one only 3 of the 4 states change.

If you run the code below and open up your console it logs the keys every frame, then try pressing the keys and you'll notice the issues.

Code: [Select]

#include <SFML/Graphics.hpp>

int main () {

sf::RenderWindow window(sf::VideoMode(640, 480, 32), "SFML Key Test");
window.SetFramerateLimit(60);

bool wKey;
bool aKey;
bool sKey;
bool dKey;

bool wHeld;
bool aHeld;
bool sHeld;
bool dHeld;

int wState;
int aState;
int sState;
int dState;


while (window.IsOpened()){
sf::Event event;
        while (window.PollEvent(event)){
            if (event.Type == sf::Event::Closed){
                window.Close();
}


}


window.Clear();

wKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::W);

if (wKey) {
if (!wHeld) {
wState = 1;
wHeld=true;
}else {
wState = 2;
}
}else {
wHeld = false;
wState = 0;
}

dKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::D);

if (dKey) {
if (!dHeld) {
dState = 1;
dHeld=true;
}else {
dState = 2;
}
}else {
dHeld = false;
dState = 0;
}

sKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::S);

if (sKey) {
if (!sHeld) {
sState = 1;
sHeld=true;
}else {
sState = 2;
}
}else {
sHeld = false;
sState = 0;
}

aKey = sf::Keyboard::IsKeyPressed(sf::Keyboard::A);

if (aKey) {
if (!aHeld) {
aState = 1;
aHeld=true;
}else {
aState = 2;
}
}else {
aHeld = false;
aState = 0;
}

printf("W:%i A:%i S:%i D:%i\n", wState, aState, sState, dState);

window.Display();

}

return EXIT_SUCCESS;

}


29
Window / logging a series of key presses
« on: January 25, 2012, 05:37:39 pm »
Hay, I'm wondering what peoples thoughts are solving my problem.
 I want to develop a system that records a series of button presses.
These act like a "combo" on many platform games.
Say i press the keys L,O,P very quickly, that would preform a certain action.
 These 'combos' are going to be stored in an array like int[LKEYCODE, OKEYCODE, PKEYCODE].
However I want to these to only match if the time between each key press is < 0.5 seconds.

How would one go about creating something like this?

30
System / Only want a function to get called once on a keyDown.
« on: January 24, 2012, 09:13:40 pm »
I've got something like this going on

Code: [Select]


Player {
public:
    sf::Window win;
    void SetWindow(sf::Window window);
}

void Player::SetWindow(sf::Window window){
    this->win = window;
}



But it's telling me it's 'Not copyable'

Pages: 1 [2] 3 4