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

Pages: [1]
1
Window / Re: Drawing sprite while passing ByRef RenderWindow
« on: June 13, 2014, 02:23:32 pm »
The Bullet contructor is :

Bullet::Bullet(){
        this->MoveVelocity = 5;
        this->posX = 0;
        this->posY = 0;
        this->dead = true;

        if (this->bulletTexture.loadFromFile("img\\bullet\\bullet.png"))
        {
                this->bulletTexture.setSmooth(true);
                this->bulletTexture.setRepeated(true);

                this->bulletSprite.setTexture(this->bulletTexture);
                //this->bulletSprite.setScale(0.7F, 0.7F);
        }
}            


Bullet::Bullet(int x, int y){
        this->MoveVelocity = 5;
        this->posX = x;
        this->posY = y;
        this->dead = false;
        if (this->bulletTexture.loadFromFile("img\\bullet\\bullet.png"))
        {

                this->bulletTexture.setSmooth(true);
                this->bulletTexture.setRepeated(true);

                this->bulletSprite.setTexture(this->bulletTexture);
                this->bulletSprite.setColor(sf::Color::Red);
                //this->bulletSprite.setScale(0.7F, 0.7F);
        }
};

 
//BULLET piece of HEADER:

#ifndef Bullet_H
#define Bullet_H

class Bullet{
public:
        Bullet();
        Bullet(int x, int y);
        sf::Sprite retBullet();
        void Explode();
        void SetPos(int x, int y);
        bool isDead();
protected:
private:
        sf::Texture bulletTexture;
        sf::Sprite bulletSprite;

        int posX;
        int posY;

        int MoveVelocity;

        bool dead;
};
#endif

 

it is initialized and stored well, on debug i don't receive error  on texture or on sprite it seems that the procedure draws it correctly but i don't see it


P.S.
@Jesper Juhl   @select_this  I am a C# programmer

2
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;
};
 


3
Window / Re: Detect multiple keypress
« on: June 10, 2014, 11:19:26 am »
@Jesper Juhl
Thanks for help it's what I need. I want to choose your answer as Solved answer and I don't know how..
Thanks.

4
Window / Re: Detect multiple keypress
« on: June 09, 2014, 06:06:56 pm »
Use a couple of bool variables to hold state information about keys.
So, when you get the event that down is pressed, set "down_pressed = true;" and when it is released set it to false.
Do the same for the other keys. Then to check if you are going down and right, check "if (down_pressed && right_pressed) { down_right_do_stuff(); }" etc.

I can't do that because in if block (event.type == sf::Event::KeyPressed) it never catch the right key press, it only catch the down key press when i hold both right and down keys, so a bool is useless here.
I hope I understand what you've suggested to me.
P.S. Sorry for my poor english

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