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

Pages: [1]
1
Window / Drawing sprite while passing ByRef RenderWindow
« on: June 12, 2014, 10:00:47 am »
The problem is that if I pass the RenderWindow ByRef to function I don't see the bullet but if I create the bullet in main.cpp I see the bullet, on debug i see that the programs enter in BULLET DRAWING and generates NO error, here is the piece of code:
in Main I have
while (window.isOpen())
        {
                ControlKeyPress(&window, &event);  

                window.clear();
                window.draw(game.getBACKSprite());
                window.draw(me.retPlane());

                me.DrawBullets(&window);
 
                window.display();
        }
 
The draw function is :
void MyPlayer::DrawBullets(sf::RenderWindow *window){
        int usB = 0;
        for (int i = 0; i < 6; i++){
                if (!this->bullet[i].isDead()){
                        window->draw(this->bullet[i].retBullet());  // BULLET DRAWING
                        usB++;
                }
        }
        this->usingBullet = usB;
};

 
sf::Sprite Bullet::retBullet(){
        if (!this->dead){
                if (this->posX <= 800 - this->MoveVelocity)
                        this->posX += MoveVelocity;
                else
                        this->dead = true;

                this->bulletSprite.setPosition((float)this->posX, (float)this->posY);
        }
        return this->bulletSprite;
};
 


2
Window / Detect multiple keypress
« on: June 09, 2014, 02:03:32 pm »
Hi,
I want to detect multiple keypress like downArrow and RightArrow I have the code:
 if (event.type == sf::Event::KeyPressed)
                        {
                                if (event.key.code == sf::Keyboard::Key::Escape)
                                        window.close();

                                if (event.key.code == sf::Keyboard::Key::Right)
                                        me.MoveXAxis(1);
                                else if (event.key.code == sf::Keyboard::Key::Left)
                                        me.MoveXAxis(-1);

                                if (event.key.code == sf::Keyboard::Key::Up)
                                        me.MoveYAxis(-1);
                                else if (event.key.code == sf::Keyboard::Key::Down)
                                        me.MoveYAxis(1);
                        }
 

As you can see up-down and left-right are in different IF blocks but if I press Down-Right it only goes on DOWN how can I intercept the right key press ? so the plane can move on diagonal...
Thanks.

Pages: [1]
anything