Skip to content
Browse files

Add accessors/mutators for fps and move_ratio

  • Loading branch information...
1 parent 1a68fe5 commit f96e89cad3941b55e0cd92a545d7c9854bef0d60 @jtpalmer committed
Showing with 50 additions and 0 deletions.
  1. +26 −0 examples/test.pl
  2. +24 −0 lib/SDLx/Controller/FPS.pm
View
26 examples/test.pl
@@ -1,6 +1,8 @@
#!/usr/bin/env perl
use strict;
use warnings;
+use SDL::Event;
+use SDL::Events;
use SDLx::App;
use SDLx::Controller::FPS;
@@ -19,6 +21,30 @@
h => 25,
};
+$controller->add_event_handler(
+ sub {
+ my ($event) = @_;
+
+ if ( $event->type == SDL_KEYDOWN ) {
+
+ my $key = SDL::Events::get_key_name( $event->key_sym );
+
+ if ( $key eq '1' ) {
+ $controller->fps(30);
+ $controller->move_ratio(1);
+ }
+ elsif ( $key eq '2' ) {
+ $controller->fps(15);
+ $controller->move_ratio(2);
+ }
+ elsif ( $key eq '3' ) {
+ $controller->fps(10);
+ $controller->move_ratio(3);
+ }
+ }
+ }
+);
+
$controller->add_move_handler(
sub {
$rect->{x} += 1;
View
24 lib/SDLx/Controller/FPS.pm
@@ -72,4 +72,28 @@ sub run {
sub stop { $_stop{ refaddr $_[0] } = 1 }
+sub fps {
+ my $self = shift;
+
+ my $ref = refaddr $self;
+
+ if (@_) {
+ $_fps{$ref}->set( $_[0] );
+ }
+
+ return $_fps{$ref}->get();
+}
+
+sub move_ratio {
+ my $self = shift;
+
+ my $ref = refaddr $self;
+
+ if (@_) {
+ $_move_ratio{$ref} = $_[0];
+ }
+
+ return $_move_ratio{$ref};
+}
+
1;

0 comments on commit f96e89c

Please sign in to comment.
Something went wrong with that request. Please try again.