资源描述:
《javafx方块系统》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、/***Copyright(c)2008,2012Oracleand/oritsaffiliates.*Allrightsreserved.Useissubjecttolicenseterms.*/importjavafx.scene.transform.Rotate;importjavafx.scene.PerspectiveCamera;importjavafx.scene.transform.Translate;importjavafx.application.Application;importjavafx.scene.Group;importjavafx.scene.Scene;
2、importjavafx.stage.Stage;importjavafx.animation.Animation;importjavafx.animation.KeyFrame;importjavafx.animation.KeyValue;importjavafx.animation.Timeline;importjavafx.scene.Node;importjavafx.scene.paint.Color;importjavafx.scene.shape.RectangleBuilder;importjavafx.util.Duration;/***Asamplethatdemon
3、stratesananimatedrotationof3Dcubes.Whenthe*applicationrunsinstandAlonemode,thescenemustbeconstructedwith*thedepthBufferargumentsettotrue,andtherootnodemusthavedepthTest*settotrue.**@seejavafx.scene.transform.Rotate*@seejavafx.scene.paint.Color*@seejavafx.scene.shape.RectangleBuilder*/publicclassCu
4、beSampleextendsApplication{privateTimelineanimation;privatevoidinit(StageprimaryStage){Grouproot=newGroup();primaryStage.setResizable(false);primaryStage.setScene(newScene(root,400,150,true));primaryStage.getScene().setCamera(newPerspectiveCamera());root.getTransforms().addAll(newTranslate(400/2,1
5、50/2),newRotate(180,Rotate.X_AXIS));root.getChildren().add(create3dContent());}publicNodecreate3dContent(){Cubec1=newCube(50,Color.RED,1);c1.rx.setAngle(45);c1.ry.setAngle(45);Cubec2=newCube(50,Color.GREEN,1);c2.setTranslateX(100);c2.rx.setAngle(45);c2.ry.setAngle(45);Cubec3=newCube(50,Color.ORANG
6、E,1);c3.setTranslateX(-100);c3.rx.setAngle(45);c3.ry.setAngle(45);animation=newTimeline();animation.getKeyFrames().addAll(newKeyFrame(Duration.ZERO,newKeyValue(c1.ry.angleProperty(),0d),newKeyValue(c2.rx.angleProperty(),0d),newKeyValue(c3.rz.angleProperty(),0d)),newKeyFrame(Duration.seconds(1),new
7、KeyValue(c1.ry.angleProperty(),360d),newKeyValue(c2.rx.angleProperty(),360d),newKeyValue(c3.rz.angleProperty(),360d)));animation.setCycleCount(Animation.INDEFINITE);returnnewGroup(c1,c2,c3);}publicvoidplay(){anim