Programming games - PowerPoint PPT Presentation

1 / 23
About This Presentation
Title:

Programming games

Description:

If your player is inputting a speed or an angle, your code must convert this ... Can use Adobe Flash Media Encoder (part of the Adobe CS4 package) to take one ... – PowerPoint PPT presentation

Number of Views:51
Avg rating:3.0/5.0
Slides: 24
Provided by: Jeanin
Category:

less

Transcript and Presenter's Notes

Title: Programming games


1
Programming games
  • Registration experiment. Drawing.
  • Equations of motion.
  • Video.
  • Homework Finish cannonball. Start Video.

2
Registration/origin
  • Defines the position of a movie clip
  • Origin and transform point may be different. Can
    adjust either one.
  • Not necessarily the center of occupied pixels of
    the object
  • YOU decide where you want that to be.
  • Remember if/when you change a symbol in the
    Library, it changes everywhere!
  • unlike changing the contents of a frame

3
Advice
  • Experiment
  • create simple movie clips in the Library
  • Brush size. Stroke vs Fill.
  • Move/make instances of them to the Stage
  • Observe the positions (X, Y) in the Property
    Panel
  • Notice the origin (cross-hairs) and the
    transformation point (empty circle)
  • Write trace statements to reveal positions
    (properties .x and .y)

4
Equations of motion
  • displacement time velocity
  • Traveling 20 miles/hour for 2 hours
  • 40 miles
  • Traveling 30 miles/hour for .5 hours???
  • Traveling 40 miles/hour for .75 hours???

5
Equations of motion
  • change in velocity time acceleration
  • Traveling at 30 miles/hour, accelerating
    (changing velocity) 2mile/hour/minute, then after
    5 minutes, now going 30 10 miles/hour 40
    miles/hour

6
Discrete calculations
  • Going one speed at the start of an interval and a
    different speed at the end, calculate
    displacement using the average
  • displacement
  • time (vspeed1 vspeed2).5

7
Ballistics
  • Initial movement
  • cannonball leaves cannon at initial speed and
    direction ('at an angle')
  • BUT we can only move things by moving them
    horizontally and vertically!
  • Also, the vertical velocity will change because
    of gravity

8
Syntax note
  • The brackets make multiple statements the
    equivalent of a single statement
  • You may see
  • if (condition) statement
  • But using the brackets means you won't make a
    mistake if/when you add a statement
  • if (condition)

9
Data types
  • Numbers are not character strings (text)
  • The number 12 is different from '12'.
  • The latter is the character string numeral 1
    followed by numeral 2.
  • Contents of text boxes are text, that is,
    character strings.
  • If your player is inputting a speed or an angle,
    your code must convert this to a number.
  • Multiplying will do it! (and you probably didn't
    notice that a conversion (also called a cast) was
    taking place.

10
Compiling
  • The Flash program translates / combines all the
    coding to make the thing that runs (the .swf
    file).
  • This translation process is called compiling.
    Errors found during it are called compiler
    errors.
  • Publishing is doing the translation and producing
    an .html file and a .swf file. You upload both
    (plus in certain situations another file) to the
    server. Links are to the .html file.

11
Flash .swf files
  • are relatively small because
  • they make use of the Flash plugin. The code in
    your program includes calls to routines in the
    plugin.
  • Much of the graphics may be vector graphics
    stored as formulas and not bit maps.
  • Check out the file sizes.

12
Common problems
  • Copying and pasting anything that looks like code
    from tutorial to your project.
  • NOT naming things or being inconsistent.
  • Instance name is what matters for the coding
  • If there are compiler errors, it will not work.

13
Video in Flash
  • More than one way to incorporate video into Flash
  • bring in whole video that plays along with the
    frames. We will not use this way!
  • For this class, we will use a FLVPlayback object
  • Requires an import statement
  • This allows shorthand names for built-in parts of
    ActionScript
  • Requires statement adding to Display list
  • Objects created in code (as opposed to put
    directly on the Stage) need to be added to the
    Display list to be shown.

14
Videos
  • Different types of videos (like different types
    of images)
  • Flash video playback requires videos of type .flv
  • Can use Adobe Flash Media Encoder (part of the
    Adobe CS4 package) to take one type of video and
    produce an flv

15
Basic coding
  • import fl.video. //get the builtin classes
  • var flvFLVPlayback //set up variable
  • flv new FLVPlayback() //give it a value
  • flv.source "dickey2.flv" //set source attribute
  • flv.x 10 //position on screen horizontally
  • flv.y 10 // and vertically
  • addChild(flv) // make visible by adding to
    // Display list

16
addChild
  • Adds to the Display list.
  • In my tutorials, you also will seecanvass.addChil
    d(stuff)
  • This adds the newly created stuff object as a
    child of canvass. This will determine the
    positioning of stuff.

17
Skins
  • These are the video clip controls.
  • Appropriate when you want to give the
    player/user/customer more controls
  • You may choose NOT to give user control in
    certain cases
  • Many choices
  • USE HELP!
  • Requires you to upload an .swf file to the
    server.

18
Files for your application
  • Your application will consist of the following
    files. Say your application is called mywork.fla
  • mywork.html
  • mywork.sw
  • For each video f1.flv, f2.flv, etc. The names
    f1, f2, need to be replaced by the names you gave
    the video. (Remember no blanks!)
  • For each skin the name of the skin file
    xxxx.swf

19
Video examples
  • Play back single video
  • Play back choice of video (two ways)
  • Bouncing Ball
  • Used mask to make the playback a circle
  • Jigsaw puzzle turning into video
  • ???

20
Ballot example
  • I had a request from stranger Sunday before
    election
  • Radio buttons
  • SharedObject
  • This is the equivalent of cookies a way to store
    data on the client (player) computer.
  • Dynamically created text field

21
Consider
  • You can use SharedObject to save information on
    the client (user, player, customer) computer.
  • Score (last score)
  • Video choice
  • Name

22
Video
  • Use camera
  • Need to upload
  • If not .flv, use Flash Media encoder to made an
    .flv
  • Use keepvid.com (or other sites) to download
    video from YouTube
  • Note I prefer you to use your own. If you use
    someone else's, you must make 'value-add' to the
    project.

23
Homework
  • Finish Cannonball (Due in 1 week)
  • Start Video project. Do something simple. You can
    build on it for the final project.
  • Buttons for choosing
  • With or without skin
  • With saving using SharedObject
  • Video as part of other project
  • Bouncing ball
  • Rock-paper-scissors
  • Cannonball
  • ??? Ask me for help
Write a Comment
User Comments (0)
About PowerShow.com