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

Pages: [1] 2 3 4
1
Graphics / Re: Setting points in sf::VertexArray relative to sprite
« on: July 28, 2014, 07:19:58 pm »
Woops, I never think about the documentation for some reased!

Anyway, thank you!

2
Graphics / Re: Setting points in sf::VertexArray relative to sprite
« on: July 28, 2014, 01:54:41 am »
Thanks!

I just tried that but I get errors. 

IntelliSense: no operator "*" matches these operands operand types are: sf::Vector2f * const sf::Transform   

3
Graphics / Setting points in sf::VertexArray relative to sprite
« on: July 27, 2014, 01:49:52 am »
Hi again everybody,

After more experimenting with VertexArrays, I want to set each vertex (2 vertices in the array) to one end of a sprite.  This wouldn't be that bad, except that the sprite rotates.  I might not have done too great of a job explaining what I mean, so here's a visual representation:



How can I set each vertex to stay at that end of the sprite?

Sorry for all the questions about this, I'm still learning more advanced topics of C++ and SFML, but I figured that a good way to learn would be pushing myself with harder projects, so I'm not entirely sure how to solve all the problems I run across.

Thanks for all the help!

4
Ah, sorry about that, pressed and isPressed are the same variable, that was just a typo.  I tried assigning points[1] to like this:

void Player::update(sf::RenderWindow& window, sf::Time dt)
{
        mousePos = sf::Mouse::getPosition(window);

        if (pressed)
                points[0] = sf::Vector2f(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
        if (!pressed)
                points[1] = sf::Vector2f(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));
}

But I quickly realized that doesn't work.  At this point I'm out of ideas though. =\

5
Graphics / Drawing a line segment with end points set by mouse click
« on: July 24, 2014, 06:35:10 am »
Hi everybody,

I did some quick googling and I think I found how to draw the line successfully, but I have a problem setting the start and end points of the line.  When I use the code that I have now, the start point is the top left corner of the screen, and it ends wherever I click.  How can I get it to start where the first click is and end at the second click? 

This is what I have now:
Player::Player()
        : isPressed(false)
{
        points[0].color = sf::Color::Red;
        points[1].color = sf::Color::Red;
}

void Player::handleInput(sf::Event event)
{
        switch (event.type)
        {
        case sf::Event::MouseButtonPressed:
                pressed = true;
                std::cout << std::to_string(pressed) << std::endl;
                break;
        case sf::Event::MouseButtonReleased:
                pressed = false;
                std::cout << std::to_string(pressed) << std::endl;
                break;
        }
}

void Player::update(sf::RenderWindow& window, sf::Time dt)
{
        mousePos = sf::Mouse::getPosition(window);

        if (isPressed)
                points[0] = sf::Vector2f(static_cast<float>(mousePos.x), static_cast<float>(mousePos.y));

        std::cout << points[0].position.x << std::endl;
}

void Player::render(sf::RenderWindow& window)
{
        window.draw(points, 2, sf::Lines);
}

Thank you for the help!

6
SFML projects / Re: Marvin - A Desktop Platformer
« on: July 08, 2014, 02:05:41 am »
Awesome!  Do you ever plan on releasing the source code?

7
SFML projects / Re: Marvin - A Desktop Platformer
« on: July 07, 2014, 01:00:43 am »
Just an observation/opinion.

I think the ground on the menu screen is moving a bit too fast, I noticed that it looks like it's flickering instead of moving, so you may want to slow that down a bit just for aesthetic purposes.

Either way the game is really fun!  I was impressed at the graphics, did you make the art or did somebody else, because they're fantastic.

8
That's what I love about programming, there's always a better way to solve a problem.

Thanks, I was over-thinking it again.

9
General / Moving the sf::View at the same rate that the player moves
« on: July 06, 2014, 11:27:21 pm »
I want to make a sidescroller, but I ran into the problem where it seems unnecessarily complicated to get the camera to move at the same rate as the player.  If I do this:

