Actionscript 2 - PowerPoint PPT Presentation

1 / 16
About This Presentation
Title:

Actionscript 2

Description:

If it is clicked on, the alien explodes. A green alien moves across the stage. ... If it is clicked on, the alien explodes on alien mc ... – PowerPoint PPT presentation

Number of Views:97
Avg rating:3.0/5.0
Slides: 17
Provided by: CathE61
Category:

less

Transcript and Presenter's Notes

Title: Actionscript 2


1
Actionscript 2
  • Variables Game Planning

2
What is a variable
  • A variable is simply a name that STANDS FOR
    something.hi-score1033nameCatherine
    StonesIn Actionscript the above code would
    assign the value 1033 to the term hi-score

3
Variable names
  • NO SPACES
  • No Punctuation except underscores and dashes.

4
Why we need variables
  • SPEED Its quicker to type name, than it is
    Catherine Stones
  • FLEXIBILITY A high score might changea
    variable, wherever it is in the code, stands for
    the high score. Adjust the score, and the
    variable value is updated.

5
Variable Types main variables
  • _root.mynamecatherine
  • ANYWHERE in your code, if you write _root.myname
    flash will read Catherine.
  • _root. before a variable name means the variable
    belongs to the maintimeline.

6
Variables specific to each movieclip
  • onClipEvent(load)pointvalue50on(press)_r
    oot.mytotal_root.mytotalpointvalue
  • This code, would add 50 to the total score when
    this movieclip was clicked on.

7
Getting variable values to show on the stage
  • You need a DYNAMIC TEXT BOX.
  • You need to assign the DYNAMIC TEXT BOX to a
    VARIABLE VALUE..i.e. _root.totalscore.
  • Do this in the properties box.
  • Hey presto screen info that can CHANGE
    dynamically.

8
Adding Variables
  • _root.number15_root.number210_root.total_ro
    ot.number1_root.number2What would be stored in
    _root.total?

9
Adding an increment to a variable
  • _root.myscoreAdds 1 to the
    score_root.myscore
  • Subtracts 1 from the score

10
Puzzle
  • Make a button so that every time you click on it
    a number displayed on the stage goes up by 1 in
    value.
  • This is a really primitive GAME!

11
Approaches to Game Design
  • So you have EVENTS which run at certain times
    (on(press))
  • You have MOVIECLIPS which can be controlled,
    moved, rotated, with code.
  • You have VARIABLES which can store scores and
    whose values can be changed.
  • But what about a GAME?

12
WARNING there is NO GAMING CODE
  • There is no actionscript for actions
    likefollow enemy, or dont walk into walls.
  • EVERYTHING HAS TO BE CARVED FROM BASIC BUILDING
    BLOCKS.
  • IF thisdo this.Do this5 times.Change the
    movieclips horizontal location

13
Game Design Step 1
  • In English, write down all the things you want to
    happen
  • i.e. A red alien moves across the stage.If it
    is clicked on, your score goes up.If it is
    clicked on, the alien explodes.A green alien
    moves across the stage.If it is clicked on, your
    score goes down.

14
Game Design Step 2
  • Identify what has to happen continuously, and
    what happens once, or when buttons pressed.
  • This tells you what type of event the code should
    be in.
  • i.e. A red alien moves across the stage.If it
    is clicked on, your score goes up.If it is
    clicked on, the alien explodes.A green alien
    moves across the stage.If it is clicked on, your
    score goes down.

Continuously so in onClipEvent(enterframe)
When pressed so in on(press)
Continuously so in onClipEvent(enterframe)
When pressed so in on(press)
15
Game Design Step 3
  • Identify where the code could go.
  • On which movieclip? On the frame?
  • i.e. A red alien moves across the stage any
    mcIf it is clicked on, your score goes up on
    alien mc.If it is clicked on, the alien explodes
    on alien mcA green alien moves across the
    stage any mcIf it is clicked on, your score
    goes down on alien mc

16
Puzzle in the Lab
  • Create two squares, when you click on ONE the
    score displayed on the screen goes UP, when you
    click on another the score goes down. The
    beginning score should be 10.
  • AND start to flow chart, list the actions in your
    game. Break game down into chunks.Consider the
    potential pitfalls of each sequence.
Write a Comment
User Comments (0)
About PowerShow.com