This wiki has been moved to https://github.com/SuperTux/wiki into the mediawiki branch.

Difference between revisions of "ScriptingScriptedObject"

From SuperTux
Jump to: navigation, search
(Methods)
Line 40: Line 40:
 
|colspan="2" class="title"| Methods
 
|colspan="2" class="title"| Methods
 
|-
 
|-
! class="method" set_animation(string animation_name)
+
! class="method"| set_animation(string animation_name)
 
| Activates the sprite's animation specified in <tt>animation_name</tt>.
 
| Activates the sprite's animation specified in <tt>animation_name</tt>.
 
|-
 
|-
! class="method" get_animation()
+
! class="method"| get_animation()
 
| Returns the name of the sprite's current animation.
 
| Returns the name of the sprite's current animation.
 
|-
 
|-
! class="method" move(float x, float y)
+
! class="method"| move(float x, float y)
 
| Moves the object by <tt>x</tt> units to the right and <tt>y</tt> down relative to its current position.
 
| Moves the object by <tt>x</tt> units to the right and <tt>y</tt> down relative to its current position.
 
|-
 
|-
! class="method" set_pos(float x, float y)
+
! class="method"| set_pos(float x, float y)
 
| Basically identical to <tt>move</tt>, except its relativity to the sector origin.
 
| Basically identical to <tt>move</tt>, except its relativity to the sector origin.
 
|-
 
|-
! class="method" get_pos_x()
+
! class="method"| get_pos_x()
 
| Returns the X coordinate of the object's position.
 
| Returns the X coordinate of the object's position.
 
|-
 
|-
! class="method" get_pos_y()
+
! class="method"| get_pos_y()
 
| Returns the Y coordinate of the object's position.
 
| Returns the Y coordinate of the object's position.
 
|-
 
|-
! class="method" set_velocity(float x, float y)
+
! class="method"| set_velocity(float x, float y)
 
| Makes the object move in a certain direction (with a certain speed) given by the <tt>x</tt> and <tt>y</tt> coordinates.
 
| Makes the object move in a certain direction (with a certain speed) given by the <tt>x</tt> and <tt>y</tt> coordinates.
 
|-
 
|-
! class="method" get_velocity_x()
+
! class="method"| get_velocity_x()
 
| Returns the X coordinate of the object's velocity.
 
| Returns the X coordinate of the object's velocity.
 
|-
 
|-
! class="method" get_velocity_y()
+
! class="method"| get_velocity_y()
 
| Returns the Y coordinate of the object's velocity.
 
| Returns the Y coordinate of the object's velocity.
 
|-
 
|-
! class="method" set_visible(bool visible)
+
! class="method"| set_visible(bool visible)
 
| Shows or hides the object according to the value of <tt>visible</tt>.
 
| Shows or hides the object according to the value of <tt>visible</tt>.
 
|-
 
|-
! class="method" is_visible()
+
! class="method"| is_visible()
 
| Returns true if the object is visible, false otherwise.
 
| Returns true if the object is visible, false otherwise.
 
|-
 
|-
! class="method" get_name()
+
! class="method"| get_name()
 
| Returns the name of the object
 
| Returns the name of the object
 
|}
 
|}

Revision as of 07:18, 17 April 2006

Summary

A ScriptedObject is basically a SuperTux object that can be scripted to move around and animate. You can created ScriptedObjects by defining them in level files. Each scripted object will be exposed under its name to the scripting engine.

Example

Example of a definition:

  (scriptedobject
    (x 2291)
    (y 1275)
    (name "SUPERTUX")
    (sprite "images/creatures/tux_big/tux.sprite")
    (layer 100)
    (visible #t)
    (physic-enabled #t)
    (solid #t)
  ) 
 

The above object will be exposed under the name SUPERTUX in the scripting engine. Example usage:

  // This script will make tux look and walk left/right (this should make him appear
  //   "upset")
  SUPERTUX.set_action("stand-right");
  wait(2);
  SUPERTUX.set_velocity(200,0);
  wait(0.3);
  SUPERTUX.set_velocity(0,0);
  wait(0.4);
  SUPERTUX.set_action("stand-left");
  SUPERTUX.set_velocity(-200,0);
  wait(0.3);
 

Methods

Methods
set_animation(string animation_name) Activates the sprite's animation specified in animation_name.
get_animation() Returns the name of the sprite's current animation.
move(float x, float y) Moves the object by x units to the right and y down relative to its current position.
set_pos(float x, float y) Basically identical to move, except its relativity to the sector origin.
get_pos_x() Returns the X coordinate of the object's position.
get_pos_y() Returns the Y coordinate of the object's position.
set_velocity(float x, float y) Makes the object move in a certain direction (with a certain speed) given by the x and y coordinates.
get_velocity_x() Returns the X coordinate of the object's velocity.
get_velocity_y() Returns the Y coordinate of the object's velocity.
set_visible(bool visible) Shows or hides the object according to the value of visible.
is_visible() Returns true if the object is visible, false otherwise.
get_name() Returns the name of the object

Constants

None