view.move(sf::Vector2f(Speed, 0.f));

The camera moves significantly faster than the player, how can I match them up?

10
SFML projects / Re: The 8-Bit Encounter - My Open-World 2D Game Demo
« on: June 23, 2014, 09:42:29 pm »
Is there a particular reason that the music fades whenever you collide with something?  It got pretty irritating after a little bit, but I'm not sure if it's a glitch or you did that on purpose.

11
SFML projects / Re: Zeran's Folly
« on: June 23, 2014, 08:29:08 pm »
Wow!  That looks like it could be a great app (I would absolutely download it if it was).

Oh, and if you don't mind me asking, what did you use to make the maps?  Was it TiledMapEditor or your own level editor?

12
General / Re: Methods for Collsion Detection
« on: June 22, 2014, 01:42:02 am »
Ok, so I implemented the bounding box collision system and it works, but I want to split it up so that I can tell whether the ball collides with the top or bottom half of the paddle.  This is the boundingboxtest function, how can i modify it to check if it's colliding with the top or bottom half?

int boundingBoxTest(const sf::RectangleShape& object1, const sf::RectangleShape& object2)
        {
                // 0 = not colliding
                // 1 = colliding with top
                // 2 = colliding with bottom

                BoundingBox obj1 = object1;
                BoundingBox obj2 = object2;

                // Create the four distinct axes that are perpindicular to the edjes of the two rectangles
                sf::Vector2f axes[4] =
                {
                        sf::Vector2f(obj1.points[1].x - obj1.points[0].x, obj1.points[1].y - obj1.points[0].y),
                        sf::Vector2f(obj1.points[1].x - obj1.points[2].x, obj1.points[1].y - obj1.points[2].y),
                        sf::Vector2f(obj2.points[0].x - obj2.points[3].x, obj2.points[0].y - obj2.points[3].y),
                        sf::Vector2f(obj2.points[0].x - obj2.points[1].x, obj2.points[0].y - obj2.points[1].x)
                };

                for (int i = 0; i < 4; i++)
                {
                        float minOBJ1, maxOBJ1, minOBJ2, maxOBJ2;

                        obj1.projectOntoAxis(axes[i], minOBJ1, maxOBJ1);
                        obj2.projectOntoAxis(axes[i], minOBJ2, maxOBJ2);

                        if (!((minOBJ2 <= maxOBJ1) && (maxOBJ2 >= minOBJ1)))
                                return 0;
                }

                return 1;
        }

13
General / Re: Methods for Collsion Detection
« on: June 19, 2014, 10:08:45 pm »
Quick question actually, how do I use this?

sf::Vector2f pos = Object.TransformToGlobal(sf::Vector2f(0, 0));

I can't find a transformToGlobal function anywhere.  Am I missing something?

14
General / Re: Methods for Collsion Detection
« on: June 19, 2014, 08:46:13 pm »
Awesome, that's just what I needed!

Thanks.

15
General / Methods for Collsion Detection
« on: June 19, 2014, 08:37:24 pm »
Hi everybody.

Right now I'm just working on a pong game.  So far I have the ball bouncing off the top and bottom of the screen implemented, along with scoring for the player and opponent.  But I'm having some trouble with the paddle collision.  I tried this:

if (ball.getPosition().x > player.getPosition().x &&
                ball.getPosition().x < (player.getPosition().x + PADDLE_WIDTH) &&
                ball.getPosition().y > player.getPosition().y &&
                ball.getPosition().y < (player.getPosition().y + PADDLE_HEIGHT))
        {
                ballDirX = 1;
                if (ballDirY == 1)
                        ballDirY = -1;
                else
                        ballDirY = 1;
        }

But I realized that this only checks if ONE POINT on the ball is colliding with the player's paddle, which causes problems when the player only hits part of the ball that isn't being checked for collisions.  How could I implement a collision system that doesn't have these problems?

Pages: [1] 2 3 4