Basically I figured that In current I would run a while statment and some how check SDL_KEYUP to see when it would be equal to the previously pressed key but that hasn't worked. Any ideas?use strict; use SDL; use SDL::App; use SDL::Rect; use SDL::Surface; use SDL::Color; use SDL::Event; my $hold = 0; my $key; my $right = 0; my $left = 0; my $up = 0; my $down = 0; my $x = 10; my $y; my $key2; my $gangsta = SDL::Surface->new( -name => 'gangsta.gif', ); my $ghetto = SDL::Surface->new( -name => 'ghetto.jpg', ); my $app = SDL::App->new( -height => $ghetto->height(), -width => $ghetto->width(), -depth => 16, -title => "China Man Shooter 0.2 (Gang Fights)", ); my $bg_rect = SDL::Rect->new( -height => $ghetto->height(), -width => $ghetto->width(), -x => 0, -y => 0, ); my $bg = SDL::Rect->new( -height => $app->height(), -width => $app->width(), -x => 0, -y => 0, ); my $gangsta_rect = SDL::Rect->new( -height => $gangsta->height(), -width => $gangsta->width(), -x => 0, -y => 0, ); my $gang = SDL::Rect->new( -height => $gangsta_rect->height(), -width => $gangsta_rect->width(), -x => 10, -y => 100, ); refresh(); my $event = new SDL::Event(); my %events = ( SDL_QUIT() => sub { exit(0); }, SDL_KEYDOWN() => sub { $event = shift; $key = $event->key_name(); current(); }, SDL_KEYUP() => sub { $event = shift; $key2 = $event->key_name(); }, ); $app->loop( \%events ); sub current { while ($hold == 0) { my $current_x = $gang->x(); my $current_y = $gang->y(); if ($key eq 'right') { for my $m ($current_x..($current_x + 5)) { $gang->x( $m ); refresh(); } } if ($key eq 'left') { for my $m ($current_x..($current_x - 5)) { $gang->x( $m ); refresh(); #I have no idea what im doing here %events->SDL_KEYUP(); if ($key eq $key2) { $hold = 1; } else { $hold = 0; } } } } } sub refresh { $ghetto->blit($bg_rect, $app, $bg); $gangsta->blit($gangsta_rect, $app, $gang); $app->update($bg, $gang); }
Thanks for the Help its all works great now
In reply to SDL Events hold key down by Treehunter
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |