Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you already know when the bullet is off screen, you can use two approachs: 1. Have a reference for the enemy on his bullet, so you can call a funcion on it so "recicle" the bullet; 2. Create a custom event dispatched for the bullet when it is off screen.</p> <p>I would stick with the 2), because of flexibility.</p> <p>You can find more about it here:</p> <ul> <li><a href="http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html" rel="nofollow">http://docs.coronalabs.com/api/type/EventListener/dispatchEvent.html</a></li> <li><a href="http://docs.coronalabs.com/api/type/EventListener/addEventListener.html" rel="nofollow">http://docs.coronalabs.com/api/type/EventListener/addEventListener.html</a></li> </ul> <hr> <pre><code>-- 1) function enemy:shoot() local Bullet = require "Bullet"; Bullet.owner = self; -- the same as your previous code end; function enemy:canShootAgain() self.activeBul = false; end; -- When you want the enemy to shoot again, just call canShootAgain from bullet bullet.owner:canShootAgain(); </code></pre> <hr> <pre><code>-- 2) function enemy:shoot() local Bullet = require "Bullet"; Bullet.owner = self; -- the same as your previous code end; function enemy:canShootAgain() self.activeBul = false; end; -- When you want the enemy to shoot again, just call canShootAgain from bullet bullet.owner:dispatchEvent({name = 'canShootAgain'}); -- Add this to the end of your enemy construction enemy:addEventListener('canShootAgain', enemy); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload