thombruce / verse

πŸš€ A universe in progress
Other
8 stars 0 forks source link

Scrolling Credits #56

Closed thombruce closed 10 months ago

thombruce commented 10 months ago

There's plenty more I want to add to the credits. In the mid-to-long term:

In the more immediate term, I've added a new audio asset and am unable to fit the credit on screen. I want to append this to the credits, but will need to implement scrolling in order to start showing more info:

            parent.spawn((TextBundle {
                style: Style {
                    margin: UiRect::top(Val::Px(25.)),
                    ..default()
                },
                text: Text::from_section(
                    "Audio".to_ascii_uppercase(),
                    TextStyle {
                        font: ui.font.clone(),
                        font_size: 24.0,
                        color: Color::rgb_u8(0x00, 0x88, 0x88),
                    },
                ),
                ..default()
            },));
            parent.spawn((TextBundle {
                style: Style {
                    margin: UiRect::top(Val::Px(25.)),
                    ..default()
                },
                text: Text::from_section(
                    "Impact Sounds by Kenney",
                    TextStyle {
                        font: ui.font.clone(),
                        font_size: 20.0,
                        color: Color::rgb_u8(0xCC, 0xCC, 0xCC),
                    },
                ),
                ..default()
            },));
            parent.spawn((TextBundle {
                text: Text::from_section(
                    "kenney.nl, CC0",
                    TextStyle {
                        font: ui.font.clone(),
                        font_size: 14.0,
                        color: Color::rgb_u8(0xAA, 0xAA, 0xAA),
                    },
                ),
                ..default()
            },));
thombruce commented 10 months ago

Also, the way I'm writing credits at the moment directly into the .rs file is overly cumbersome. I should try to implement a way to load credits from a .json, .toml, .ron or .yml file. Backers will probably be loaded from a .csv as this is what sites like Ko-fi and Patreon export.

thombruce commented 10 months ago

Ideally credits would...

  1. Spawn off-screen, below camera
  2. Move upwards every tick
  3. Return to StartMenu once their full length has left top of screen

Step one is easy. We just alter their spawn coordinates.

Step two is easy. We just modify their Y coordinate on every Update.

Step three...

Can we get the height of the credits text entity? This would give us a Y position to reach above the screen. The credits scroll system could then, upon reaching this, return the player to the StartMenu.

Should be easy enough.

thombruce commented 10 months ago

Wow. That third point is not easy at all. You can't use comparators to compare two Val components, meaning I can't do something like style.top <= -style.height. That's just not allowed... and I can't see a way to get the pixel values from these as floats. πŸ˜•

We do have scrolling credits though. I'm going to leave this open, but I am going to push the new scrolling credits which include the previously omitted audio credits.

The problem:

For the time being, the credits do just roll off screen and... nothing happens. You aren't returned to the menu, they don't roll around again. Nothing happens.

I need some way to acknowledge that the credits have rolled their full length and respond to this, but I just don't see a way to do that yet.

thombruce commented 10 months ago

Since the credits do now scroll though, I am happy to remove the v0.0.16 milestone and leave this as something to figure out before v0.1

thombruce commented 10 months ago

Here's a thought...

Instead of updating the value of the styles directly, could we update a component with an f32 value?

Say it has an initial value of 1000.0 (or whatever the screen's Y extent is). Every tick, we subtract the same value from it we had been subtracting from the pixel value with .try_sub(). And every tick we reassign the style.top with a new Val::Px() set to the value of the f32 component.

We also keep track of the .size() of both the window extents and the credits and when Component f32 goes below the negated Y of the credits size... then we swap state back to the StartMenu.

thombruce commented 10 months ago

Yep: 3b098bd57ed92afcc4da743e04458102ca77f060

I just had to get the .size() of the Node itself rather than the style of its contents. Of course.

I mean, not of course - that's hardly intuitive - but it works!