implemented collidepoint
[sdlgit/SDL_perl.git] / lib / SDL / Tutorial.pm
CommitLineData
bfd90409 1#!/usr/bin/env perl
2#
3# Tutorial.pm
4#
5# Copyright (C) 2005 David J. Goehrig <dgoehrig@cpan.org>
6#
7# ------------------------------------------------------------------------------
8#
9# This library is free software; you can redistribute it and/or
10# modify it under the terms of the GNU Lesser General Public
11# License as published by the Free Software Foundation; either
12# version 2.1 of the License, or (at your option) any later version.
13#
14# This library is distributed in the hope that it will be useful,
15# but WITHOUT ANY WARRANTY; without even the implied warranty of
16# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17# Lesser General Public License for more details.
18#
19# You should have received a copy of the GNU Lesser General Public
20# License along with this library; if not, write to the Free Software
21# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22#
23# ------------------------------------------------------------------------------
24#
25# Please feel free to send questions, suggestions or improvements to:
26#
27# David J. Goehrig
28# dgoehrig@cpan.org
29#
30
31package SDL::Tutorial;
32
33use strict;
02ddb292 34use warnings;
35
bfd90409 36use SDL;
37use SDL::App;
38
39# change these values as necessary
40my $title = 'My SDL App';
41my ($width, $height, $depth) = ( 640, 480, 16 );
42
43my $app = SDL::App->new(
44 -width => $width,
45 -height => $height,
46 -depth => $depth,
47 -title => $title,
48);
49
50# your code here; remove the next line
51sleep 2;
bfd90409 52
531;
54
55__END__
56
57=head1 NAME
58
59SDL::Tutorial - introduction to Perl SDL
60
61=head1 SYNOPSIS
62
63 # to read this tutorial
64 $ perldoc SDL::Tutorial
65
66 # to create a bare-bones SDL app based on this tutorial
e8ebd102 67 $ perl -MSDL::Tutorial -e 1
bfd90409 68
69=head1 SDL BASICS
70
71SDL, the Simple DirectMedia Layer, is a cross-platform multimedia library.
72These are the Perl 5 bindings. You can find out more about SDL at
73L<http://www.libsdl.org/>.
74
75Creating an SDL application with Perl is easy. You have to know a few basics,
76though. Here's how to get up and running as quickly as possible.
77
78=head2 Surfaces
79
80All graphics in SDL live on a surface. You'll need at least one. That's what
81L<SDL::App> provides.
82
83Of course, before you can get a surface, you need to initialize your video
84mode. SDL gives you several options, including whether to run in a window or
85take over the full screen, the size of the window, the bit depth of your
86colors, and whether to use hardware acceleration. For now, we'll build
87something really simple.
88
89=head2 Initialization
90
91SDL::App makes it easy to initialize video and create a surface. Here's how to
92ask for a windowed surface with 640x480x16 resolution:
93
94 use SDL::App;
95
96 my $app = SDL::App->new(
97 -width => 640,
98 -height => 480,
99 -depth => 16,
100 );
101
102You can get more creative, especially if you use the C<-title> and C<-icon>
103attributes in a windowed application. Here's how to set the window title of
104the application to C<My SDL Program>:
105
106 use SDL::App;
107
108 my $app = SDL::App->new(
109 -height => 640,
110 -width => 480,
111 -depth => 16,
112 -title => 'My SDL Program',
113 );
114
115Setting an icon is a little more involved -- you have to load an image onto a
116surface. That's a bit more complicated, but see the C<-name> parameter to
117C<SDL::Surface->new()> if you want to skip ahead.
118
119=head2 Working With The App
120
121Since C<$app> from the code above is just an SDL surface with some extra sugar,
122it behaves much like L<SDL::Surface>. In particular, the all-important C<blit>
123and C<update> methods work. You'll need to create L<SDL::Rect> objects
124representing sources of graphics to draw onto the C<$app>'s surface, C<blit>
125them there, then C<update> the C<$app>.
126
127B<Note:> "blitting" is copying a chunk of memory from one place to another.
128
129That, however, is another tutorial.
130
131=head1 SEE ALSO
132
133=over 4
134
135=item L<SDL::Tutorial::Drawing>
136
137basic drawing with rectangles
138
139=item L<SDL::Tutorial::Animation>
140
141basic rectangle animation
142
143=item L<SDL::Tutorial::Images>
144
145image loading and animation
146
147=back
148
149=head1 AUTHOR
150
151chromatic, E<lt>chromatic@wgz.orgE<gt>.
152
153Written for and maintained by the Perl SDL project, L<http://sdl.perl.org/>.
154
155=head1 COPYRIGHT
156
157Copyright (c) 2003 - 2004, chromatic. All rights reserved. This module is
158distributed under the same terms as Perl itself, in the hope that it is useful
159but certainly under no guarantee.