Welcome to the monastery iraid3r

Anonym pointend you about the fact that $enem is not an object, but maybe this is good for you: if i understand your question correctly you create an object-sprite and want to reuse for many anonymous hashes like $enem (so $enem and company will be not objects).

In this case you have a lot of options: if you isolate,for example, coordinates for the creation of the army into an ArrayofArrays where each element is a pair of x and y. like  @coord_pairs = ( [1,2], [3,7], [5,9]) then you can cycle through them as in:
my @coord_pairs = ( [1,2], [3,7], [5,9]); my @enemy_container; foreach my $index (coord_pairs) { my $enem = { sprite => $enemy_sprite , v_y => $coord_pairs[$index]->[0], # element 0 of the current p +air v_x => $coord_pairs[$index]->[1], # element 1 of the current p +air }; push @enemy_container, $enem; }
As said there a lot of options to deal with lists and arrays: foreach while map shift pop ...

i know nothing about SDL, and dunno if you can reuse the created sprite seveveral times: maybe you need to clone it, or in the worst case you can create a new sprite for each enemy created, even if the png is the same:
my @coord_pairs = ( [1,2], [3,7], [5,9]); my @enemy_container; foreach my $index (coord_pairs) { my $temp_enemy_sprite = SDLx::Sprite->new ( width => $20, height => + $20 ); $enemy_sprite->load('example.png'); my $enem = { sprite => $temp_enemy_sprite , v_y => $coord_pairs[$index]->[0], # element 0 of the current p +air v_x => $coord_pairs[$index]->[1], # element 1 of the current p +air }; push @enemy_container, $enem; }
As little side note, avoid name like $20 for your variables: if you are starting coding choice meaningful name for them as i tried to do in my little example. There is chance to other parts of the program change the value (accidentally) of $20 ending with $20 containing 30. Perl let you to define true constant as described in the docs. In this case you can use constant TWENTY => 20; because number are not allowed as constant name (but you can use _20).

Post clear question to obtain the best from perlmonks. i'm courious to see your gaming attempt anyway.

HtH
L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

In reply to Re: Perl SDL instantiation with Sprites by Discipulus
in thread Perl SDL instantiation with Sprites by iraid3r

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.