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

Pages: [1]
1
Graphics / getPosition not getting updated in other class
« on: March 15, 2021, 12:26:57 pm »
Hello,

i need to create bullet object based on player position.

I have 2 classes, Bullet and Player and i want to copy player.getPosition() to bullet.setPosition()

Problem is that player.getPosition() is not updating when moving, it have only value that was initiated when Player object is created.


Bullet class:
Quote
#include "Bullet.h"
#include "Player.h"
Bullet a;
Bullet::Bullet(float t_Width, float t_High)
{
   
   shape.setFillColor(Color(237, 9, 9));
   shape.setSize({ t_Width, t_High });
   shape.setOrigin(t_Width / 2.f, t_High / 2.f);
   
}



void Bullet::update()
{
   getPlayerPosition();
   

   if (sf::Keyboard::isKeyPressed(sf::Keyboard::Space))
   {
      
      shape.move(velocity);
      shape.setPosition(getPlayerPosition().x,getPlayerPosition().y);

   }

}

Vector2f Bullet::getPlayerPosition()
{
   return a.PlayerPosition();
}
[/quote]

Quote
Player:

Vector2f Player::PlayerPosition()
{
   return shape.getPosition();
}


Can someone help? Thanks in advance!


Pages: [1]