Version Française English Version [ Xtras for Macromedia Director ]  

Last Updates Last Updates
 
Xtras Xtras
o
o
o
o
o
3D-UDI
BinFileIO
Joystick
SetMouseLoc
PointInside...
 
Shockwave Demo Shockwave
 o
o
o
o
Jeu de la Vie
Arbre
The Legend of Zelda
Zelda Breakout
 
3D Lingo Lingo 3D
 o
o
o
o
Model Highlighter
Text On Screen
Text To Texture
Animated Texture
 
3D Lingo Lingo
 o


Save an image to disk
 
3D Lingo Pogopixels - Widgets, Flash and Web Applications

Laurent Cozic,

Last updated on Thursday, 18 May, 2006


Xtra: 3D User Data Inspector

Xtra: BinFileIO -- Binary File Input / Output

Xtra: Joystick -- Game Device control

Xtra: SetMouseLoc -- To set the mouse location

Xtra: PointInsidePolygon -- To check if a point is inside a polygon

You'll find on this page some free Xtras for Macromedia Director. They have been made and tested under Windows and so should be compatible with this system.

18/05/06 - These Xtras are now open source.

As I don't really have time anymore to improve or debug these Xtras I've decided to make them open source under the GNU General Public Licence. Should you want to have a look at them, the most asked features are: the support for two joysticks and point of view for the Joystick Xtra; and some bug fixes for binFileIO Xtra (there seems to be a random bug when closing a file). The source codes might need some more comments although most of it should be self-explanatory. If not please feel free to contact me and I'll try to help. Each source code archive also includes a Director movie for testing purpose.


ShockwaveXtra 3D User Data Inspector

3D User Data Inspector is a cross-plateform Dcr-Xtra that allows monitoring the values of the #userData property of all the models, cameras and lights in a given 3D member. It builds a userData table and updates it in real-time. The aim of UDI is mainly to facilitate the debugging of scenes that use a lot the #userData property (in the case of a game engine for example).

To install it, copy the .dcr file at the root of the Xtras directory. UDI will then be accessible via the Xtras menu of the Director authoring environment.

Download 3D User Data Inspector (20K)


Xtra BinFileIO

BinFileIO allows binary file input / output from Lingo. It supports most of data types (signed and unsigned short, char and long as well as floating point numbers (float and double)) and can also read or write Lingo integer or float lists or strings.

Download BinFileIO Xtra (120 K)

Download BinFileIO Xtra Source Code

Available functions:

Name Description Input Output
openFile Open a file <string> file name
<integer> mode:
1: read only
2: write / read
3: write / read. If the file exists its content is erased prior to opening.
<symbol> result:
#ok
#errorOpeningFile
closeFile Close the file (no input) <symbol> result:
#ok
#errorClosingFile
readNumeric Read a numeric data. <symbol> Type of data:
#unsignedChar, #signedChar, #unsignedShort, #signedShort, #unsignedLong, #signedLong,
#float, #double (1)
<integer> read value
or if there's an error:
<symbol> error code:
#endOfFile,
#fileNotOpened
writeNumeric Write a numeric data <symbol> Type of data:
#unsignedChar, #signedChar, #unsignedShort, #signedShort, #unsignedLong, #signedLong,
#float, #double (1)
<integer> Data to write.
<symbol> Result:
#ok
#fileNotOpened
readChars Read a string <integer> Size of the string to read. <string> Read string
or if there's an error:
<symbol> error code:
#endOfFile
#fileNotOpened
writeChars Write a string <string> String to write
<integer> Size of the string
<symbol> Result:
#ok
#fileNotOpened
readArray Read a Lingo list <symbol> Type of data:
#unsignedChar, #signedChar, #unsignedShort, #signedShort, #unsignedLong, #signedLong,
#float, #double (1)
<integer> Number of data to read
<list> Read list.
or if there's an error:
<symbol> error code:
#endOfFile
#fileNotOpened
writeArray Write a Lingo list <symbol> Type of data in the list:
#unsignedChar, #signedChar, #unsignedShort, #signedShort, #unsignedLong, #signedLong,
#float, #double (1)
<list> Lingo list.
<integer> Size of the list
<symbol> Result:
#ok
#cantWriteToFile
#fileNotOpened
setPosition Move to the given position. The next writing / reading operation will start at this position. <integer> New position. <symbol> Result:
#ok
#fileNotOpened
getPosition Return the current file position. (no input) <integer> Current position
size Return the size of the file. (no input) <integer> File size
eof Return TRUE if it's the end of the file. (no input) <boolean>

(1)
Unsigned Char (1 byte) : for values from 0 to 255
Signed Char (1 byte) : from -128 to 127
Unsigned Short (2 bytes) : from 0 to 65535
Signed Short (2 bytes) : from -35537 to 35568
Unsigned Long (4 bytes) : from 0 to 4294967295
Signed Long (4 bytes) : from -2147483648 to 2147483647
Float (4 bytes) : from 1.5 x 10^-45 to 3.4 x 10^38
Double (8 bytes) : from 5.0 x 10^-324 to 1.7 x 10^308

Example:

try = f.openFile("c:/test.bin", 2) -- try to open the file
if try = #ok then
-- if the file has been successfully opened
   f.writeNumeric(#unsignedLong, 350)
-- write an integer in the file
   s = "une chaîne"
   f.writeChars(s, length(s))
-- write a string in the file
   uneListe = [1,2,3,4,5,6,7]
   f.writeArray(#unsignedLong, uneListe, uneListe.count)
-- write a list of integers
   f.setPosition(0)
-- go back to the start of the file
   put f.readNumeric(#unsignedLong)
-- read an integer
   
-- Displays "350"
   s = f.readChars(9)
-- read nine characters
   put s
   
-- Displays "une chaîn"
   f.setPosition(f.getPosition + 1)
-- move by one byte (skip the "e" of "une chaîne")
   put f.readArray(#unsignedLong, 7)
-- read a list of seven integers
   
-- Displays "[1,2,3,4,5,6,7]"
   try = f.closeFile()
-- close the file
   if try <> #ok then
      Alert("Error closing file!")
   end if
else
   Alert("Error opening file!")
end if


Xtra Joystick

This Xtra allows using some simple functions to control a game device such as a joystick or a game pad.

Download Joystick Xtra (57 K)

Download Joystick Xtra Source Code

Available functions:

Name Description Input Output
useJoy Use the specified joystick. <integer> Joystick ID (from 1 to numberOfJoy) <boolean> Return TRUE if the specified joystick is available.
button Test the state of a button. <integer> Button ID (from 1 to buttonCount) <boolean> Button state (TRUE if it's pressed, FALSE otherwise)
xPos Return the X position of the analogic axis. (no input) <integer> X Position (1st axis)
yPos Return the Y position of the analogic axis. (no input) <integer> Y Position (1st axis)
zPos Return the Z position of the second analogic axe. (no input) <integer> Z Position (1st axis)
rPos Return the X position of the second analogic axis. (no input) <integer> X Position (2nd axis)
uPos Return the Y position of the second analogic axis. (no input) <integer> Y Position (2nd axis)
vPos Return the Z position of the analogic axe. (no input) <integer> Z Position (2nd axis)
numberOfJoy

Return the number of connected joysticks.

(no input) <integer> Number of joysticks.
buttonCount Return the number of buttons. (no input) <integer> Number of buttons
axeCount Return the number of axes. (no input) <integer> Number of axes.


Xtra SetMouseLoc

Use this Xtra to set the mouse cursor location.

Download SetMouseLoc Xtra (30 K)

Download SetMouseLoc Xtra Source Code

Available functions:

Name Description Input Output
setMouseLoc Set the cursor location relatively to the stage. <integer> X Position
<integer> Y Position
(No output)
setMouseAbsoluteLoc Set the cursor location relatively to the screen. <integer> X Position
<integer> Y Position
(No output)

Example:

-- NB: The two functions are globals so you don't need to create a new instance of SetMouseLoc
setMouseLoc(0,0) -- Set the cursor position to the top left hand corner of the stage
setMouseLoc(the stageRight, the stageBottom) -- ... to the bottom right hand corner of the stage.
setMouseAbsoluteLoc(0,0) -- ... to the top left hand corner of the screen.
setMouseAbsoluteLoc((the desktopRectList[1]).right, (the desktopRectList[1]).bottom) -- ... to the bottom right hand corner of the screen.


Xtra pointInsidePolygon

This Xtra checks if the given point is inside the given n-sided polygon. It can be used, for example, to detect if a character is inside a plane surface in a 3D game (so that the use of modelsUnderRay(), which is quite slow, can be avoided in some cases).

Download PointInsidePolygon Xtra (45 K)

Download PointInsidePolygon Xtra Source Code

Name Description Input Output
pointInsidePolygon Check if the given point is inside the given polygon. <float or integer> point X coordinate
<float or integer>
point Y coordinate
<list>
polygon [[x1,y1], [x2,y2], [x3,y3], etc.]
<Boolean> Result. TRUE if the point is inside the polygon.
pointInsidePolygonEC The same as above but with error checking. <float or integer> point X coordinate
<float or integer>
point Y coordinate
<list>
polygon [[x1,y1], [x2,y2], [x3,y3], etc.]
<Boolean> Result. TRUE if the point is inside the polygon.
or <Symbol> ErrorCode, if there's an error.

Warning: for performance reasons, pointInsidePolygon() doesn't check the input parameters. So if one of the parameter is non-numeric, Director will crash with a fatal error. In general there's no reason for it to happen but, for more security, you might want to use pointInsidePolygonEC() while debugging and replace it later by pointInsidePolygon() once you are sure that the function receives the expected parameters.

Example:

-- Create the polygon from a #plane model
planeModel.addModifier(#meshDeform)
v = planeModel.meshDeform.mesh[1].vertexList
polygon = [[v[2].x, v[2].y], [v[1].x, v[1].y], [v[3].x, v[3].y], [v[4].x, v[4].y]]
-- Add the world position of the model to get the world position of its vertices
repeat with p in pPolygon
   p[1] = p[1] + planeModel.worldPosition.x
   p[2] = p[2] + planeModel.worldPosition.y
end repeat
-- Check if the character is inside planeModel
characterPos = [characterModel.worldPosition.x, characterModel.worldPosition.y]
if pointInsidePolygon(characterPos[1], characterPos[2], polygon) then
   put "The character is inside the plane"
else
   put "The character is outside the plane"
end if


23/05/2003 - counter