1
Graphics / Why sprite not showing up after i use sf::setOrigin
« on: September 25, 2022, 09:28:17 am »
why
here code:
here code:
#pragma once
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Animation.hpp"
namespace p_1{
class Player{
public:
Player(sf::Texture &b, sf::Texture &p_t2_, sf::Vector2u img_count,
float switch_time, float speed) : animation(&p_t2_, img_count, switch_time){
sprite.setTexture(p_t2_);
sprite.setScale(sf::Vector2f(2.f, 2.f));
sprite.setPosition(640/2, 480/2);
this->speed = speed;
this->face_r = true;
const sf::Vector2f spriteSize(sprite.getGlobalBounds().width/2.f, sprite.getGlobalBounds().height/2.f);
sf::Vector2u size = b.getSize();
//sprite.setOrigin(size.x / 2, size.y / 2);
}
virtual ~Player() = default;
private:
sf::Sprite sprite;
unsigned int row;
int speed=0.0f;
bool face_r=false;
Animation animation;
public:
void draw(sf::RenderWindow& window);
void update(float dt);
sf::Vector2f getPosition(){
return sprite.getPosition();
}
};
}
#include <SFML/Graphics.hpp>
#include <iostream>
#include "Animation.hpp"
namespace p_1{
class Player{
public:
Player(sf::Texture &b, sf::Texture &p_t2_, sf::Vector2u img_count,
float switch_time, float speed) : animation(&p_t2_, img_count, switch_time){
sprite.setTexture(p_t2_);
sprite.setScale(sf::Vector2f(2.f, 2.f));
sprite.setPosition(640/2, 480/2);
this->speed = speed;
this->face_r = true;
const sf::Vector2f spriteSize(sprite.getGlobalBounds().width/2.f, sprite.getGlobalBounds().height/2.f);
sf::Vector2u size = b.getSize();
//sprite.setOrigin(size.x / 2, size.y / 2);
}
virtual ~Player() = default;
private:
sf::Sprite sprite;
unsigned int row;
int speed=0.0f;
bool face_r=false;
Animation animation;
public:
void draw(sf::RenderWindow& window);
void update(float dt);
sf::Vector2f getPosition(){
return sprite.getPosition();
}
};
}