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:
Can someone help? Thanks in advance!
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"[/quote]
#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
Player:
Vector2f Player::PlayerPosition()
{
return shape.getPosition();
}
Can someone help? Thanks in advance!