1

I've always had a question about datlib


for(i=0;i<BOXNUM3;i++) {

short boxsprNum=80;

aSpriteInit((aSprite*)&boxs[i],&bmary3_ spr,boxsprNum,16+bmary4_ spr.palInfo ->count,randnum[rand()%M],90,0,FLIP_ NONE,AS_ FLAGS_ DEFAULT);

boxsprNum+=4;

}


Boxsprnum can only be set to 375 at most. If it is more, it will not be displayed.


If the game has characters, bullets. Enemy, enemy bullets. 375 sprites are not enough

Five enemies, five bullets for the enemy, one character, five bullets for the characters. That's all.

NEOGEO business games can always have a lot of sprites. Especially shooting games.


Is there any way to have more Sprite? Thank you very much.
avatar

2

Part of the answer you are looking for is here: https://wiki.neogeodev.org/index.php?title=Sprites

Try moving the yPos to see if the other sprites appear. You have yPos=90 and after 96 sprites on the same scanline (which I believe are y positioned), sprites will be dropped.
avatar

3

Slow down.


No bullets. More than seven enemies are moving on the screen. Slow down, it will be very serious.


Thank you very much for your help. Thank you very much.
avatar

4

To avoid slow down you need to think about program flow. Such as this:

(player input)->(move objects) -> (check for collisions)->(update ui)->(break to allow neo to render)

In MoveObjects and Collisions there might be some objects that can be skipped. With MoveObjects/Collisions some objects are turned off because they are not being used. In collisions a quick sector check could be used to see if a collision 'might' happen. So the pipeline might look like this:

(player input/update sector)->(move/update sectors of alive objects) -> (check for collisions based on sector)->(update ui)->(break to allow neo to render)

I did find at some point an article that suggested looking for not colliding was faster than looking for collision. With bullets using a point in box collision would be faster and look just a as good, because the bullet is so small. Box collision is faster the circle collision.

One last thing is to use int instead of float for math calculations. Int is much faster. If you need a certain type of movement, a hard coded table would be faster. Such as an enemy moving in a wave pattern with curves. A lot of the program is preloaded before game play for some games.

I would suggest playing some older games and see how many objects were on the screen. I have tried to skip some parts of the program flow for a frame or two to increase rendering speed, but that didn't seem to have helped.

I hope some of this helps.
avatar

5

deqcdaw
Are u using C to code a fast sprite routs with collision check ?
If you are talking about bullets, the only way to do it the faster you can is to code a asm rout (for instance) called in C with objects parameters ...
Without asm code it will be difficult to do this faster ...

6

Thank you very much for your reply. Thank you very much.


My code for creating and destroying enemies is simple and crude.


Creating enemies


typedef struct box_ type {

aSprite as;

ushort currentAnim;

ushort stepNum;

short posX,posY;

short state,id,get;

int relX,relY;

int flag;


} box_ type;

box_ type boxs[7];

short i;


////////////////////////////////////


void boxint3(short boxsprNum){


for(i=0;i<BOXNUM3;i++) {

aSpriteInit((aSprite*)&boxs[i],&bmary3_ spr,boxsprNum,16+bmary4_ spr.palInfo ->count,150,90,0,FLIP_ NONE,AS_ FLAGS_ DEFAULT);

boxsprNum+=4;

}

palJobPut(16+bmary4_ spr.palInfo ->count,bmary3_ spr.palInfo ->count,&bmary3_ spr.palInfo ->data);

for(i=0;i<BOXNUM3;i++) {


boxs[i].flag=0;

}

for(i=0;i<BOXNUM3;i++) {


boxs[i].id=13;

}

}
////////////////////////////////////////
Create collisions:

for(i=0;i<BOXNUM3;i++){
if(boxs[i].id!=13) {boxs[i].relX=boxs[i].as.posX-8;
boxs[i].relY=boxs[i].as.posY-80;}
if((boxs[i].id==13)&&(boxs[i].as.currentAnim==6)) {boxs[i].relX=boxs[i].as.posX-8;
boxs[i].relY=boxs[i].as.posY-60;}
if((boxs[i].id==13)&&(boxs[i].as.currentAnim==8)) {boxs[i].relX=boxs[i].as.posX-8;
boxs[i].relY=boxs[i].as.posY-60;}
if((boxs[i].id==13)&&(boxs[i].as.currentAnim<=5)) {boxs[i].relX=boxs[i].as.posX-8;
boxs[i].relY=boxs[i].as.posY-80;}
if((boxs[i].id==13)&&(boxs[i].as.currentAnim>=10)) {boxs[i].relX=boxs[i].as.posX-8;
boxs[i].relY=boxs[i].as.posY-80;}
}
///////////////////////////////////////////////////////////////////////////////
Destroy the enemy and put it out of the screen:

if((boxs[i].as.currentAnim==15)&&(boxs[i].as.stepNum==15)&&(boxs[i].id==13)) {boxs[i].as.posX=350; boxs[i].as.posY=-250; }

//////////////////////////////////////////////////////////////////////////////

Sorry, the C game code I can find is very limited. I can only think of that.


Then slow down.

I mainly don't understand how to destroy what was created. Just put it out of the screen.

Thank you
avatar

7

Hi deqcdaw,

I look at things from a very basic perspective so take this with a grain of salt.

You have 381 sprites that are 16 pixels wide up to 512 pixels in height. EX: A character that is 32 pixels wide regardless of height takes up 2 of your 381 sprites

Now out of 381 you can only display 96 at any given time (Again take this with a grain of salt I know there is more to it than this but for starters it doesn't hurt to think this way)

You must master Hiding and Showing sprites. When sprites are hidden they aren't rendered and don't contribute to slow down.

HPMAN's DATlib documentation document's:

aSpriteHide();
aSpriteShow();

(Master these function calls. EX: Practice by mapping button inputs to hide and show various sprites...don't think of deleting sprites...just think of hiding what you don't want and showing what you do want)

Finally, if you have way more than 381 sprites in your game you can re-purpose any of your 381 sprites to point to different GFX data anytime you want by re-initializing the same sprite slot with different GFX and palette data.

This is my basic info that some may frown upon due to it being very simplistic and not 100% accurate in it's definition but for starters I think it will be helpful.

I do intend on replying to your other posts just haven't had a chance yet.

8

This is the struct for a box around the sprite.

typedef struct rect { int x; int y; int width; int height; }rect;
This is a reverse collision check.

int FastCollisionCheck(rect one, rect two) { if( one.y + one.height < two.y || one.y > two.y + two.height || one.x > two.x + two.width || one.x + one.width < two.x ) { //no collision detected return 0; } //collision detected return 1; }
No collision check in assembly using position and wiidth/height.

*** int checkCollision(int x, int y, int w, int x1, int y1, int w1) *** This function checks for the opposite of collision. if any are true *** boxes cannot be colliding. Does not support different width and height. *** Width and height are the same value. *** Entering 0 for width (w1) makes the second box a point checkCollision: .set _ARGS, 4 * check y + w < y1 move.l _ARGS+4(a7), d0 add.l _ARGS+8(a7), d0 move.l _ARGS+16(a7), d1 cmp.l d1,d0 * branch if less than else continue blt HHH * check y > y1 + w1 move.l _ARGS+4(a7), d0 move.l _ARGS+16(a7), d1 add.l _ARGS+20(a7), d1 cmp.l d1,d0 bgt HHH * check x > x1 + w1 move.l _ARGS(a7), d0 move.l _ARGS+12(a7), d1 add.l _ARGS+20(a7), d1 cmp.l d1,d0 bgt HHH * check x + w < x1 move.l _ARGS(a7), d0 add.l _ARGS+8(a7), d0 move.l _ARGS+12(a7), d1 cmp.l d1 , d0 * branch if less than else continue blt HHH * if all are false, boxes collide move.l #1, d0 rts HHH: * if any are true, boxes don't collide move.l #0, d0 rts
avatar

9

Thank you very much.


OK, I understand that sprite can't be deleted.


aSpriteHide();

aSpriteShow();


I'll keep trying


Hine62, your collision check looks great.


I will continue to study.


Thank you very much for your help
avatar