-
Notifications
You must be signed in to change notification settings - Fork 486
Open
Labels
Description
Not sure if this is an intended feature or not but, as seen in the screenshots below, when the gray box has the default origin, it's able to interact with the white box. But when it has a custom origin, it is not able to interact with the white box.
Custom Origin:
PlayState Code:
package;
import flixel.util.FlxColor;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.tweens.FlxEase;
import flixel.tweens.FlxTween;
import flixel.util.FlxCollision;
class PlayState extends FlxState
{
var circle:FlxSprite;
var box:BaseBall;
var overlaps:Bool;
override function create()
{
super.create();
box = new BaseBall();
box.screenCenter();
box.weapon.origin.set(20, 20);
circle = new FlxSprite();
circle.makeGraphic(24,24);
circle.screenCenter();
// move right so it only touches at certain angles
circle.x += (box.width + circle.width - 10) * 0.55;
add(circle);
add(box);
}
override function update(elapsed:Float)
{
super.update(elapsed);
final overlaps = FlxCollision.pixelPerfectCheck(circle, box.weapon);
box.alpha = overlaps ? 0.5 : 1;
}
}
Box Code:
package;
import flixel.FlxSprite;
import flixel.group.FlxSpriteGroup;
import flixel.util.FlxColor;
class Box extends FlxSpriteGroup
{
public var sprite:FlxSprite;
public var weapon:FlxSprite;
public function new(x:Float = 0, y:Float = 0, color:FlxColor = FlxColor.RED)
{
super(x, y);
sprite = new FlxSprite();
sprite.makeGraphic(32, 32, color);
weapon = new FlxSprite();
weapon.setPosition(sprite.width, 10);
weapon.angularVelocity = 180;
add(sprite);
add(weapon);
}
override public function update(elapsed:Float)
{
super.update(elapsed);
}
}
Is there another method of checking collisions when a sprite is rotating that works with custom origins that I don't know about?
