Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><strong>Hello!</strong></p> <p>I don't really get what you mean by "<strong>Anonymous</strong>", but one of the solutions is to create so-called <strong>hitboxes</strong>.</p> <p>Let us assume you have an Enemy class:</p> <pre><code>public class Enemy { public var hitBox:Sprite = new Sprite() ; public function Enemy() { hitBox.graphics.clear() ; /* Not filled by a color, as needs to be invisible */ hitBox.graphics.drawRect(x,y,width,height) ; /* Adjust the parameters manually */ this.addChild(hitBox) ; } } </code></pre> <p>There are a lot of enemies, so just create enemyArray and push the enemies into it. And here goes the player's bullet:</p> <pre><code>public class PlayerBullet extends Sprite { private var stageReference:Stage ; public function PlayerBullet(coord:Point, stageReference:Stage){ this.x = coord.x ; this.y = coord.y ; this.stageReference = stageReference ; this.stageReference.addChild(this) ; this.addEventListener(Event.ENTER_FRAME, loop) ; } private function loop(e:Event){ /*Provide some movement for bullet by changing or incrementing this.x and this.y as you wish */ for (var i:Number = 0 ; i &lt; enemyArray.length ; i++){ if (this.hitTestObject(enemyArray[i].hitBox)) { enemyArray.splice(i,1) ; /* Remove the enemy from enemy array on collision */ this.stageReference.removeChild(this) ; /* Do not display bullet anymore on collision with enemy */ } } } } </code></pre> <p>Note: the hitboxes do provide only some square area. If you need some exact detailes of the collision, create several hitboxes.</p> <p>I hope, this will help ! :)</p>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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