Director 3D > Interaction in 3D

Creating a rollover effect

2D design elements such as rollovers are possible. See the following sample and the Lingo within for an example. This simulates the functionality of the mouse enter and mouse leave Lingo for a standard Director score.

The Lingo:

Here is a breakdown of the code used:

Property porigin, spritenum, pskip, pTime, pfrequency -- This declares the variables we use in this handler

Global scene -- "scene" is a global object - the 3D world

On beginsprite me -- in essence, this sets the variables used in the handler
Porigin = point(sprite(spritenum).left, sprite(spritenum).top)
Pskip = -1
Ptime = the milliseconds
Pfrequency = 100

Finpoint = the mouseloc - porigin --this returns the location of the mouse cursor within the stage
Test = sprite(spritenum).camera.Modelunderloc(finpoint)
--this line tests whether the mouse position is "over" a model in the scene
-- calls the enterAction handler when a model found to be under the cursor
Pskip = test
End if
if pskip <> -1 then
exitaction(me, pskip)
-- calls the exitAction handler when the cursor "leaves"/rolls out of the model
pskip = -1
end if
End if
PTime = the milliseconds
End if

The following code is where the enter and exit handlers come into play. First up, the "exit" handler:

On exitaction me, whichmodel -- this receives the name of the model "rolled over"

Case( of -- this "listens" for the name of models being rolled over

"redbox": -- therefore if the "redbox" shape is rolled out of we carry out the following actions
scene.model("redbox").transform.scale = vector(1,1,1) --return the scale to normal
scene.model("redbox").shader.blend = 100
--make the "blend" value of the shader 100 (opaque)

"bluebox": --this basically does the same as the code above!
scene.model("bluebox").transform.scale = vector(1,1,1)
scene.model("bluebox").shader.blend = 100

end case


Next: the enterAction handler (the crux of the rollover effect):

On enteraction me, whichmodel

Case( of
scene.model("redbox").transform.scale = vector(1.2,1.2,1.2)
scene.model("redbox").shader.blend = 50
scene.model("bluebox").transform.scale = vector(1.2,1.2,1.2)
scene.model("bluebox").shader.blend = 50
end case


< Previous | Next >

July 2003