Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Cristian |
Hi.
I have some questions in C#.
1) From Sprite, cant get a texture. Edit: From a current Sprite class, Get from an external List/Array Sprites get randomly the texture, and assign it to the current Sprite class.
// I did not write all the code, because is annoying writing code in this page. Just skipped the random generation code.
public class RandomSprite : Sprite
{
[Export] public Array<Sprite> sprites = new Array<Sprite>( ); // This doesnt works
[Export] public Sprite mysprite; // This doesnt work
[Export] public Texture myTexture; // This works.
public override void _Ready()
{
Texture = sprites[0].Texture; // This does not work. // Error: Casting. Even if is not null
Texture = mysprite.Texture; // This does not work. // Error: Casting. Even if is not null
Texture = myTexture; // Why this works?
}
// code...
}
2) Change font color from a button. The only way is by code or adding RichTectLabel, Label, and change the color?
myButton.Set("custom_colors/font_color", Color.Color8(1, 1, 1, 255));
I think, there is no solution for this.
3) I need to create, inside of CollisionShape2D a Shape (RectangleShape2D), BUT, the Extents will be by code.
The thing is, I am translating one tutorial from Unity to Godot (Making a procedural level) and Creating a Room. Adding a Sprite(Tile) and random will get from a List, in this case an Array a sprite and show it.
BUT, also will get a collider (The walls or floor), BUT, the collision shape needs to fit in the sprite.
So, I dont know how to create a RectangleShape2D with its Extents in the CollisionShape2D.Shape by code.
Thank you.
Hi.
Can you please give me more Information, what you are even trying to do?
juppi | 2022-07-24 15:55
Trying to implement this in Godot: https://www.youtube.com/watch?v=hk6cUanSfXQ&t=6s
- Sprite generator randomly.
- Place each sprite generator around the room.
- In the Sprite, get a List < Sprite > , in this case an Array < Sprite >.
- Random, get from the Array a sprite.texture and place it
[Export] public Array<Texture> sprites = new Array<Texture>( );
Texture = sprites[randomnumber].Texture; // This gets an error of Casting.
Cristian | 2022-07-24 16:59