Softpedia
 


LINUX CATEGORIES:



GLOBAL PAGES >>
NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
WEEK'S BEST
  • Linux Kernel 3.9.3 / 3....
  • LibreOffice 3.6.6 / 4.0.3
  • MPlayer 1.1.1
  • systemd 204
  • Arch Linux 2013.05.01
  • Blender 2.67
  • KDE Software Compilatio...
  • CrunchBang Linux Stable...
  • Elementary OS 0.1 / 0.2...
  • SystemRescueCd 3.6.0
  • Home > Linux > Programming > Libraries

    Meta::Widget::Gtk::Sprite 0.01

    Download button

    No screenshots available
    Downloads: 383  View global page NEW!  Tell us about an update
    User Rating:
    Rated by:
    NOT RATED
    0 user(s)
    Developer:

    License / Price:

    Last Updated:

    Category:
    Jeremy Price | More programs
    Perl Artistic License / FREE
    July 11th, 2006, 15:37 GMT
    ROOT / Programming / Libraries

     Read user reviews (0)  Refer to a friend  Subscribe

    Meta::Widget::Gtk::Sprite description

    Meta::Widget::Gtk::Sprite is a Perl module to do C64 style sprites.

    Meta::Widget::Gtk::Sprite is a Perl module to do C64 style sprites.

    SYNOPSIS
    use Gtk;
    use Gnome;
    init Gnome "test.pl";
    use Meta::Widget::Gtk::Sprite;
    my $mw = new Gtk::Window( "toplevel" );
    my($canvas) = Gnome::Canvas->new() ;
    $mw->add($canvas );
    $canvas->show;
    my $croot = $canvas->root;
    my $sprites = new Meta::Widget::Gtk::Sprite($croot);
    my $p1 = $sprites->create("./player1.xpm", 100, 0);
    $sprites->slide_to_time($p1,5000, 100, 100);
    my $p2 = $sprites->create("./player2.xpm", 0, 0);
    $sprites->slide_to_speed($p2,10, 100, 100);
    $sprites->set_collision_handler(&Bang);
    $mw->show;
    Gtk->main;
    sub Bang
    {
    print "Bang!n";
    exit;
    }

    Sprite is a module to bring back the simple graphics programming of the C64 (hopefully without the lookslikearse component). You can declare pictures to be 'sprites' on the canvas, and then move them around and crash them into each other.

    NOTE
    The canvas is the Gnome::Canvas object. You have to have a Gtk::Canvas object before starting Sprite.

    METHODS
    new Meta::Widget::Gtk::Sprite( $canvas_root );

    The new method takes one argument, the canvas root object for the canvas you want to draw on.

    You may obtain the canvas root from your canvas like this:

    my $croot = $canvas->root;

    $sprite_number = $sprites->create("/path/to/filename", 10, 20);
    Create will load an image file (right now, only xpm format) from disk and make a sprite out of it. The two numbers are the x and y position on the canvas.

    $sprites->show( $sprite_number );
    Makes the sprite appear on the canvas

    $sprites->hide( $sprite_number );
    Make the sprite picture disappear from the canvas. Note that it can still collide with other sprites. If you don't want it to hit anything, move it out of the way or ignore it in your own collision handler.

    $sprites->destroy( $sprite_number );
    Completely destroys a sprite.

    $sprites->move_to( $sprite_number, 10, 20 );
    Teleports the sprite named in $sprite_number to the position given immediately. Contrast slide_to_xxx functions.

    $sprites->slide_to_time( $sprite_number, $time, 10, 20 );
    Will make the sprite $sprite_number 'slide' across the canvas to the position 10, 20. It will take $time seconds to do so. Slow speeds will appear jerky.

    $sprites->slide_to_speed( $sprite_number, $speed, 10, 20);
    Will 'slide' the sprite $sprite_number to the position 10, 20. It will move at a speed of $speed pixels per second.

    $sprites->pos( $sprite_number);
    Returns the x and y coordinates of $sprite_number

    $sprites->velocity( $sprite_number, 5, 6);
    Sets the speed of $sprite_number. The numbers are the x and y speeds. Negative numbers will make the sprite go backwards.

    $sprites->set_collision_handler ( &collision_handler );
    Name a function that will be called when two sprites collide. Note that the collision detection system is extremely crappy right now. It turns out that it is very difficult to efficiently detect collisions.

    Your function will be called like this:

    collision_handler( $sprite_number, $sprite_number);

    where the two sprite numbers are the two sprites that collided. Multiple sprites colliding will cause many collision handler callbacks.

    Note well that if you set the collision handler Sprite.pm will check every single sprite for collisions every animation loop. I haven't optimised this, so you will notice a massive slowdown as you add more sprites.

    To switch collisions checking off, set the handler to undef:

    $sprites->set_collision_handler ( undef );

    Product's homepage

    Requirements:

    · Perl

      


    TAGS:

    GTK widget | GTK sprite | Perl module | Meta::Widget::Gtk::S | Meta | Widget

    Go to top

    WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

    SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM