displaylist.java
来自「利用opensource的开源jar实现生成flash文件」· Java 代码 · 共 205 行
JAVA
205 行
/*
* DisplayList.java
* Examples
*
* Created by Stuart MacKay on Tue May 13 2003.
* Copyright (c) 2001-2006 Flagstone Software Ltd. All rights reserved.
*
* This code is distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND Flagstone HEREBY DISCLAIMS ALL SUCH WARRANTIES, INCLUDING
* WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
* PURPOSE, AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
*/
package com.flagstone.transform.examples;
import com.flagstone.transform.*;
import java.util.*;
/*
* The DisplayList class illustrates how to use the classes that update and change
* the Flash Player's display list.
*
* To run this example, type the following on a command line:
*
* java DisplayList [--resultDir path]
*
* where
*
* resultDir is the directory where the Flash file generated by the example is
* written to.
*
*/
public class DisplayList extends Example
{
public static void main(String[] args)
{
new DisplayList(args);
}
public DisplayList(String[] args)
{
super(args);
createMovie();
writeFile("DisplayList.swf");
}
public void createMovie()
{
int width = 3200;
int height = 2400;
movie.setFrameRate(2.0f);
movie.setFrameSize(new FSBounds(0, 0, 17600, 3600));
movie.add(new FSSetBackgroundColor(FSColorTable.lightblue()));
/*
* Define the basic components of the rectangle shapes.
*/
int identifier = 0;
FSBounds bounds = new FSBounds(-width/2, -height/2, width/2, height/2);
ArrayList lineStyles = new ArrayList();
ArrayList fillStyles = new ArrayList();
/*
* Define the outline of the rectangle.
*/
ArrayList rectangle = new ArrayList();
rectangle.add(new FSShapeStyle(1, 1, 0, -width/2, -height/2));
rectangle.add(new FSLine(width, 0));
rectangle.add(new FSLine(0, height));
rectangle.add(new FSLine(-width, 0));
rectangle.add(new FSLine(0, -height));
/*
* Define a red rectangle.
*/
identifier = movie.newIdentifier();
lineStyles.add(new FSSolidLine(20, FSColorTable.black()));
fillStyles.add(new FSSolidFill(FSColorTable.red()));
FSDefineShape redRectangle = new FSDefineShape(identifier, bounds,
fillStyles, lineStyles, new FSShape(rectangle));
movie.add(redRectangle);
/*
* Define a yellow rectangle.
*/
identifier = movie.newIdentifier();
bounds = new FSBounds(-width/2, -height/2, width/2, height/2);
lineStyles = new ArrayList();
fillStyles = new ArrayList();
lineStyles.add(new FSSolidLine(20, FSColorTable.black()));
fillStyles.add(new FSSolidFill(FSColorTable.yellow()));
FSDefineShape yellowRectangle = new FSDefineShape(identifier, bounds,
fillStyles, lineStyles, new FSShape(rectangle));
movie.add(yellowRectangle);
/*
* The FSPlaceObject class is used to add a shape on the display list.
*
* Objects are referenced by their unique identifier - specified when the
* object is created. Objects are placed on the display list on a given
* layer. Layers define the order in which shapes are displayed. Shapes
* with a higher layer number are displayed in front of those with a lower
* layer number. The location and appearance of the shape is controlled
* by an FSCoordTransform and optional FSColorTranform objects. These
* transforms can be used to display a shape without changing the original
* definition - allowing it to be reused.
*
* The FSPlaceObject class provides a simplified constructor which allows
* the coordinates where an object will be placed to be specified rather
* than explicitly creating an FSCoordTranform object.
*
* FSShowFrame is used to render the display list on the screen. The scope
* of a frame is delimited by successive FSShowFrame objects.
*/
/*
* Place the red rectangle on layer 1, at coordinates (100,80).
*/
movie.add(new FSPlaceObject(redRectangle.getIdentifier(), 1, 2000, 1600));
movie.add(new FSShowFrame());
/*
* Place the yellow rectangle in front of the red rectangle.
*/
movie.add(new FSPlaceObject(yellowRectangle.getIdentifier(), 2, 2400, 2000));
movie.add(new FSShowFrame());
/*
* To Change the location of an object it first must be removed then placed
* at its new location. The FSPlaceObject2 class simplifies this into single
* step - see later.
*/
movie.add(new FSRemoveObject(redRectangle.getIdentifier(), 1));
movie.add(new FSPlaceObject(redRectangle.getIdentifier(), 1, 2800, 1600));
movie.add(new FSShowFrame());
/*
* The FSPlaceObject2 class provides more control over how the display
* list is updated. It should be used in preference to the FSPlaceObject
* class. For placing new objects on the display list the constructors
* are identical.
*/
movie.add(new FSPlaceObject2(redRectangle.getIdentifier(), 3, 6400, 1600));
movie.add(new FSShowFrame());
/*
* Place the yellow rectangle in front of the red rectangle.
*/
movie.add(new FSPlaceObject2(yellowRectangle.getIdentifier(), 4, 6800, 2000));
movie.add(new FSShowFrame());
/*
* To Change the location of an object only the layer number is required to
* reference the object.
*/
movie.add(new FSPlaceObject2(3, 7200, 1600));
movie.add(new FSShowFrame());
/*
* The FSPlaceObject2 class can also be used to replace an object on a layer
* with another. Only the identifier of the new object and the layer number
* of the object being replaced is required. The new object will be placed
* at the same location as the one it replaces.
*/
movie.add(new FSPlaceObject2(redRectangle.getIdentifier(), 5, 11200, 1600));
movie.add(new FSShowFrame());
movie.add(new FSPlaceObject2(yellowRectangle.getIdentifier(), 5));
movie.add(new FSShowFrame());
/*
* The FSPlaceObject2 class can define clipping region where the outline of a
* shape is used to clip objects placed in front of it up to and including a
* given layer number.
*
* Use the outline of th red rectangle to clip all objects placed
* in front, up to layer 8.
*/
movie.add(new FSPlaceObject2(redRectangle.getIdentifier(), 6, 8, 14800, 1600));
movie.add(new FSPlaceObject2(redRectangle.getIdentifier(), 7, 15200, 2000));
movie.add(new FSPlaceObject2(yellowRectangle.getIdentifier(), 8, 15600, 2400));
movie.add(new FSShowFrame());
/*
* the FSRemoveObject2 class is slightly simpler to use than FSRemoveObject
* as only the layer number is required to remove an object.
*/
movie.add(new FSRemoveObject2(8));
movie.add(new FSShowFrame());
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?