Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / Problem displaying multiple sprites

Author
Message
Joe21
8
Years of Service
User Offline
Joined: 24th Apr 2012
Location:
Posted: 24th Apr 2012 20:57
Hey, I am currently working on a final project which I use GarkGDK to make a game, SpaceSurvival. The user controls a spaceship and is supposed to avoid asteriods that appear on the screen. My problem is displaying multiple asteriods at once.

I have a SpaceSurvival class which has a private member that is a vector of Asteriods (vector<Asteriods> MyAsteriods so that I can keep track of how many asteriods are on the screen at once.

Then in the SpaceSurvival game class, I make instances of Asteriods:

int i = 4; // First spriteId unused
while(MyAsteriods.size() < MyAsteriodsMax)
{
Asteriods newAsteriod(i);
MyAsteriods.push_back(newAsteriod);
i++;
}
and then have each Aasteriod updated:
for(int i = 0; i < MyAsteriods.size(); i++)
{
MyAsteriods[i].Update();
}

However, my game only displays one asteriod, even though it makes all 10 (ten is the max size of the vector). Does anyone know why this would be happening? I asked my teacher and he wasn't sure either.

Attached is the constructor of my Asteriod class as well..

I'd appreciate any advice on how to fix this problem

Attachments

Login to view attachments
kamac
9
Years of Service
User Offline
Joined: 30th Nov 2010
Location: Poland
Posted: 26th Apr 2012 19:09
Why do you use vector for fixed amount of asteroids? You'd be better with a table I think.

So:



Because you create ten asteroids anyway, why not to use a table. (Also because you set vector's max to 10. Vectors are helpful when you don't know how many instances of that class will be created)


Besides that,



Here is the error.

It should be:



Joe21
8
Years of Service
User Offline
Joined: 24th Apr 2012
Location:
Posted: 27th Apr 2012 00:26
I thought I should use a vector because I wanted to have asteriods move down the screen, delete them when they move off the screen, and then make more asteriods (add them back to the vector) and always keep track of the amount of asteriods on the screen so I thought that would make the most sense that way, if I am thinking about it correctly.

Also I realized my mistake and changed it to MyAsteriods[i].Update(); but it still did not work.

What I don't understand is how all of the sprites are being created and updated (I debugged the code to check this) but only one asteriod is actually displayed on the screen. Do you have an idea why this is happening?
Joe21
8
Years of Service
User Offline
Joined: 24th Apr 2012
Location:
Posted: 27th Apr 2012 01:52
Never mind I just fixed my mistake. I messed up the random generator for the coordinates and they were all being displayed on top of each other. Can't believe I did that. thanks for the advice though.

Login to post a reply

Server time is: 2020-09-19 06:25:49
Your offset time is: 2020-09-19 06:25:49