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

Pages: [1]
1
Graphics / Re: Rendering an instanced class object
« on: April 02, 2013, 11:41:37 pm »
Right, I'll leave out this until I get a bit better then...

Thanks for the reply!

2
Graphics / Rendering an instanced class object
« on: April 02, 2013, 11:23:53 pm »
Hi there,

I'm trying to create an instanced class object (I don't know if it even works) when the mouse is clicked, so therefore I'll be able to shoot multiple bullets. I'm new to classes and hardly understand it, so please don't be too harsh! ;)

This is the bullet class:
        class Bullet
        {
        public:

                sf::Sprite sprite;
                float xPosition;
                float yPosition;
                float xVelocity;
                float yVelocity;

                void Bullet::Shape()
                {
                        sf::RectangleShape bullet;
                        bullet.setSize(sf::Vector2f(1,1));
                        bullet.setFillColor(sf::Color::Black);
                        bullet.setPosition(xPosition, yPosition);
                        bullet.move(xVelocity, yVelocity);
                }
        };
        Bullet bullet[10];

Then this actually shoots it (well, it should do but I haven't got to testing that yet...)
//Shooting
                if (leftClick == true)
                {                      
                        //Get bullet position  
                        bulletOpposite = sin(gunRotationAngle * PI/180) * 5;
                        bulletAdjacent = cos(gunRotationAngle * PI/180) * 5;

                        //Set position
                        bullet[bulletNumber].xPosition = gun.getPosition().x + bulletAdjacent;
                        bullet[bulletNumber].yPosition = gun.getPosition().y + bulletOpposite;

                        //Set velocity
                        bullet[bulletNumber].xVelocity = bulletAdjacent;
                        bullet[bulletNumber].yVelocity = bulletOpposite;

                        bulletNumber += 1;

                        leftClick = false;
                }

I've calculated the location of where the bullet is and the velocity from the angle of the gun (which is a 5 x 1 pixel 'object').

Then I try to render it...
window.draw(bullet[bulletNumber]);

But get an error: Error   5   error C2664: 'void sf::RenderTarget::draw(const sf::Drawable &,const sf::RenderStates &)' : cannot convert parameter 1 from 'Bullet [10]' to 'const sf::Drawable &'

Again, I don't totally understand classes, but I appreciate anybody's help!

Thanks! :D

Pages: [1]
anything