Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7902777
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:35:29+00:00 2026-06-03T09:35:29+00:00

How do I create a vector of Sprites using SFML and vector header? I

  • 0

How do I create a vector of Sprites using SFML and vector header?
I started the vector like

vector<sf::Sprite> test;

and I’m trying to do a push_back(), but I don’t know what I need to put inside the “()”.

Anyway, my vector will be 41×31, so there is a way t do something like

vector<vector<sf::Sprite> > test (41,vector<sf::Sprite>(31,??))
?

I’m using this to create a tile map, if someone has a better idea, I will appreciate

EDIT:

I still got errors, thats my code

vector<vector<int> > mapc (5,vector<int>(5,1));

sf::Sprite mapa[5][5];

void fmap() {
    mapc[0][0] = 1; mapc[0][1] = 1; mapc[0][2] = 1; mapc[0][3] = 1; mapc[0][4] = 1;
    mapc[1][0] = 1; mapc[1][1] = 0; mapc[1][2] = 0; mapc[1][3] = 0; mapc[1][4] = 1;
    mapc[2][0] = 1; mapc[2][1] = 0; mapc[2][2] = 1; mapc[2][3] = 0; mapc[2][4] = 1;
    mapc[3][0] = 1; mapc[3][1] = 0; mapc[3][2] = 0; mapc[3][3] = 0; mapc[3][4] = 1;
    mapc[4][0] = 1; mapc[4][1] = 1; mapc[4][2] = 1; mapc[4][3] = 1; mapc[4][4] = 1;

    sf::Image w;
    w.LoadFromFile("w.png");
    sf::Image f;
    f.LoadFromFile("f.png");
    unsigned int i,j;
    for(i=0;i<mapc.size();i++) {
        for(j=0;j<mapc[i].size();j++) {
            if(mapc[i][j] == 1) { sf::Sprite teste(w); }
            else { sf::Sprite teste(f); }
           mapa[i][j] = teste;
        }
    }
//     test.push_back(teste);
}

it says that

“‘teste’ was not declared in this scope”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T09:35:31+00:00Added an answer on June 3, 2026 at 9:35 am

    Edit: Actually I lied, if you know the exact size of the map then you can just use

    sf::Sprite map[41][31];  
    

    Unless your map is going to be changing its size during runtime you should just create an array on the stack.

    sf::Sprite temp; //used to initialize the map
    map = new sf::Sprite[num_rows];  
    for(int i = 0; i < num_rows; i++){  
        map[i] = new sf::Sprite[num_cols];  
        for(int j = 0; j < num_cols; j++){  
            map[i][j] = temp;  
        }  
    }  
    

    Then you’ll want to run through the map one more time to initialize it. If you can’t do that and you need to use a vector then you can do something similar for the vector.

    sf::Sprite temp; //used to initialize the map  
    vector<vector<sf::Sprite> > map;  
    vector<sf::Sprite> row;  
    map.resize(0);  
    row.resize(0);  
    for(int i = 0; i < num_cols; i++){  
        row.push_back(temp);  
    }  
    for(int i = 0; i < num_rows; i++){  
        map.push_back(row);  
    }  
    

    Your map is then accessible as
    map[x][y]
    in either case.

    Hope this helps

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a sparse vector class in C++, like so: template<typename V,
I'm trying to create a vector for D3DXMATRIXA16 like so: vector<D3DXMATRIXA16> matrices; and am
I'm using Flash CS4 and Flex 3.4.0. I'd like to create a vector-graphic button
I was trying to create a vector of lambda, but failed: auto ignore =
I would like to create a vector of functions using a two agruments function
I'm new to using vectors...I just started studying them today. I'm trying to create
Can I create a vector v3 = [1,100,2,99,3,98,...,100,1] using just colon notation? I've only
I would like to create a vector that repeats itself. (eg 1:3 until 12
I would like to create a vector with the entries filled with normal distribution
This looks simple but I am confused: The way I create a vector of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.