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

Author Topic: I need help with my own class implementation  (Read 883 times)

0 Members and 1 Guest are viewing this topic.

Ladislav

  • Newbie
  • *
  • Posts: 1
    • View Profile
    • Email
I need help with my own class implementation
« on: January 12, 2019, 12:37:54 pm »
Good day, I´m relatively new to using SFML, I watched a ton of diferent videos for class and using it with SFML, I get the idea how it works but for some reason it wont work and I have no idea why, I made 3 classes and all of them I comented out and used meanwhile some copy-paste ones as  replacment.

my header file :
#pragma once
#include <SFML/Graphics.hpp>
class MyMap
{
public:
   MyMap(std::string &MapName, unsigned int width, unsigned int height, const int* tiles,
      unsigned int StartX, unsigned int StartY, unsigned int SizeOfOne, const int NumberofObjects);
   ~MyMap();

   /*void draw(sf::RenderWindow &window);*/
private:
   sf::Sprite sprite;
   
};

My cpp:
#include "MyMap.h"
#include "Resource.h"


MyMap::MyMap(std::string &MapName, unsigned int width, unsigned int height,const int* tiles,
   unsigned int StartX,unsigned int StartY,unsigned int SizeOfOne,const int NumberofObjects)
{
   sf::Sprite Osprite[10],OverlayMapS[2];
   sprite.setTexture(Resource::getTexture(MapName));
   for (int a = 0; a <= NumberofObjects; a++)
   {
      Osprite[a] = sprite;
    Osprite[a].setTextureRect(sf::IntRect(StartX, SizeOfOne, StartY, SizeOfOne));
    Osprite[a].setOrigin(SizeOfOne/2, SizeOfOne/2);
   }

   for (unsigned int i = 0; i < width; i++)
   {
      for (unsigned int j = 0; j < height; j++)
      {
         int curentObject = tiles[i + j * width];

         Osprite[curentObject].setPosition(i*SizeOfOne,j*SizeOfOne);
      
      }
   }

   
   
}


MyMap::~MyMap()
{
}

and my implementation in the main
[/size][/size]
const    int MPC[] =
   {
      0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
      0, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 2, 0, 0, 0, 0,
      1, 1, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3,
      0, 1, 0, 0, 2, 0, 3, 3, 3, 0, 1, 1, 1, 0, 0, 0,
      0, 1, 1, 0, 3, 3, 3, 0, 0, 0, 1, 1, 1, 2, 0, 0,
      0, 0, 1, 0, 3, 0, 2, 2, 0, 0, 1, 1, 1, 1, 2, 0,
      2, 0, 1, 0, 3, 0, 2, 2, 2, 0, 1, 1, 1, 1, 1, 1,
      0, 0, 1, 0, 3, 2, 2, 2, 0, 0, 0, 0, 1, 1, 1, 1,
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
      2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
      3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
   };

   MyMap map(window,"Map.png", 16, 12, MPC,0,0, 40,4);
It show an Error when i implement window from my own fuction in MyMap class, I just cant get the constructor right, Can somebody help me ?? :'( :'( :'( :-[ :-\



Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32009
    • View Profile
    • SFML's website
    • Email
Re: I need help with my own class implementation
« Reply #1 on: January 12, 2019, 03:18:44 pm »
1. Please use forum tags to format C++ code in your posts, it will be much more readable

2. When you have a compile error, please post the error message...

3. Why do you pass a "window" argument to your MyMap constructor if it doesn't take one?
Laurent Gomila - SFML developer

 

anything