Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Setting texture on sprite not working  (Read 960 times)

0 Members and 1 Guest are viewing this topic.

rageeph

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Setting texture on sprite not working
« on: October 14, 2019, 04:44:17 am »
I created a header file (level.h) which has a constructor with a texture parameter called 'ImagePath'. I am then saying what it will do in the level.cpp file which is to apply the 'ImagePath' texture to a sprite. I am then getting an error:

level.cpp: In constructor ‘Tile::Tile(const sf::Texture&)’:
level.cpp:5:22: error: no match for call to ‘(sf::Sprite) (const sf::Texture&)’
    5 |  TileSprite(ImagePath);

Here is my code:

level.h
#ifndef LEVEL_H
#define LEVEL_H

#include<SFML/Graphics.hpp>

class Tile: public sf::Drawable {

   public:   
   Tile(const sf::Texture& ImagePath);   
   virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;   
   
   
   private:
         
      sf::Sprite TileSprite;
};

#endif


level.cpp
#include "level.h"

Tile::Tile(const sf::Texture& ImagePath) {
   
   TileSprite(ImagePath);      

}


void Tile::draw(sf::RenderTarget& target, sf::RenderStates states) const {


   //Apply transform here
      
   target.draw(TileSprite,states);
   


}

G.

  • Hero Member
  • *****
  • Posts: 1592
    • View Profile
Re: Setting texture on sprite not working
« Reply #1 on: October 14, 2019, 06:20:42 am »
C++. That's not how it works. Use the initialization list to initialize your sprite.

rageeph

  • Newbie
  • *
  • Posts: 2
    • View Profile
    • Email
Re: Setting texture on sprite not working
« Reply #2 on: October 14, 2019, 03:26:21 pm »
ah, thank you.
« Last Edit: October 15, 2019, 04:51:33 pm by rageeph »