イントロダクション
前回は、3Dでのじゃんけんゲームを作成しようと悪戦苦闘しました。そして諦めました。。。
3D関連の実装は理解しなくてはならないことが多いので2日では実装できそうにないと判断しました。戦略的撤退です、逃げてはいません(笑)。
実装状況
現在は簡単なタイトル文言とボタンを表示するだけの実装ができています。
シンプルイズベスト?
作成したコードと流れ
自動生成された、Mainクラスの「JankenGameクラス」から同様に生成されたクラス「BasicView」を表示したのがタイトル部分です。「じゃんけんゲーム」と上部に表示しています。
「スタートボタン」を押下したら隣の球体のみの画面に画面遷移します。
コードはいたってシンプルです。
BasicView
public class BasicView extends View { public BasicView() { // 縦のレイアウト VBox layout = new VBox(300); layout.setAlignment(Pos.CENTER); // タイトル文言 layout.getChildren().add(this.getTitleNode()); // スタートボタン Button start = new Button("スタート"); start.setOnAction(event -> setCenter(new TestingView())); layout.getChildren().add(start); // 画面に登録 Group gp = new Group(layout); setCenter(gp); } @Override protected void updateAppBar(AppBar appBar) { // appBar.setNavIcon(MaterialDesignIcon.MENU.button(e -> System.out.println("Menu"))); // appBar.setTitleText("Basic View"); // appBar.getActionItems().add(MaterialDesignIcon.SEARCH.button(e -> System.out.println("Search"))); } /** * 画面のタイトルを作成します。 * @return タイトル部分のノード */ private HBox getTitleNode() { HBox hbox = new HBox(20); Text jan = new Text("じゃん"); this.settingFont(jan, Color.BLUE); hbox.getChildren().add(jan); Text ken = new Text("けん"); this.settingFont(ken, Color.YELLOW); hbox.getChildren().add(ken); Text game = new Text("ゲーム"); this.settingFont(game, Color.RED); hbox.getChildren().add(game); return hbox; } /** * テキストの設定を行います。 * @param tx 表示するテキスト * @param color 設定する色 */ private void settingFont(Text tx, Color color) { double width = MobileApplication.getInstance().getGlassPane().getWidth(); tx.setFont(new Font(width / 10)); tx.setFill(color); tx.setStroke(Color.BLACK); tx.setStrokeWidth(1.0); } }
TestingView
/** * JavaFXでの3Dモデルの描画(作成?)、とりあえず写経する。 * * @author takunoji * @see https://docs.oracle.com/javase/jp/8/javafx/graphics-tutorial/overview-3d.htm#CJAHFAHJ */ public class TestingView extends View { public TestingView() { Sphere sp = new Sphere(30.0); setCenter(sp); } }
これで、タイトル表示からゲームの起動画面まで来ました。
残すはじゃんけんゲームの実装部分になります。残すところは11時間。。。
でわでわ。。。[rakuten ids="yamada-denki:10159121"]