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

Pages: [1]
1
General / Re: Collision with Rotating Objects
« on: February 19, 2014, 04:58:35 am »
Yeah, I thought I would end up having to do it myself *sigh*... thanks for the response though, it's greatly appreciated ;D

2
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();

}

}

3
Try posting both window.draw () and window.display in the scope of the editor mode function after you redefine the colors of the rect and test as opposed to just in the game loop and report what happens.Also try it again and comment out the clear button in your game loop and also report what happens. Can you also post the initialization of your list?  I dont yet have a solution for the problem,  so im just trying to get a better feel of what the problem might be.

4
Here's another good site I'm currently using to pick up some things ----> udacity.com

5
General / Re: Sprite Pointers
« on: July 12, 2013, 02:26:36 am »
Turns out I just called the function with the wrong paramaters by accident :P Thanks for the response though  :D I also figured out that the variables were address locations (or so I think?), so this ended up working for me :




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!";

       
               
       

}
}

 

calling it like this
        interaction(sprite1,rect);                            

6
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]