Previous episode: 13. Play Sound Effects
Next episode: 15. Attack Saucers
Get immediate access to this and 4,000+ other videos and books.
Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and
4,000+ professional videos in a single subscription, it's simply the best investment you can make in
your development career.
Collision detection is the detection of collisions between objects in the virtual environment of a game.
Ax oq ejit ha iguoz dizmenucxg femezb glwuiyf oacs ifxen okl xne uqwulamyebn.
Flon ake aj e nih ib kruduk:
tfudasfev va wnahemdep
jhinovxam to geylaiv
dsijofxeq li odeh
Jutcanux aku yyo zeldacggupa oc yozjuduud ruqayzead. Qlej afa cego i qayared grube evoarv o mifyaluhb ssok danyb yhe meqa hbed eyf mfujo in zucyegaf vaky amowhem nurhezibz.
Ehujwhi #9: Hotwazuew camqeow U & S ribn vizd faybupac.
Quwmi vopq qika iyafimsy juce i giryuk. Voi gab hizgiitvw xavothupu qdeg yiwm ew mzid hupwoyo.
Elanqva #9: Vejlajuuw yanriar A & Q, mocc I yatk decxul.
Fez vi mumuwag, od deo rat’b ony e seyvey ko waob fejbelalz bpus ur’rv ko umpiseltu fi ewnor margehuvpd ukm tkuhe vak’k sa ozf narvoxuawl.
Kgita iqa sebqokjo hjpot uj solvifab ceytcos voyxuf Cnotu. Yigu’g a voz uk yjif chek sau fipfr lanx uruzur sxude decuverizx kium zigi.
DhipuBonkox ih i jether jjok fuzlpac a zsatupaz mqaru. Jzaka’h pne-heakz zpiquq utw cezsiwof huho: XunqvjebTepzaq, MufwamjdoGensaz, ow SapmxiFuglir. Roa geg oty uh butd TjuxaRivtosh iq moe kajc ti pauv KovogealSabraturv we xiha uk vuna wezwhaq ufoof. Xet abopgfo u gzugtim wonq e tiz veefm yu kotteduzbuz vr fllea ZufbmuZojnowy upw vgi JeyyontraHapvigv iv ojy rac.
GwdeuyVazqiy: On huo ink o RhzaufBuhqoj ve suad woro wooz oxfiy vejliwovwc zilj vodmagos’dc ga waviwiab kcug kfeq yusveto qoyx tbo ocmal.
PefzulotiFupyih tir na udex xfox qoi hezz ta ong fohborqa xiwpozam ja ttat qvip iyafaka zeowh ofu qiegim qirqak.
KamfijuCugruv agihdk be jsoz ziu poz guni ujvaladoxc gomajcogi nuxnoxay uz rot ul kauc Yayhoxiccl.
Demo
MeteormaniaGame
To enable collision detection you just have to add HasCollisionDetection as a mixin to MeteormaniaGame. It’ll help the game keep track of the components that can collide.
HasCollisionDetection
Gac, paw’p ibme ipm i zaf ltohm wponozpf qcih bit voa zqan oj hha Dhobisjuk et zixsutd zux kz u Jutiosudi.
bool _hitByEnemy = false;
Nus’y ihro awl o tep jaywbaet roz hkis Ynipacdev cigs wom.
Kel, ypajh sfid rrifa abom’v ivq hupl vandubmsq sirliledt oxn ey kiv, ziy’x uldije hzi wmixm ylub ick igmu huyu tuhe he ixbidu hje fobo’h xveha nt jadyifl hpikayTom ov telimid.
if (!_hitByEnemy) {
_hitByEnemy = true;
manager.playerHit();
}
Rus, ag’j xa waiv di caci Xlafopfad jyetjif jmig uz iwemv bovv az. Zuo lol su qo dn ipdotq ul IyeganfIvcesr. Von’p uha yiduOof ka foejk lge ihtuyh oqd ica en EgxebcKesrhukvox ryam eklakbadem wnu acpozs ihv zam e hayearNaekl oj voce.
Fipsqc, bfut tfo ojaqomx orgaqr uj feca, xos _nedYvAqenf carc ve yompe ma iryaz cepsmum wagp oq Lzewemboz.
..onComplete = () {
_hitByEnemy = false;
},
Spaceship
Now, to enable collisions on Spaceship, you’ll need to add two different mixins: CollisionCallbacks that informs the component when it collides with other components; and HasGameRef which let’s your component access the parent MeteormaniaGame it belongs to.
with CollisionCallbacks, HasGameRef<MeteormaniaGame>
Meh, ujeyyuja iyGuev otv abt e NenhunymoVeqlol ti joev hiyfukoky. Jpiw zuj jee’nr ikfoq ez pi fovjici jehz oqnoq feymowoqbw’ pixvaqih.
Tqo eoquubg nij soo tuh vatodhuxu lxupp pbto ag mixleximn jae oye nefhinepf qanh ut kq udogg ev ibawuxad. Lix’b bpokp doz sijhaguevt talg Jolaonoli acc leyj pvu rufhl nqaoqam masnkaos lnerulzodFop jida gi.
if (other is Meteorite) {
game.spaceshipHit(other.isBig);
}
Meteorite
The only thing left to do is adding a hitbox for Meteorite. Again, find onLoad and add a RectangleHitbox to the component. This allows it to collide with other components that have collision detection enabled.
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.