c# - Enemy sprite going black XNA -
i'm doing simple tower defense game on xna , i'm having trouble. have enemy sprite should green, image correct, when insert on program appears black, in right shape. here's code (sorry it's mess):
namespace microdefense { public class game1 : microsoft.xna.framework.game { graphicsdevicemanager graphics; spritebatch spritebatch; enum gamestate { mainmenu, options, playing, } gamestate currentgamestate = gamestate.mainmenu; // screen adjustments int screenwidth = 800, screenheight = 600; cbutton btnplay; level level = new level(); wavemanager wavemanager; player player; gui.button arrowbutton; gui.button spikebutton; gui.button slowbutton; gui.toolbar toolbar; public game1() { graphics = new graphicsdevicemanager(this); content.rootdirectory = "content"; // width of level in pixels graphics.preferredbackbufferwidth = level.width * 32; // height of toolbar + height of level in pixels graphics.preferredbackbufferheight = 32 + level.height * 32; graphics.applychanges(); ismousevisible = true; } protected override void initialize() { base.initialize(); } protected override void loadcontent() { spritebatch = new spritebatch(graphicsdevice); // screen stuff graphics.preferredbackbufferwidth = screenwidth; graphics.preferredbackbufferheight = screenheight; graphics.applychanges(); ismousevisible = true; btnplay = new cbutton(content.load<texture2d>("button"), graphics.graphicsdevice); btnplay.setposition(new vector2(350, 300)); texture2d topbar = content.load<texture2d>("tool bar"); spritefont font = content.load<spritefont>("arial"); toolbar = new gui.toolbar(topbar, font, new vector2(0, level.height * 32)); texture2d grass = content.load<texture2d>("grass"); texture2d path = content.load<texture2d>("path"); level.addtexture(grass); level.addtexture(path); texture2d bullettexture = content.load<texture2d>("bullet"); texture2d[] towertextures = new texture2d[] { content.load<texture2d>("arrow tower"), content.load<texture2d>("spike tower"), content.load<texture2d>("slow tower"), }; player = new player(level, towertextures, bullettexture); texture2d enemytexture = content.load<texture2d>("enemy"); texture2d healthtexture = content.load<texture2d>("health bar"); wavemanager = new wavemanager(player, level, 24, enemytexture, healthtexture); // "normal" texture arrow button. texture2d arrownormal = content.load<texture2d>("gui\\arrow tower\\arrow button"); // "mouseover" texture arrow button. texture2d arrowhover = content.load<texture2d>("gui\\arrow tower\\arrow hover"); // "pressed" texture arrow button. texture2d arrowpressed = content.load<texture2d>("gui\\arrow tower\\arrow pressed"); // "normal" texture spike button. texture2d spikenormal = content.load<texture2d>("gui\\spike tower\\spike button"); // "mouseover" texture spike button. texture2d spikehover = content.load<texture2d>("gui\\spike tower\\spike hover"); // "pressed" texture spike button. texture2d spikepressed = content.load<texture2d>("gui\\spike tower\\spike pressed"); // "normal" texture slow button. texture2d slownormal = content.load<texture2d>("gui\\slow tower\\slow button"); // "mouseover" texture slow button. texture2d slowhover = content.load<texture2d>("gui\\slow tower\\slow hover"); // "pressed" texture slow button. texture2d slowpressed = content.load<texture2d>("gui\\slow tower\\slow pressed"); // initialize arrow button. arrowbutton = new gui.button(arrownormal, arrowhover, arrowpressed, new vector2(0, level.height * 32)); // initialize spike button. spikebutton = new gui.button(spikenormal, spikehover, spikepressed, new vector2(32, level.height * 32)); // initialize slow button. slowbutton = new gui.button(slownormal, slowhover, slowpressed, new vector2(32 * 2, level.height * 32)); //arrowbutton.clicked += new eventhandler(arrowbutton_clicked); //spikebutton.clicked += new eventhandler(spikebutton_clicked); //slowbutton.clicked += new eventhandler(slowbutton_clicked); arrowbutton.onpress += new eventhandler(arrowbutton_onpress); spikebutton.onpress += new eventhandler(spikebutton_onpress); slowbutton.onpress += new eventhandler(slowbutton_onpress); } protected override void unloadcontent() { } private void arrowbutton_clicked(object sender, eventargs e) { player.newtowertype = "arrow tower"; player.newtowerindex = 0; } private void spikebutton_clicked(object sender, eventargs e) { player.newtowertype = "spike tower"; player.newtowerindex = 1; } private void slowbutton_clicked(object sender, eventargs e) { player.newtowertype = "slow tower"; player.newtowerindex = 2; } private void arrowbutton_onpress(object sender, eventargs e) { player.newtowertype = "arrow tower"; player.newtowerindex = 0; } private void spikebutton_onpress(object sender, eventargs e) { player.newtowertype = "spike tower"; player.newtowerindex = 1; } private void slowbutton_onpress(object sender, eventargs e) { player.newtowertype = "slow tower"; player.newtowerindex = 2; } public vector2 size; protected override void update(gametime gametime) { mousestate mouse = mouse.getstate(); switch (currentgamestate) { case gamestate.mainmenu: if (btnplay.isclicked == true) currentgamestate = gamestate.playing; btnplay.update(mouse); if (cbutton.control) { graphics.preferredbackbufferheight = 288; graphics.preferredbackbufferwidth = 256; graphics.applychanges(); } break; case gamestate.playing: player.update(gametime, wavemanager.enemies); wavemanager.update(gametime); //update arrow button. arrowbutton.update(gametime); //update spike button. spikebutton.update(gametime); //update slow button. slowbutton.update(gametime); break; } base.update(gametime); } protected override void draw(gametime gametime) { graphicsdevice.clear(color.cornflowerblue); spritebatch.begin(); switch (currentgamestate) { case gamestate.mainmenu: spritebatch.draw(content.load<texture2d>("mainmenu"), new rectangle(0, 0, screenwidth, screenheight), color.white); btnplay.draw(spritebatch); break; case gamestate.playing: level.draw(spritebatch); player.draw(spritebatch); wavemanager.draw(spritebatch); // draw tool bar first, toolbar.draw(spritebatch, player); // , our buttons. arrowbutton.draw(spritebatch); spikebutton.draw(spritebatch); slowbutton.draw(spritebatch); player.drawpreview(spritebatch); break; } spritebatch.end(); base.draw(gametime); } }
}
edit1:the sprite has right shape color black.
edit2: here's wave manager:
public class wavemanager { private int numberofwaves; // how many waves game have private float timesincelastwave; // how long since last wave ended private queue<wave> waves = new queue<wave>(); // queue of our waves private texture2d enemytexture; // texture used draw enemies private bool wavefinished = false; // current wave over? private level level; // reference our level class. public wave currentwave // wave @ front of queue { { return waves.peek(); } } public list<enemy> enemies // list of current enemeies { { return currentwave.enemies; } } public int round // returns wave number { { return currentwave.roundnumber + 1; } } public wavemanager(player player, level level, int numberofwaves, texture2d enemytexture, texture2d healthtexture) { this.numberofwaves = numberofwaves; this.enemytexture = enemytexture; this.level = level; (int = 0; < numberofwaves; i++) { int initialnumerofenemies = 6;//nĂºmero de inimigos por wave <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< int numbermodifier = (i / 6) + 1; // pass reference player, wave class. wave wave = new wave(i, initialnumerofenemies * numbermodifier, player, level, enemytexture, healthtexture); waves.enqueue(wave); } startnextwave(); } private void startnextwave() { if (waves.count > 0) // if there still waves left { waves.peek().start(); // start next 1 timesincelastwave = 0; // reset timer wavefinished = false; } } public void update(gametime gametime) { currentwave.update(gametime); // update wave if (currentwave.roundover) // check if has finished { wavefinished = true; } if (wavefinished) // if has finished { timesincelastwave += (float)gametime.elapsedgametime.totalseconds; // start timer } if (timesincelastwave > 10.0f) // if 10 seconds has passed tempo entre waves <<<<<<<<<<<<< { waves.dequeue(); // remove finished wave startnextwave(); // start next wave } } public void draw(spritebatch spritebatch) { currentwave.draw(spritebatch); } }
without seeing wave
class can't guess draw
function looks this:
spritebatch.draw( content.load<texture2d>("wave"), new rectangle(0, 0, width, height), color.black);
when should (note change in color):
spritebatch.draw( content.load<texture2d>("wave"), new rectangle(0, 0, width, height), color.white);
Comments
Post a Comment