Hello, Monks!

I need your help i have this Perl SDL app that will move the sprite image if you press your right arrow key but the image is duplicating inside the box ... see my code:
#!/usr/bin/perl use strict; use warnings; use Carp; use SDL; use SDLx::App; use SDL::Event; use SDL::Events; use SDL::Image; use SDL::Audio; use SDL::Mixer; use SDLx::Sprite; use SDLx::Sprite::Animated; use SDL::Mixer::Samples; use SDL::Mixer::Channels; use SDL::Mixer::Music; my $app=SDLx::App->new( w=>500, h=>500, title=>'Moving Sprite' ); my $quit=0; my $laser=20; my $laser_y=25; my $fire=0; my $e_x=100; my $e_y=50; #positions my $pos_y=15; my $pos_x=5; my $ex=SDL::Rect->new($e_x,$e_y,20,20); my $dt=15; my $rect=SDL::Rect->new(0,0,50,50); my $sprite = SDLx::Sprite::Animated->new(width=>100,height=>120); $sprite->load("man.png"); #$sprite->ticks_per_frame(1); sub get_events{ my $event=SDL::Event->new(); #$event->set_key_repeat(10,10); SDL::Events::pump_events(); while(SDL::Events::poll_event($event)){ $quit=1 if $event->type==SDL_QUIT; if($event->type==SDL_KEYDOWN){ if($event->key_sym==SDLK_RIGHT){ print "RIGHT!\n"; $sprite->next; last; }elsif($event->key_sym==SDLK_SPACE){ $sprite->stop; $sprite->reset; } } } } sub render{ $sprite->draw($app); $app->update(); SDL::Video::update_rects($app,$sprite->rect); } while(!$quit){ get_events(); render(); }
Here is the man.png file. Thanks

In reply to Perl Moving Sprite image using SDLx::Sprite::Animated correctly by Muskovitz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.