Skip to main content
gamedev.net
🔒 Locked

Misplaced Models

Started by BangorRipper 3 replies 1.1k views
Original Post
BangorRipper
BangorRipper
When i start a game, my ship model is in the center of the screen, most of the time, when i complete a level, the ship will remain in the center, however sometimes the ship model will begin off the screen, sometimes to the left and sometimes to the right and then it has to be brought back into view, has anyone had the samwe problem or does anyone know where the problem may lie? also my aliens sometimes come in from the left, outside of the screen when they are supposed to begin in the middle, like i said, most of the time ok, but sometimes, if it was all of the time i could probably spot the problem easier thanks
dawidjoubert
dawidjoubert
Could you please post some code....

Im assuming when an alien dies a bool called alive is set to false...

then when you reinitialize them u just set it to true but without changing their coords....

Make a new function for the aliens and the ship called RESET()

and then when u start again run RESET for every alien and ship...
Making sure you reset everything...

Please Source Code..
----------------------------http://djoubert.co.uk
BangorRipper
BangorRipper
public void allAliensKilled()
{
createAliens(); // reset aliens
createShip(); // reset ship
}

private static void createAliens()
{
if(levelNumber < 4) numAliens = numRowsAliens * 6;
aliens = new Alien[numAliens];

for (int x = 0;x<6;x++)
{
if(levelNumber < 4) for (int z = 0;z }

private static void createShip()
{
ship = new Ship((float)0.0,0.0f,40.0f, true);
}

is there anyhting there that suggests they may be drawn somewhere other than the center on some occasions?

how would a reset method be used to reset the aliens?
is that not what my create aliens method is doing?

thanks
BangorRipper
BangorRipper
it seems to happen most often when i use the mouse to play the game aswell :(
dawidjoubert
dawidjoubert
Okay well here is modifications on your source to make things safer...

Have you considered to step through the program and checking the actualy values of the ships

[Source]void InitPlayer()  // Called once and that is with glInit(){ship = new ShipClass;}void DestroyAliens() // Called every time a level is loaded{delete [] aliens; // Free memory}void DestroyShip() // Also Called only once{delete ship;     // Free memory}void allAliensKilled(){DestroyAliens();   // its important to free the old memory used// Now we recreate the ships so the player can play the level again createAliens(); // reset aliens createShip(); // reset ship}void createAliens() {if(levelNumber < 4) numAliens = numRowsAliens * 6; aliens = new Alien[numAliens];for (int x = 0;x<6;x++) {if(levelNumber < 4) for (int z = 0;z<numRowsAliens;z++) aliens[(z*6)+x] = new Alien((float)-10+x*4,0.0f,(float)z*3-((levelNumber-1)*3), true);}void createShip(float x,y,z) {ship.x = Xship.y = Yship.z = Zship.Active = true}[/Source]


Yeah you might wanna give that code a try..
I hope ur not calling AllAliensKilled() from within an alien class because that function now deletes that class which should return an error.

I think more source would be helpfull,maybe the class source
----------------------------http://djoubert.co.uk

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.