c# - Monogame - Changing background colour error -
i'm building 2d platformer , want have different colour backgrounds each level. i've made object when collided with, places character onto next level changing player.position
, so...
protected override void update(gametime gametime){ if (player.bounds.intersects(teleportobj.bounds)) { graphicsdevice.clear(color.slategray); // fails change bg color player.position = new vector2(172, 0); // changes character position mediaplayer.play(dungeonsong); // plays new song mediaplayer.isrepeating = true; // repeats new song } }
i have set background first level begin in game1's draw()
function this:
graphicsdevice.clear(color.cornflowerblue);
but when player collides teleportobj
, the background color doesn't change.
graphicsdevice.clear(color.slategray);
used in draw
function. try creating new color
variable, , change variable in update
method, , when using graphicsdevice.clear(name of variable);
, use in draw function.
code this:
color backgroundcolor = color.cornflowerblue; protected override void update(gametime gametime) { if (player.bounds.intersects(teleportobj.bounds)) { backgroundcolor = color.slategray; player.position = new vector2(172, 0); mediaplayer.play(dungeonsong); mediaplayer.isrepeating = true; } else backgroundcolor = color.cornflowerblue; } protected override void draw(spritebatch spritebatch) { graphicsdevice.clear(backgroundcolor); *draw other stuff* }
Comments
Post a Comment