Friday, October 7, 2022
HomeGame DevelopmentThousents of bullets logic/efficiency logic - cocos2d-x

Thousents of bullets logic/efficiency logic – cocos2d-x


Whats up,
I used to be enjoying some previous retro video games and began questioning how did they do it again then. There the place shootemups video games the place you actually had a whole bunch of bullets flying across the display. And any of them may kill you.
I’ve been studying some cocos books (previous however nonetheless legitimate I assume), and evidently the logic is to retailer all of the bulllets on display in a ccArray and within the replace technique you do a CCARRAY_FOREACH (which i assume in cocos3dx 4.0 is now CCARRAYDATA_FOREACH).
So when you’ve got say, 200 bullets, and the sport is 60 fps, it signifies that the replace technique is checking 12000 intersections per second!! + all the pieces else in your sport logic.

I come from a CGI background the place you progress meshes with thousents of vertices per second ar 24 fps, which is form of regular. So I ponder, being new into sport improvement, if 12000 intersection checks per seconds is loopy or is doable.

thanks,
R


okay, I’ve been studying abit on the subject and evidently one of the simplest ways to do it’s to make use of a pool and sphere colliders (apparently sooner than field colliders). So insteand of instanciating and destroying all of the bullets,
they’re created all of sudden off display, after which simply transfer round and reposition out of display when not wanted.



1 Like

Hello there, I feel they might of simply examine the space from and object to object,
not all of the factors of a physics object in an engine.

Instance code.

float diffY = p1.y – p2.y;
float diffX = p1.x – p2.x;
return sqrt((diffY * diffY) + (diffX * diffX));
then if the space is much less then say 2 then collide, however again within the day it will of additionally been Meeting language.

That’s is attention-grabbing(It can save you some efficiency although with out making use of the sq. root)
My concern was extra about creating the sprites situations than the collisions. As an alternative of making and destroying the sprites situations, they’ll all be created directly off display at loading time, after which simply transfer then round. As an example, when colliding, as an alternative of destroying the sprite and creating a brand new one once more, simply transfer it again off display till you want it.
I do one thing comparable with some background clouds. Create as soon as, and as soon as they depart the display, set the place out once more and restart.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments