Popfly Game Creator API

Modified: 2008/09/04 17:11 by BenAnderson - Categorized as: Game Creator


Edit

Popfly Game Creator API

Table of Contents [Hide/Show]


Popfly Game Creator API
   The Game Object
       Game Object Methods
         GetValue
         SetValue
         PlayAudio
         SpawnActor
         ChangeScene
       Game Object Properties
         MousePosition
         CurrentScene
    Scene Objects
         X
         Y
         XVelocity
         YVelocity
         RotationVelocity
         XAcceleration
         YAcceleration
         XDrag
         YDrag
       Scene Objects Methods
         GetValue
         SetValue
         GetActors
         GetActor
         RemoveEventListener
         AddEventListener
    Actor Objects
       Actor Object Built-In Properties
         X
         Y
         Rotation
         ScaleX
         ScaleY
         XVelocity
         YVelocity
         RotationVelocity
         ScaleXVelocity
         ScaleYVelocity
         XAcceleration
         YAcceleration
         RotationAcceleration
         ScaleXAcceleration
         ScaleYAcceleration
         XDrag
         YDrag
         RotationDrag
         ZIndex
         Mass
         Opacity
       Actor Objects Methods
         GetValue
         SetValue
         GetCenter
         GetCenterY
         GetCenterX
         GetPosition
         GetVisualRoot
         AddEventListener
         RemoveEventListener
         ChangeState
         IsOffScene
         Remove
         currentState

Edit

The Game Object


The game object persists between scenes and is responsible for transitioning between scenes, the instantiation of actors, and game-level properties.

Edit

Game Object Methods

GetValue

Parameters:
PropertyTypeDescription
propertyNameStringName of the property to be retrieved.

Returns:
TypeDescription
Any TypeValue of the specified property


Retrieves a particular property from the current game object.

JavaScript:
var curScore = Game.GetValue("Score");

SetValue

Parameters:
PropertyTypeDescription
propertyNameStringName of the property to be set.
valueAny typeValue of the property.


Set a particular property on the current game object.

JavaScript:
Game.SetValue("Score", Game.GetValue("Score") + 10);

PlayAudio

Parameters:
PropertyTypeDescription
urlStringAddress containing the audio file
repeatbooleanif true, audio repeats indefinitely.


Plays the specified WMA or MP3 file.

SpawnActor

Parameters:
PropertyTypeDescription
paramspropertyBagName of the property to be set.

Returns:
TypeDescription
ActorThe spawned actor.

Params property bag
PropertyTypeDescription
actorStringName of the actor type you would like to spawn
xnumber (optional)x location of the spawned actor
ynumber (optional)y location of the spawned actor
effectproperty bagcontains 2 boolean flags, scale and fade.
Spawns the an actor specified by the parameter onto the current scene.

ChangeScene

Parameters:
PropertyTypeDescription
newSceneNameStringThe name of the scene to change to.


Changes the scene to the one specified.

Edit

Game Object Properties

MousePosition

Contains two subproperties: X and Y. They together describe the current location of the mouse relative to the scene.


JavaScript:
var curMouseX = Game.MousePosition.X;
var curMouseY = Game.MousePosition.Y;

CurrentScene

A reference to the current active scene (ie. Intro, Main or Lost)

Edit

Scene Objects

Scene object encapulates a particular scene in the game. Like the game object, they can also have properties. However their properties only persist over the duration of the scene.

Another thing differencating scene objects and the game object is that you first need to get a reference to the scene (through something like Game.CurrentScene).


X

TypeDescription
floating-point numberDistance from the left side of the scene in Silverlight "pixels" to the current position of the left side of the viewport.

Y

TypeDescription
floating-point numberDistance from the top side of the scene in Silverlight "pixels" to the current positiion of the top side of the viewport.

XVelocity

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second the viewport is moving (get) or to move (set) to the right (positive values) or left (negative values). Changes from frame to frame based on XDrag (see XDrag for more info).

YVelocity

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second the viewport is moving (get) or to move (set) to the bottom (positive values) or top (negative values). Changes from frame to frame based on YDrag (see YDrag for more info).

RotationVelocity

TypeDescription
floating-point numberNumber of degrees per second the viewport is moving (get) or to move (set) clockwise (positive values) or counter-clockwise (negative values). Changes from frame to frame based on RotationDrag (see XDrag for more info).

XAcceleration

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second more the viewport is moving (get) or to move (set) to the right per second (positive values) or left per second (negative values). Reset to 0 every frame unless set during that frame.

YAcceleration

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second more the viewport is moving (get) or to move (set) to the bottom (positive values) or top (negative values). Reset to 0 every frame unless set during that frame.

XDrag

TypeDescription
floating-point number from 0 to 1.0Conceptually, drag is what slows things down when they start moving. In Popfly Game Creator, XDrag refers to a multiplier against XVelocity which is applied as an acceleration in the opposite direction of XVelocity (for example, if XDrag is 0.5, and you are moving right at a speed of 100, an acceleration of 50 will be applied opposite the direction you are moving to slow you down). If XDrag is 0, motion will continue in the left-right directions at the same speed until something occurs to change it. If XDrag is 1, we treat acceleration specially. When XDrag is 1, motion should be frozen by the normal rules, but instead, we apply your acceleration value directly to velocity so that if you attempt apply an XAcceleration of 500, you will move right at 500 Silverlight pixels a second.

YDrag

TypeDescription
floating-point number from 0 to 1.0See XDrag

Edit

Scene Objects Methods

GetValue

Parameters:
PropertyTypeDescription
propertyNameStringName of the property to be retrieved.

Returns:
TypeDescription
Any TypeValue of the specified property

Retrieves a particular property from the scene.

JavaScript:
var curScene = Game.CurrentScene;
var curSceneX= curScene .GetValue("X");

SetValue

Parameters:
PropertyTypeDescription
propertyNameStringName of the property to be set.
valueAny typeValue of the property.


Set a particular property on the scene.

JavaScript:
var curScene = Game.CurrentScene;
curScene.SetValue("X", 5);



GetActors

Parameters:
PropertyTypeDescription
ActorsStringActor Name

Returns:
TypeDescription
List of ActorsList of all currently active instances of the Actor whose name is passed in.

Retrieves a list of actor instances based on the list of actor names passed in.

JavaScript:
var curScene = Game.CurrentScene;
var actors = curScene.GetActors(["Spaceship 1", "Spaceship 2"]);


GetActor

Parameters:
PropertyTypeDescription
ActorStringactor name to retrieve

Returns:
TypeDescription
Actorretrieved actor based on the actor name passed in

Retrieves an actor based on the actor name passed in.

JavaScript:
var curScene = Game.CurrentScene;
var actor = curScene.GetActor("Spaceship 1");


RemoveEventListener


AddEventListener


Edit

Actor Objects


Edit

Actor Object Built-In Properties

X

TypeDescription
floating-point numberDistance from the left side of the scene in Silverlight "pixels"

Y

TypeDescription
floating-point numberDistance from the top side of the scene in Silverlight "pixels"

Rotation

TypeDescription
floating-point numberNumber of degrees clockwise from the straight up an actor is turned.

ScaleX

TypeDescription
floating-point numberA multiplier against the original width of the actor. The actor will display with ScaleX * original width as its width. That is, when ScaleX is 1.0, the actor's width is unchanged, when ScaleX is 0.5, it will be half its original width and when ScaleX is 2.0, it will be twice its original width.

ScaleY

TypeDescription
floating-point numberA multiplier against the original height of the actor. The actor will display with ScaleY * original height as its height. That is, when ScaleY is 1.0, the actor's height is unchanged, when ScaleY is 0.5, it will be half its original height and when ScaleY is 2.0, it will be twice its original height.

XVelocity

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second the actor is moving (get) or to move (set) to the right (positive values) or left (negative values). Changes from frame to frame based on XDrag (see XDrag for more info).

YVelocity

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second the actor is moving (get) or to move (set) to the bottom (positive values) or top (negative values). Changes from frame to frame based on YDrag (see YDrag for more info).

RotationVelocity

TypeDescription
floating-point numberNumber of degrees per second the actor is moving (get) or to move (set) clockwise (positive values) or counter-clockwise (negative values). Changes from frame to frame based on RotationDrag (see XDrag for more info).

ScaleXVelocity

TypeDescription
floating-point numberAmount per second the actor is scaling (get) or to scale (set) along the actor's width / X-axis. Changes from frame to frame based on ScaleDrag (see XDrag for more info).

ScaleYVelocity

TypeDescription
floating-point numberAmount per second the actor is scaling (get) or to scale (set) along the actor's width / Y-axis. Changes from frame to frame based on ScaleDrag (see XDrag for more info).

XAcceleration

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second more the actor is moving (get) or to move (set) to the right per second (positive values) or left per second (negative values). Reset to 0 every frame unless set during that frame.

YAcceleration

TypeDescription
floating-point numberNumber of Silverlight "pixels" per second more the actor is moving (get) or to move (set) to the bottom (positive values) or top (negative values). Reset to 0 every frame unless set during that frame.

RotationAcceleration

TypeDescription
floating-point numberNumber of degrees per second more the actor is moving (get) or to move (set) clockwise(positive values) or counterclockwise (negative values). Reset to 0 every frame unless set during that frame.

ScaleXAcceleration

TypeDescription
floating-point numberAmount per second more the actor is scaling(get) or to scale (set) along the X-axis. Reset to 0 every frame unless set during that frame.

ScaleYAcceleration

TypeDescription
floating-point numberAmount per second more the actor is scaling(get) or to scale (set) along the Y-axis. Reset to 0 every frame unless set during that frame.

XDrag

TypeDescription
floating-point number from 0 to 1.0Conceptually, drag is what slows things down when they start moving. In Popfly Game Creator, XDrag refers to a multiplier against XVelocity which is applied as an acceleration in the opposite direction of XVelocity (for example, if XDrag is 0.5, and you are moving right at a speed of 100, an acceleration of 50 will be applied opposite the direction you are moving to slow you down). If XDrag is 0, motion will continue in the left-right directions at the same speed until something occurs to change it. If XDrag is 1, we treat acceleration specially. When XDrag is 1, motion should be frozen by the normal rules, but instead, we apply your acceleration value directly to velocity so that if you attempt apply an XAcceleration of 500, you will move right at 500 Silverlight pixels a second.

YDrag

TypeDescription
floating-point number from 0 to 1.0See XDrag

RotationDrag

TypeDescription
floating-point number from 0 to 1.0See XDrag

ZIndex

TypeDescription
numberZIndex determines which actors to draw on top of which other actors. Any actor with a lower ZIndex will get drawn behind an actor with a higher ZIndex. If both actors have the same ZIndex, the one added to the scene last will be drawn on top.

Mass

TypeDescription
numberMass determines which actor to move during a collision. The actor with the lower mass will be moved while the actor with higher mass will continue moving (or remaining stationary) as it was. If both actors have equal mass, the one moving faster will push the slower moving actor.

Opacity

TypeDescription
number from 0 to 1Opacity determines the transparency of an actor. When Opacity is 1, nothing behind the actor will be visible. When Opacity is 0, the actor will be invisible and you will only see what is behind it. The closer to 1 the less of what is behind an actor you will see and the closer to 0, the more.

Edit

Actor Objects Methods

GetValue

Parameters:
PropertyTypeDescription
propertyNameStringName of the property to be retrieved.

Returns:
TypeDescription
Any TypeValue of the specified property

Retrieves a particular property from the actor.

JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorX= curActor.GetValue("X");

SetValue

Parameters:
PropertyTypeDescription
propertyNameStringName of the property to be set.
valueAny typeValue of the property.


Set a particular property on the actor.

JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
curActor.SetValue("X", 5);



GetCenter

Returns:
TypeDescription
PointLocation of the center point of the actor relative to the scene. Contains the X and Y component.

Retrieves the center point of the actor

JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorX= curActor.GetCenter().X;

GetCenterY

Returns:
TypeDescription
IntegerLocation of the center point, the Y value, of the actor relative to the scene.

Retrieves the Y value of the center point of the actor

JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorY= curActor.GetCenterY();

GetCenterX

Returns:
TypeDescription
IntegerLocation of the center point, the X value, of the actor relative to the scene.

Retrieves the X value of the center point of the actor

JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorX= curActor.GetCenterX();

GetPosition

Returns:
TypeDescription
PointLocation of the top left point of the actor relative to the scene. Contains the X and Y component.

Retrieves the top left point of the actor

JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorX= curActor.GetPosition().X;

GetVisualRoot

Returns:
TypeDescription
Silverlight ElementRoot canvas of the actor

Retrieves the root canvas of the actor


AddEventListener


RemoveEventListener


ChangeState

Parameters:
PropertyTypeDescription
newStateNameStringThe name of the stateto change to.


Changes the state to the one specified.

IsOffScene

Returns:
TypeDescription
Booleantrue if the actor is currently off-screen


Check if the actor is currently offscreen.

Remove

Parameters:
PropertyTypeDescription
effectproperty bagcontains 2 boolean flags, scale and fadein.


Removes the actor from the scene with the specified effect

currentState

Object:
PropertyTypeDescription
namestringcontains the actuale name of the state.
widthintegerContains the width of the Actor in this state.
heightintegerContains the height of the Actor in this state.
isSolidbooleanReturns true or false wether the Actor is an solid.
xamlstringReturns the complete XAML value for this state.
egdesuknownunknown


Returns an object with the above properties.

JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var currentState = curActor.currentState.name;

Privacy. Terms of Use. Trademarks.
ScrewTurn Wiki version 2.0.22. Some of the icons created by FamFamFam.