Note that there are some explanatory texts on larger screens.

plurals
  1. POCannot implicitly convert type 'WindowsGame24.Bullet' to 'WindowsGame24.Enemy'
    text
    copied!<p>I get this error message in the Draw method of the Map class. What is wrong? I want to draw the bullets which I create in the Enemy class. Cannot implicitly convert type 'WindowsGame24.Bullet' to 'WindowsGame24.Enemy'</p> <pre><code>public class Map { Texture2D myEnemy, myBullet ; Player Player; List&lt;Enemy&gt; enemieslist = new List&lt;Enemy&gt;(); List&lt;Bullet&gt; bulletslist = new List&lt;Bullet&gt;(); float fNextEnemy = 0.0f; float fEnemyFreq = 3.0f; int fMaxEnemy = 3 ; Vector2 Startposition = new Vector2(200, 200); GraphicsDeviceManager graphicsDevice; public Map(GraphicsDeviceManager device) { graphicsDevice = device; } public void Load(ContentManager content) { myEnemy = content.Load&lt;Texture2D&gt;("enemy"); myBullet = content.Load&lt;Texture2D&gt;("bullet"); Player = new Player(graphicsDevice); Player.Load(content); } public void Update(GameTime gameTime) { Player.Update(gameTime); float delta = (float)gameTime.ElapsedGameTime.TotalSeconds; for(int i = enemieslist.Count - 1; i &gt;= 0; i--) { // Update Enemy Enemy enemy = enemieslist[i]; enemy.Update(gameTime, this.graphicsDevice, Player.playershape.Position, delta); // Try to remove an enemy if (enemy.Remove == true) { enemieslist.Remove(enemy); enemy.Remove = false; } } this.fNextEnemy += delta; //New enemy if (fMaxEnemy &gt; 0) { if ((this.fNextEnemy &gt;= fEnemyFreq) &amp;&amp; (enemieslist.Count &lt; 3)) { Vector2 enemyDirection = Vector2.Normalize(Player.playershape.Position - Startposition) * 100f; enemieslist.Add(new Enemy(Startposition, enemyDirection, Player.playershape.Position)); fMaxEnemy -= 1; fNextEnemy -= fEnemyFreq; } } } public void Draw(SpriteBatch batch) { Player.Draw(batch); for (int i = enemieslist.Count - 1; i &gt;= 0; i--) { Enemy enemy = enemieslist[i]; enemy.Draw(batch, myEnemy); } Enemy bullets; for (int i = bullets.bulletslist.Count - 1; i &gt;= 0; i--) { Enemy bullet = bullets.bulletslist[i]; bullet.Draw(batch, myBullet); } } } public class Enemy { public List&lt;Bullet&gt; bulletslist = new List&lt;Bullet&gt;(); private float nextShot = 0; private float shotFrequency = 2.0f; Vector2 vPos; Vector2 vMove; Vector2 vPlayer; public bool Remove; public bool Shot; public Enemy(Vector2 Pos, Vector2 Move, Vector2 Player) { this.vPos = Pos; this.vMove = Move; this.vPlayer = Player; this.Remove = false; this.Shot = false; } public void Update(GameTime gameTime, GraphicsDeviceManager graphics, Vector2 PlayerPos, float delta) { nextShot += delta; for (int i = bulletslist.Count - 1; i &gt;= 0; i--) { // Update Bullet Bullet bullets = bulletslist[i]; bullets.Update(gameTime, graphics, delta); // Try to remove a bullet... Collision, hit, or outside screen. if (bullets.Remove == true) { bulletslist.Remove(bullets); bullets.Remove = false; } } if (nextShot &gt;= shotFrequency) { this.Shot = true; nextShot -= shotFrequency; } // Does the enemy shot? if ((Shot == true) &amp;&amp; (bulletslist.Count &lt; 1)) // New bullet { Vector2 bulletDirection = Vector2.Normalize(PlayerPos - this.vPos) * 200f; bulletslist.Add(new Bullet(this.vPos, bulletDirection, PlayerPos)); Shot = false; } if (!Remove) { this.vMove = Vector2.Normalize(PlayerPos - this.vPos) * 100f; this.vPos += this.vMove * delta; if (this.vPos.X &gt; graphics.PreferredBackBufferWidth + 1) { this.Remove = true; } else if (this.vPos.X &lt; -20) { this.Remove = true; } if (this.vPos.Y &gt; graphics.PreferredBackBufferHeight + 1) { this.Remove = true; } else if (this.vPos.Y &lt; -20) { this.Remove = true; } } } public void Draw(SpriteBatch batch, Texture2D myTexture) { if (!Remove) { batch.Draw(myTexture, this.vPos, Color.White); } } } public class Bullet { Vector2 vPos; Vector2 vMove; Vector2 vPlayer; public bool Remove; public Bullet(Vector2 Pos, Vector2 Move, Vector2 Player) { this.Remove = false; this.vPos = Pos; this.vMove = Move; this.vPlayer = Player; } public void Update(GameTime gameTime, GraphicsDeviceManager graphics, float delta) { if (!Remove) { this.vPos += this.vMove * delta; if (this.vPos.X &gt; graphics.PreferredBackBufferWidth +1) { this.Remove = true; } else if (this.vPos.X &lt; -20) { this.Remove = true; } if (this.vPos.Y &gt; graphics.PreferredBackBufferHeight +1) { this.Remove = true; } else if (this.vPos.Y &lt; -20) { this.Remove = true; } } } public void Draw(SpriteBatch spriteBatch, Texture2D myTexture) { if (!Remove) { spriteBatch.Draw(myTexture, this.vPos, Color.White); } } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload