EditPopfly Game Creator API
EditThe Game Object
The game object persists between scenes and is responsible for transitioning between scenes, the instantiation of actors, and game-level properties.
EditGame Object Methods
GetValue
Parameters:
| Property | Type | Description |
| propertyName | String | Name of the property to be retrieved. |
Returns:
| Type | Description |
| Any Type | Value of the specified property |
Retrieves a particular property from the current game object.JavaScript:
var curScore = Game.GetValue("Score");
SetValue
Parameters:
| Property | Type | Description |
| propertyName | String | Name of the property to be set. |
| value | Any type | Value of the property. |
Set a particular property on the current game object.JavaScript:
Game.SetValue("Score", Game.GetValue("Score") + 10);
PlayAudio
Parameters:
| Property | Type | Description |
| url | String | Address containing the audio file |
| repeat | boolean | if true, audio repeats indefinitely. |
Plays the specified WMA or MP3 file.
SpawnActor
Parameters:
| Property | Type | Description |
| params | propertyBag | Name of the property to be set. |
Returns:
| Type | Description |
| Actor | The spawned actor. |
Params property bag
| Property | Type | Description |
| actor | String | Name of the actor type you would like to spawn |
| x | number (optional) | x location of the spawned actor |
| y | number (optional) | y location of the spawned actor |
| effect | property bag | contains 2 boolean flags, scale and fade. |
Spawns the an actor specified by the parameter onto the current scene.
ChangeScene
Parameters:
| Property | Type | Description |
| newSceneName | String | The name of the scene to change to. |
Changes the scene to the one specified.
EditGame 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)
EditScene 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
| Type | Description |
| floating-point number | Distance from the left side of the scene in Silverlight "pixels" to the current position of the left side of the viewport. |
Y
| Type | Description |
| floating-point number | Distance from the top side of the scene in Silverlight "pixels" to the current positiion of the top side of the viewport. |
XVelocity
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number from 0 to 1.0 | Conceptually, 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
| Type | Description |
| floating-point number from 0 to 1.0 | See XDrag |
EditScene Objects Methods
GetValue
Parameters:
| Property | Type | Description |
| propertyName | String | Name of the property to be retrieved. |
Returns:
| Type | Description |
| Any Type | Value of the specified property |
Retrieves a particular property from the scene.JavaScript:
var curScene = Game.CurrentScene;
var curSceneX= curScene .GetValue("X");
SetValue
Parameters:
| Property | Type | Description |
| propertyName | String | Name of the property to be set. |
| value | Any type | Value of the property. |
Set a particular property on the scene.JavaScript:
var curScene = Game.CurrentScene;
curScene.SetValue("X", 5);
GetActors
Parameters:
| Property | Type | Description |
| Actors | String | Actor Name |
Returns:
| Type | Description |
| List of Actors | List 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:
| Property | Type | Description |
| Actor | String | actor name to retrieve |
Returns:
| Type | Description |
| Actor | retrieved 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");
EditActor Objects
EditActor Object Built-In Properties
X
| Type | Description |
| floating-point number | Distance from the left side of the scene in Silverlight "pixels" |
Y
| Type | Description |
| floating-point number | Distance from the top side of the scene in Silverlight "pixels" |
Rotation
| Type | Description |
| floating-point number | Number of degrees clockwise from the straight up an actor is turned. |
ScaleX
| Type | Description |
| floating-point number | A 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
| Type | Description |
| floating-point number | A 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Amount 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
| Type | Description |
| floating-point number | Amount 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Number 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
| Type | Description |
| floating-point number | Amount 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
| Type | Description |
| floating-point number | Amount 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
| Type | Description |
| floating-point number from 0 to 1.0 | Conceptually, 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
| Type | Description |
| floating-point number from 0 to 1.0 | See XDrag |
RotationDrag
| Type | Description |
| floating-point number from 0 to 1.0 | See XDrag |
ZIndex
| Type | Description |
| number | ZIndex 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
| Type | Description |
| number | Mass 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
| Type | Description |
| number from 0 to 1 | Opacity 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. |
EditActor Objects Methods
GetValue
Parameters:
| Property | Type | Description |
| propertyName | String | Name of the property to be retrieved. |
Returns:
| Type | Description |
| Any Type | Value 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:
| Property | Type | Description |
| propertyName | String | Name of the property to be set. |
| value | Any type | Value of the property. |
Set a particular property on the actor.JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
curActor.SetValue("X", 5);
GetCenter
Returns:
| Type | Description |
| Point | Location of the center point of the actor relative to the scene. Contains the X and Y component. |
Retrieves the center point of the actorJavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorX= curActor.GetCenter().X;
GetCenterY
Returns:
| Type | Description |
| Integer | Location of the center point, the Y value, of the actor relative to the scene. |
Retrieves the Y value of the center point of the actorJavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorY= curActor.GetCenterY();
GetCenterX
Returns:
| Type | Description |
| Integer | Location of the center point, the X value, of the actor relative to the scene. |
Retrieves the X value of the center point of the actorJavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorX= curActor.GetCenterX();
GetPosition
Returns:
| Type | Description |
| Point | Location 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 actorJavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var curActorX= curActor.GetPosition().X;
GetVisualRoot
Returns:
| Type | Description |
| Silverlight Element | Root canvas of the actor |
Retrieves the root canvas of the actor
ChangeState
Parameters:
| Property | Type | Description |
| newStateName | String | The name of the stateto change to. |
Changes the state to the one specified.
IsOffScene
Returns:
| Type | Description |
| Boolean | true if the actor is currently off-screen |
Check if the actor is currently offscreen.
Remove
Parameters:
| Property | Type | Description |
| effect | property bag | contains 2 boolean flags, scale and fadein. |
Removes the actor from the scene with the specified effect
currentState
Object:
| Property | Type | Description |
| name | string | contains the actuale name of the state. |
| width | integer | Contains the width of the Actor in this state. |
| height | integer | Contains the height of the Actor in this state. |
| isSolid | boolean | Returns true or false wether the Actor is an solid. |
| xaml | string | Returns the complete XAML value for this state. |
| egdes | uknown | unknown |
Returns an object with the above properties.JavaScript:
var curActor = Game.CurrentScene.GetActor("Spaceship 1");
var currentState = curActor.currentState.name;