René Nyffenegger's collection of things on the web | |
René Nyffenegger on Oracle - Most wanted - Feedback
- Follow @renenyffenegger
|
Following the mouse [Ming wrapper example] | ||
This example demonstrates how the the location of the mouse can be detected.
It is adapted from this example.
This flash movie was created with the following program. FollowMouse.cpp
#include <iostream> #include "SWFMovie.h" int main() { /* see http://sourceforge.net/mailarchive/forum.php?thread_id=5916402&forum_id=9823 on Ming_useSWFVersion(4) */ //Ming_useSWFVersion(4); Movie movie ("FollowMouse.swf", 320, 240, 12, 4); movie.BackgroundColor(0, 0, 0); MovieClip movieClip; // TODO: AddScout or something for exactly this // purpose here DisplayItem iMouse = movie.Add(movieClip); iMouse.Name("mouse"); movie.Add(Action("startDrag(/mouse, true);")); Morph morph; Shape shape_begin = morph.ShapeStart(); Shape shape_end = morph.ShapeEnd (); shape_begin.FillStyle(255, 255, 255); shape_begin.MoveTo (-40, -40); shape_begin.Line ( 80, 0); shape_begin.Line ( 0, 80); shape_begin.Line (-80, 0); shape_begin.Line ( 0, -80); shape_end .FillStyle( 0, 0, 0); shape_end .MoveTo ( -1, -1); shape_end .Line ( 2, 0); shape_end .Line ( 0, 2); shape_end .Line ( -2, 0); shape_end .Line ( 0, -2); MovieClip box; box.Stop(); DisplayItem iMorph = box.Add(morph); for (float n=0; n<=1; n+=1.0/25.0) { iMorph.Ratio(n); box.NextFrame(); } MovieClip cell; DisplayItem iBox = cell.Add(box); iBox.Name("box"); cell.Add(Action( "setTarget('box');" "dx = (/mouse.x + random(120)-60 - ...x)/20;" "dy = (/mouse.y + random(120)-60 - ...y)/20;" "gotoFrame(int(dx*dx + dy*dy));" )); cell.NextFrame(); cell.Add(Action("gotoFrame(0);play();")); cell.NextFrame(); for (int x=20; x<320;x+=40) { for (int y=20; y<240;y+=40) { DisplayItem iCell = movie.Add(cell); iCell.MoveTo(x, y); }} movie.NextFrame(); movie.Add(Action("gotoFrame(1);play();")); return 0; } This is one of a series of examples that demonstrates the C++ ming wrapper classes. Other examples can be found here.
|