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 / Enemies are not spawning in their locations.

Author
Message
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 15th Jan 2012 13:42
Hey all

I recently got the Enemy1 Struct array working and now i got multiple enemies with the same base.. xD

So.. After the includes i added:


This is the Enemies (array of enemy1) Spawn Positions. Each one for each enemy.

So, you can see that there are 10 values for X and for Y.

So at the LoadEnemy function i got:



Then in the Spawn i simply got this:



I also have at the Main Function:



So basicly this will Load the array and automaticly points that enemy array "id" and checks that ID in the Position arrays..

It should work right?

Well the problem is they are not spawning at that positions.


Here's all the positions:

Enemy1: 100 100
Enemy2: 100 100
Enemy3: 100 100
Enemy4: 100 100
Enemy5: 200 -600
Enemy6: 200 -600
Enemy7: -400 700
Enemy8: 100 100
Enemy9: 100 100
Enemy10: 100 100

So the Enemy5, 6, and 7 are not spawning on their locations..
Why this happens?

Here you have the entire struct of the Enemy1:





C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jan 2012 14:50
Quote: " id = rnd + 200 + dbRnd(EnemyCount + 10);
dbLoadImage("enemy1.png", id);
"

This could be problematic. Your "id" is some random number near the sprite ID you got in the previous function +200....? Why? This could create/fail loading the image without you knowing what the id actually is (you could have overlap).

Also
Quote: "Move(player.x + player.SizeX, player.y + player.SizeY);"
is not going to give you the result you want. The "size" value I posted for you before was to be used if you weren't going to be using sprite collision testing. Take the size values out-- you don't need them and they will cause your enemies to target in front of your player (Right and Down).

Quote: "for(int n = 0;n<10;n++)
{
enemy1[n].LoadEnemy(n);
}"

I this in your loop? If so, put it before your loop.

To answer your original question, I think the problem will be corrected by correcting the code I pointed out first.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 16th Jan 2012 15:18
So.. How can i make so the ID wont be the same in some enemies?
That error was causing me some problems.. :S

Ok, i fixed out what you have said and its working

Thanks a lot, you are the man!!!

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jan 2012 18:21
The whole idea behind "GetFreeSpriteID();" is that it returns a unique ID. That way you don't accedentally use the same ID for two different sprites.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 16th Jan 2012 19:06
No thats not the problem acutally...

That function is working right, but i load the enemy and only in the Update (Loop) i spawn them.. So.. Its like:

Load Enemy8574875497854
ID: 5 is free

Load Enemy969879567845854
ID: 5 is free

Then they spawn with the same id, it will add both things to 1...
Thats the error actually..

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jan 2012 20:57
It looks like you are:
Quote: "void Enemy1::LoadEnemy(int PosID)"
10 times. At least somewhere in your code. This code is unpredictable (because of the random):
Quote: "id = rnd + 200 + dbRnd(EnemyCount + 10);"
and can produce an image id that is the same as another. This will cause your load to fail. It's not actually a problem, but your code is not using unique instances or loads of the same image. I suggest you load the image once and assign it to all your sprites-- this is the more precise way to do it.

So if you change your code:

and....

This will only load the image once (using less memory) and each Enemy will have it's unique sprite ID without the possibility of overlap.
By the way, what does your "GetFreeSpriteID();" look like? I invision it to look like:


The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 16th Jan 2012 21:22
Actually its:



I tested using the same image id but the enemies position switched to -1, -1... not sure why but when i use what im using now its working good..

Basicly it loads an image to each enemy but that id only belongs to that enemy... How much memory can it use ?

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jan 2012 21:59
Quote: "How much memory can it use"

It depends on the image size.

I'm not sure what you were doing wrong before, but I know that you can assign the same image to multiple sprites at the same time.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 16th Jan 2012 22:06
well.. the image is just... 48x15.. not a full background..

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)
Hawkblood
14
Years of Service
User Offline
Joined: 5th Dec 2009
Location:
Posted: 16th Jan 2012 22:13
Even if you are just starting out or your games are very small, you should always try to reduce the programs footprint in memory useage and in clock cycles. It will get very messy and clumsy quickly with larger programs.

The fastest code is the code never written.
vitinho444
13
Years of Service
User Offline
Joined: 12th Oct 2010
Location:
Posted: 16th Jan 2012 22:33
true :X xD

Thanks a lot

C++ Medium 3.5/5
www.oryzhon.com <-- My company's website (W.I.P)

Login to post a reply

Server time is: 2024-04-24 17:30:25
Your offset time is: 2024-04-24 17:30:25