Hi
Discipulus, no matter what I do I can't get the red block to move.
I wI was for some method to produce some brick-like piece unable to collide themselves.as for some method to produce some brick-like piece unable to collide themselves.
Try this tag method.
#!/usr/bin/perl
use warnings;
use strict;
use Tk;
my $dx;
my $dy;
my $mw = MainWindow->new;
$mw->geometry("700x600");
my $canvas = $mw->Canvas(-width => 700, -height => 565,
-bg => 'black',
-borderwidth => 3,
-relief => 'sunken',
)->pack;
my $closebutton = $mw->Button(-text => 'Exit', -command => sub{Tk::exi
+t(0)})
->pack;
my $dr = $canvas->createPolygon(0, 20, 50, 20, 50, 75, 0,75,
-fill => 'red',
-tags => ['move','red','paver'],
);
my $db = $canvas->createPolygon(70, 20,
150,20,
150, 75,
70 , 75,
-fill => 'blue',
-tags => ['move','blue','paver'],
);
my $dg = $canvas->createPolygon(200, 20,
250,20,
250, 75,
-fill => 'green',
-tags => ['move','green','paver'],
);
my $dp = $canvas->createPolygon(300, 20,
350,20,
350, 75,
-fill => 'purple',
-tags => ['move','purple','paver'],
);
$canvas->bind('move', '<1>', sub {&mobileStart();});
$canvas->bind('move', '<B1-Motion>', sub {&mobileMove();});
$canvas->bind('move', '<ButtonRelease-1>', sub {&mobileStop();});
MainLoop;
sub mobileStart {
my $ev = $canvas->XEvent;
($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
$canvas->raise('current');
# print "START MOVE-> $dx $dy\n";
}
sub mobileMove {
my $ev = $canvas->XEvent;
# $canvas->bind('current', '<Leave>', sub {&mobileStop();});
+
my @coords_in = $canvas->coords('current');
# print "@coords_in\n";
$canvas->move('current', $ev->x + $dx, $ev->y +$dy);
($dx, $dy) = (0 - $ev->x, 0 - $ev->y);
# print "MOVING-> $dx $dy\n";
my @coords = $canvas->coords('current');
#print "@coords\n";
my (@olaps) = $canvas->find('overlapping', $coords[0],$coords[1]
+,$coords[4],$coords[5], );
foreach my $id(@olaps){
print $canvas->gettags($id),"\t";
}
print "@olaps\n";
print "\n";
if(scalar @olaps > 1){
# Redraw the rect
$canvas->coords('current', @coords_in);
}
}
sub mobileStop{ &mobileMove; }
what happened to the -tile option for canvas? How can I fill canvas objects (rectangles, ovals..) with Photos or advanced grafic?
I don't think there is a canvas -tile option for it's objects. What you would need to do is create canvas image objects of the appropriate size and manipulate them. See Tk ImageMap-color-zones for an example.
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.