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

Pages: [1]
1
General / Collision with Rotating Objects
« on: February 18, 2014, 11:58:54 pm »
Does getGlobalBounds really work on rotating objects? I'm trying to detect a collision and currently the collision is setting off even when it's not intersecting the intended object. I'm on Ubuntu and believe I am running SFML 2.0. Below is a rough, off hand copy of the part of code in question, any responses as to why it might not be working would be greatly appreciated :D.

Also, if the code below for some reason doesn't compile in your compiler, remember it was a quick snippet put together to help explain my problem and that the actual code in question is error free so u can pretty much ignore any insignificant syntax errors lol.


#include <SFML/Graphics.hpp>
#include <iostream>

int main()
{
sf::RenderWindow window(sf::VideoMode(800,600),"");
bool play = true;

sf::RectangleShape rocks;
rocks.setSize(sf::Vector2f(800,50));
rocks.setFillColor(sf::Color(169,169,169));
rocks.setPosition(400,200);

sf::RectangleShape rect;
rocks.setSize(sf::Vector2f(50,50));
rocks.setFillColor(sf::Color::Black);
rocks.setPosition(350,250);

while(play == true){

rocks.rotate(1);

if(rocks.getGlobalBounds().intersects(rect.getGlobalBounds()) == true){
static int g = 0;
if (g <=5){
rect.setFillColor(sf::Color::Yellow);
g++;
}

if (g >5){
rect.setFillColor(sf::Color::Blue);
g++;
if (g >= 11) g = 0;
        }

window.draw(rect);
window.draw(rocks);

window.display();

}

}

2
General / Sprite Pointers
« on: July 12, 2013, 02:07:12 am »

I'm having trouble getting my sprite to move through a function. The way it works is I pass a pointer to the function with the location of the sprite and my rectangle shape, and then I check for collision in the if statement by dereferencing the variables. The problem with this is that it's giving me errors and won't let me dereference sprite1 and rect in the if condition. I know the function runs because eveytime a collision is made it displays "MOVE!", but unfortunately it doesn't move the sprite's y variable the opposite of gravity. Can anyone tell me what I'm doing wrong and how I can get this function to work properly? I would greatly appreciate it  ;D
void interaction (sf::Sprite* sprite1, sf::RectangleShape* rect){
       
       
       

        if(*sprite1.getGlobalBounds().intersects(*rect.getGlobalBounds()) == true){

                *rect.setFillColor(sf::Color::Black);

                *sprite1.move(0, -gravity);
                cout<<"MOVE!";

       
               
       

}
}

Pages: [1]