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 9015665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T03:48:21+00:00 2026-06-16T03:48:21+00:00

Sprite1 *enemy = new Sprite1(100, 100, enemy.bmp, *screen); enemy->DrawJon(screen); enemyList.insert(enemyList.end(), *enemy); For some reason,

  • 0
            Sprite1 *enemy = new Sprite1(100, 100, "enemy.bmp", *screen);
            enemy->DrawJon(screen);

            enemyList.insert(enemyList.end(), *enemy);

For some reason, the enemy is not being stored in the list. Any ideas?

EDIT:

Also how to access the objects and use them after wards like:

for (int g=0; g<enemyList.size(); g++)
            {
                Sprite1 enemyToMove = enemyList.at(g); //.at(g);
                enemyToMove.MoveJon(0, 50, screen);
            }

EDIT:

So even though this got closed I still want people to know what the solution was. I had not made a constructor that set the properties on the class. In the end I was able to get this working with a default constructor and a setter method

  • 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-16T03:48:23+00:00Added an answer on June 16, 2026 at 3:48 am

    It inserts a copy of the object before the end of enemyList. For this, you should really prefer enemyList.push_back(*enemy). However, note that it is a copy. If you want to be referring to the same object inside and outside of the std::vector, you’re going to want a vector of pointers (preferably smart pointers). For example:

    std::vector<std::shared_ptr<Sprite1>> enemyList;
    
    std::shared_ptr<Sprite1> enemy(new Sprite1(100, 100, "enemy.bmp", *screen));
    enemy->DrawJon(screen);
    
    enemyList.push_back(enemy);
    

    Alternatively, use a std::vector<std::reference_wrapper>.

    If you have changed your std::vector to contain pointers or std::reference_wrappers, you can just access the enemies like so:

    std::shared_ptr<Sprite1> enemyToMove = enemyList[g];
    // or
    std::shared_ptr<Sprite1>& enemyToMove = enemyList[g];
    

    If you’re still containing Sprite1s directly, you need to keep a reference to the object returned by operator[] or at, otherwise you’ll copy it:

    Sprite1& enemyToMove = enemyList[g];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Sprite1 *test = new Sprite1(450, 450, enemy.bmp, *screen); test->DrawJon(); SDL_Delay(1000); test->MoveJon(20,20); I am getting
I used to stopAllActions when running a new action. I noticed some problems when
I have created a movement of the enemy that moves randomly around the screen,
So, i have a basic game scenerario: Some unit moves close to an enemy
I want to respawn enemy sprites based on a timer any suggestions would be
void spriteput(int x,int y, int stype) { char sprite1[5]=OOOO; char sprite2[5]=OOOO; char sprite3[5]=OOOO; char
I'm working with sprite animation (OpenGL + C++). I have some trouble working with
When one of my sprites is being dragged (moved around), I'm cycling through other
G'day All, If I have a number of objects called enemies on the screen,
So basically I just wanted to create an enemy class with pygames.sprite.Sprite as the

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.