Error: cannot construct `AnimatedSprite` with struct literal syntax due to inaccessible fields

I cannot figure out how to use the macroquad::experimental::animation::AnimatedSprite, I tried doing this:

let player_walking_anim = macroquad::experimental::animation::AnimatedSprite {
        tile_width: 32.0,
        tile_height: 32.0,
        animations: (&[macroquad::experimental::animation::Animation {
            name: "spritesheet.png".to_string(),
            row: 1,
            frames: 10,
            fps: 15,
        }]).to_vec(),
        playing: true,
    };

But the compiler returns this error: error: cannot construct `AnimatedSprite` with struct literal syntax due to inaccessible fields

I cannot find any documentation on this struct anywhere. And the compiler's --explain is not being very helpful:

if "Not a bool" {
Erroneous code examples: `bool`, found `&str`
}

fn plus_one(x: i32) -> i32 {
    x + 1-   ^^^^^^^^^^^^^ expected `f32`, found `&str`
}/     |
//     expected due to this
plus_one("Not a number");
//       ^^^^^^^^^^^^^^ expected `i32`, found `&str`
This error occurs when an expression was used in a place where the compiler
if "Not a bool" {
// ^^^^^^^^^^^^ expected `bool`, found `&str`
}

let x: f32 = "Not a float";
//     ---   ^^^^^^^^^^^^^ expected `f32`, found `&str`
//     |
//     expected due to this


This error occurs when an expression was used in a place where the compiler
expected an expression of a different type. It can occur in several cases, the
most common being when calling a function and passing an argument which has a
different type than the matching type in the function declaration. ```

I agree this error is not ideal. The actual problem is a combination of:

If you try to supply all the missing (private) fields, you get a better explaination.

The --explain output you show looks to be something about a different error in your code.

I think this is the result of #87872. It's probably worth a follow-up.

Filed #95872.


As for fixing the error, try using the new function instead.

1 Like