✅ Issues regarding having a fill property for a sprite

Part of my assignment requires me to change the color of some ball sprites. But this enemy class that uses a sprite keeps instantiating to base sprite because that's how it is in the abstract class for eenemy. My teacher says to cast it, but I'm not sure how
1 Reply
Rev E. Lations
Rev E. LationsOP7d ago
Here’s what I was told to do In the BallSprite class you created, in the code behind create a public property that allows you to set the fill color of the ball. In the EnemyBall class or whatever you call it after you set the sprite to the BallSprite then call that BallSprite's property you created to set the color to the desired color. Yes, it will be of type BaseSprite, but you can type cast it to a BallSprite and then you will be able to access the public property you created. My explanation was probably pretty bad, but I figured out the problems public Color Fill { set => this.ball.Fill = new SolidColorBrush(value); } Wasnt working until I realized my issue was that I wasnt using windows.ui at the top. My casting issue was that I was trying (BallSprite)this.Sprite = Color.red; When I should have done ((BallSprite)this.Sprite) = Color.red;

Did you find this page helpful?