ソースを参照

titlescreen ui elements/name

amethyst
Isabelle L. 5年前
コミット
f477636e33
1個のファイルの変更78行の追加37行の削除
  1. +78
    -37
      src/states/titlescreen.rs

+ 78
- 37
src/states/titlescreen.rs ファイルの表示

@@ -1,3 +1,4 @@
// namespacing
use crate::resources::{font::FontResource, spritesheet::SpriteSheetMap};
use amethyst::{
core::transform::Transform,
@@ -8,6 +9,7 @@ use amethyst::{
};
use nalgebra::Vector3;

// constants
const DEFAULT_SPRITE_WIDTH: f32 = 256.0;
const DEFAULT_SPRITE_HEIGHT: f32 = 144.0;

@@ -34,6 +36,7 @@ impl TitleScreenState {
.build();
}

// initialize the ui
fn init_ui(&self, world: &mut World) {
// get the font handle
let font_handle = {
@@ -44,49 +47,87 @@ impl TitleScreenState {
}
};

// create the button transforms
let exit_btn_transform = UiTransform::new(
"exit_button".into(),
Anchor::BottomRight,
Anchor::Middle,
-100.0,
50.0,
0.0,
100.0,
50.0,
);
let settings_btn_transform = UiTransform::new(
"settings_button".into(),
Anchor::BottomRight,
Anchor::Middle,
0.0,
0.0,
0.0,
200.0,
50.0,
);

// create the button ui text
let exit_btn_text =
UiText::new(font_handle.clone(), "Exit".into(), [1.0, 1.0, 1.0, 1.0], 30.0);
let settings_btn_text =
UiText::new(font_handle, "Settings".into(), [1.0, 1.0, 1.0, 1.0], 30.0);

// create ui image
let btn_image = UiImage::SolidColor([0.0, 0.0, 0.0, 1.0]);
// make the title
world
.create_entity()
.with(UiTransform::new(
"title".into(),
Anchor::Middle,
Anchor::Middle,
-450.0,
0.0,
0.0,
450.0,
50.0,
))
.with(UiText::new(
font_handle.clone(),
"Merchant Seas".into(),
[1.0, 1.0, 1.0, 1.0],
45.0,
))
.build();

// create the button
// create the buttons
world
.create_entity()
.with(UiTransform::new(
"exit_button".into(),
Anchor::BottomRight,
Anchor::Middle,
-100.0,
50.0,
0.0,
150.0,
50.0,
))
.with(UiText::new(font_handle.clone(), "Exit".into(), [1.0, 1.0, 1.0, 1.0], 30.0))
.with(UiImage::SolidColor([0.0, 0.0, 0.0, 1.0]))
.build();
world
.create_entity()
.with(UiTransform::new(
"settings_button".into(),
Anchor::BottomRight,
Anchor::Middle,
-325.0,
50.0,
0.0,
250.0,
50.0,
))
.with(UiText::new(font_handle.clone(), "Settings".into(), [1.0, 1.0, 1.0, 1.0], 30.0))
.with(UiImage::SolidColor([0.0, 0.0, 0.0, 1.0]))
.build();
world
.create_entity()
.with(exit_btn_transform)
.with(exit_btn_text)
.with(btn_image.clone())
.with(UiTransform::new(
"load_button".into(),
Anchor::BottomRight,
Anchor::Middle,
-600.0,
50.0,
0.0,
250.0,
50.0,
))
.with(UiText::new(font_handle.clone(), "Load Game".into(), [1.0, 1.0, 1.0, 1.0], 30.0))
.with(UiImage::SolidColor([0.0, 0.0, 0.0, 1.0]))
.build();
world
.create_entity()
.with(settings_btn_transform)
.with(settings_btn_text)
.with(btn_image)
.with(UiTransform::new(
"new_button".into(),
Anchor::BottomRight,
Anchor::Middle,
-875.0,
50.0,
0.0,
250.0,
50.0,
))
.with(UiText::new(font_handle, "New Game".into(), [1.0, 1.0, 1.0, 1.0], 30.0))
.with(UiImage::SolidColor([0.0, 0.0, 0.0, 1.0]))
.build();
}



読み込み中…
キャンセル
保存