Lesson 6 - Creating Objects - Teacher's Guide: Cover The Topics Under Discussion Notes (Page 2)
Lesson 6 - Creating Objects - Teacher's Guide: Cover The Topics Under Discussion Notes (Page 2)
http://www.stencyl.com/teach/act6/
Overview
Introduce students to the idea of creating new actors (objects). Talk about the differences
between Actor Types and Actor Instances (Class vs. Object).
Outcome
Through the activity, students will create new actors (objects) on the fly, thereby further
developing their understanding of behaviors and code reuse.
Stencyl Educator’s Kit Lesson 6 1
Discussion Notes
Up until this point, students have been working with actors already placed inside a scene.
Now, they’ll learn how to create new actors on the fly and how to manipulate them.
Use the following block under Scene > Actors to create a new Actor.
The Actor Type is the kind of Actor you want to create. You can either choose a specific
Actor Type, or in some cases, you can plug in an Actor Type attribute, thereby letting you
change the kind of Actor Type that is created on a case-by-case basis.
X and Y represent the position, in absolute coordinates, at which to create the actor.
The final dropdown represents the drawing layer to place the actor on. Leave this at
Front.
You’ll quickly discover that you’ll want to refer to the actor you just created. For example, if
you want to set its speed (to make it move).
You may have noticed by now that many blocks that work with Actors have a dropdown
field that says Self.
Blocks that work with Actors need to know which actor they are referring to. Self
refers to the Actor to which the behavior is attached. For our Hero with a Walking
behavior, Self refers to the Hero.
Stencyl Educator’s Kit Lesson 6 2
Last Created Actor lets us refer to the Actor we just created.
Putting this all together, here’s an example where a bullet actor is created and given an
initial speed to move at.
Aside: The game may crash or act unpredictably if you attempt to use Last Created Actor before any
Actors have been created by you. Similarly, if you kill an actor that you just created and use Last Created
Actor, the game may crash.
Further Discussion: For more advanced classes, you may want to go over using Attributes to store
Actors for referencing in the future.
Stencyl Educator’s Kit Lesson 6 3