Author Topic: Colliding with rectangle drawn in a sprite  (Read 1305 times)

dca

  • Member
  • **
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Colliding with rectangle drawn in a sprite
« on: Fri, Jan 23, 2015 »
I have a class that extends FlxSprite and I can draw the rectangle in the class in the draw() function.

What I need to do is to have other sprites collide with it.
Code: [Select]
package 
{
import flash.geom.Rectangle;

import org.flixel.FlxG;
import org.flixel.FlxSprite;

/**
* ...
* @author ...
*/
public class gutter extends FlxSprite
{
private var nX:Number=0;
private var nY:Number=0;
private var nWidth:Number=0;
private var nHeight:Number=0;

public function gutter (X:Number=0, Y:Number=0, Width:Number=0, Height:Number=0){

nX=X;
nY=Y;
nWidth=Width;
nHeight = Height;
var mygutter:Rectangle = new Rectangle(nX, nY, nWidth, nHeight);
super();
}

override public function draw():void {
super.draw();
var mygutter:Rectangle = new Rectangle(nX, nY, nWidth, nHeight);
FlxG.camera.buffer.fillRect(mygutter, 0x66FF0080);

}

override public function update():void{

super.update();
}
}
}

When I do this, though, the collisions don't happen. Any ideas?

Gama11

  • Contributor
  • ****
  • Posts: 390
  • Karma: +0/-0
    • View Profile
Re: Colliding with rectangle drawn in a sprite
« Reply #1 on: Sat, Jan 24, 2015 »
You're not setting width and height anywhere (controls the size of the hitbox). Also, why not simply use makeGraphic() to create a rectangular sprite?

dca

  • Member
  • **
  • Posts: 11
  • Karma: +0/-0
    • View Profile
Re: Colliding with rectangle drawn in a sprite
« Reply #2 on: Sat, Jan 24, 2015 »
Didn't know I could just use it to do that. Thanks!