c# - how to make sprite change with speed -


ok new coding have basic understanding of c# making brick breaker game / brick buster in case. but, have problem need have ball sprite change basic white ball other sprite after speed of 10.0f . based have seen within tutorials came code

if (ballspeed > 10f)     {       ballimage = content.load<texture2d>("fireball");      } 

i don't know if close ideas people?

edit: when go put ball ball = new ball(content); brings error , wants me change (content:);

edit2: far trying isn't working snooks method worked except end ( read above edit)

the other guys method throwing exceptions left , right . more ideas

you still have load image in loadcontent() or ball constructor. because want game have sprite in memory before might potentially used.

so in ball.cs constructor you'll load sprite.

public ball(contentmanager content) {     textureball = content.load<texture2d>("fireball");      ... } 

you can choose logic in game2.cs, or can make seperate draw method in ball.cs can call in main draw method (located in game2.cs), give better cohesion. although don't require in small projects, it's better learn habits beginning.

so how new method in ball.cs might look.

 public void draw(gametime gametime, spritebatch spritebatch)     {         ...         if (ballspeed > 10.0f)         {             spritebatch.begin();             spritebatch.draw(fireball, ballposition, null, color.white);             spritebatch.end();         }         ...     }    

now, if haven't already, declare ball gameobject in game2.cs

ball ball = new ball(content); 

now can call ball.draw(gametime, spritebatch) in draw loop of main game2.cs class. logic surrounding ball located in ball.cs

the thing wasn't clear me was: "a speed of 10 frames." think mean 10.0 float, because measuring speed in frames whole different story. it's better find float value speed suits requirements , give ball position way.


Comments