The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Game::Collisions::UserData - Role for picking up movement to the AABB

SYNOPSIS

package MyUserData;
use base 'Game::Collisions::UserData';

sub new { ... }

sub on_aabb_move
{
    my ($self, $args) = @_;
    my $add_x = $args->{add_x};
    my $add_y = $args->{add_y};
    ...
}


package main;
my $user_data = MyUserData->new;
my $collide = Game::Collisions->new;
my $box = $collide->make_aabb({
    x => 0,
    y => 0,
    length => 1,
    height => 1,
    user_data => $user_data,
});

# MyUserData instance is called from here
$box->move({
    add_x => 1,
    add_y => 3,
});

DESCRIPTION

Set an instance of this to the user_data on an AABB, and it will have its on_aabb_move() method called right after any movement.

OVERRIDABLE METHODS

on_aabb_move

   sub on_aabb_move
   {
       my ($self, $args) = @_;
       my $add_x = $args->{add_x};
       my $add_y = $args->{add_y};
       ...
   }

Is passed the add_x and add_y parameters that were passed when the AABB moved.