### 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 - Flaze07

Pages: 1 ... 3 4 [5]
61
##### Graphics / Re: Movement
« on: May 05, 2017, 05:33:23 pm »
ayy, it works thanks man

62
##### Graphics / Re: Movement
« on: May 05, 2017, 05:17:45 pm »
Interestingly, someone else just made a post right before you trying to solve the same problem. Are you perhaps working together?

Your problem is that Rect.getRotation() returns the angle in degrees, but sin and cos expect the angle to be in radians.

nope..we are not working together..

I see.. so it expects radians

edit : also does the location of the center affects the movement (I have the origin in the center...(most likely))

63
##### Graphics / Re: How can i slow down the rate my projectiles fire.
« on: May 05, 2017, 04:40:31 pm »
well, why not use CoolDown thing...

64
##### Graphics / Movement
« on: May 05, 2017, 04:37:53 pm »
hey, uh..there's a little problem here.. I'm trying to make experiment with movement based on angle..(only 0 works fine)

I wonder what's wrong..
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include <cmath>
#include <iostream>

class User
{
private :
sf::RectangleShape Rect;
const float speed;
const float rotation;
public :
User() :
speed(0.8),
rotation(0.2)
{
Rect.setSize(sf::Vector2f(38, 17));
Rect.setOrigin(Rect.getSize().x / 2, Rect.getSize().y / 2);
Rect.move(Rect.getSize().x / 2, Rect.getSize().y / 2);
}
sf::Shape &getShape()
{
return Rect;
}
void Action(const sf::RenderWindow &window)
{
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right))
{
Rect.rotate(rotation);
}
else if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left))
{
Rect.rotate(-(rotation));
}
if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up))
{
sf::Vector2f Direction;
Direction.x = speed * std::cos(Rect.getRotation());
Direction.y = speed * std::sin(Rect.getRotation());
Rect.move(Direction);
}
check(window);
}
void check(const sf::RenderWindow &window)
{
if (Rect.getPosition().x < 0) Rect.move(speed, 0);
else if (Rect.getPosition().x > window.getSize().x) Rect.move(-(speed), 0);
if (Rect.getPosition().y < 0) Rect.move(0, speed);
else if (Rect.getPosition().y > window.getSize().y) Rect.move(0, -(speed));
}
};

int main()
{
sf::RenderWindow window(sf::VideoMode(900, 600), "some window");
User user;
while (window.isOpen())
{
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed) window.close();
}
user.Action(window);
window.clear(sf::Color::Black);
window.draw(user.getShape());
window.display();
std::cout << user.getShape().getRotation() << std::endl;
}
}

Pages: 1 ... 3 4 [5]