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

Pages: [1]
1
General / messing up with key events <_<
« on: January 29, 2012, 02:27:09 pm »
Hi guys, what am I doing wrong?

Code: [Select]
               switch(Event.KeyEvent.Code)
                {
                    case sf::Key::Code::Num1:
                    {
                        SelectedColor=Black;
                        break;
                    }
                    case sf::Key::Code::Num2:
                    {
                        SelectedColor=Blue;
                        break;
                    }
                }


compiles with this error:
Quote
invalid use of ‘struct sf::Event::KeyEvent’


The Event object is obviously sf::Event Event..

2
Window / [SFML 1.6] Mouse tracking independently?
« on: January 02, 2012, 10:15:47 pm »
Is there any way of tracking mouse almost (while it's in window bounds) permanently?
Not only when it's moved but also when it just stay in the same position.

The code like this gives weird behavior when the mouse not moved, but clicked (the coordinates just jumping, or something like that, to the opposite side for a second).

Code: [Select]
sf::Vector2f MousePosition(Event.MouseMove.X, Event.MouseMove.Y);
The_Tank.GetGun().AimAt(MousePosition);


Any ideas?
The newb(me) forehand thank you. :)

P.S. Also Is there any person interested in 2D top-down view game development? I'm trying myself at that, and would be fine to see another person who can assist me or at least give a piece of advice.

3
Graphics / Which function to overload in class derived from sf::Sprite?
« on: January 02, 2012, 05:51:49 pm »
Hi all.
Which function must I overload in my class derived from sf::Sprite to keep that drawing behavior for RenderWindow::Draw() function just like the same as for Sprite. you know...

I mean how to keep behavior of my class like that
Code: [Select]
sf::RenderWindow App(/*init there*/);
sf::Sprite MySprite(); //let's count this sprite as fully initialized

App.Draw(MySprite);

But for my derived class.
To make the discussion more objective here is my class(es) code:

Code: [Select]
class Gun : public sf::Sprite
{
 public:
    Gun(const sf::Vector2f& Position, float Rotation=0, std::string texture=Options::Gun::Texture)
    {
        Texture.LoadFromFile(texture);
        sf::Sprite::SetImage(Texture);
        sf::Sprite::SetPosition(Position);
        sf::Sprite::SetCenter(Options::Gun::Center);
        sf::Sprite::SetRotation(Rotation);
    }
    void AimAt(const sf::Vector2f& Mouse)
    {
        sf::Vector2f Position = sf::Sprite::GetPosition();
        float angle = std::atan2(Mouse.y - Position.y, Mouse.x - Position.x)*rad;  // угол наклона

        sf::Sprite::SetRotation(270 - angle);
    }
 private:
    sf::Image Texture;
    float VecLength(const sf::Vector2f& first, const sf::Vector2f& second)
    {
        return std::sqrt (std::pow( (second.x-first.x) ,2) + std::pow( (second.y-first.y) ,2));
    }
};

class Tank : public sf::Sprite
{
 public:
    Tank(const sf::Vector2f& Position, float Rotation=0, std::string texture=Options::Tank::Texture) : Cannon(Options::Tank::GunPlace, Rotation)
    {
        Texture.LoadFromFile(texture);
        sf::Sprite::SetImage(Texture);
        sf::Sprite::SetPosition(Position);
        sf::Vector2f PureCenter(Texture.GetWidth()/2 , Texture.GetHeight()/2);
        sf::Sprite::SetCenter(PureCenter);
        sf::Sprite::SetRotation(Rotation);
    }
    Gun& GetGun(void)
    {
        return Cannon;
    }
    void Simulate(const sf::Vector2f& Mouse)
    {

    }
 private:
    Gun Cannon;
    sf::Image Texture;
};


As you can see I need my Tank class to Draw both itself's sprite and the cannon's sprite at the request of drawning the Tank sprite...

So which functions and how must I overload?
I guess it's some of Sprite::Draw() or Sprite::Render() functions.

Forehand thank you. And sorry for my bad English =(

Pages: [1]
anything