Microsoft Game Technologies: xna sprite and background

  • carroll_iain / 100 / Mon, 25 Jan 2010 18:11:00 GMT / Comments (11)
  • can anyone tell me how do i see my sprite character over my background which is scrolling. the both work independentl but when i put them together i can only see the background image. id say the character is still there but behind the background.

    i heard its using layer but still cant figure it out.
    so i just want to see my charater sprite with the background in the background.

    help me please

  • Keywords:

    xna, sprite, background, microsoft, game

  • http://msdn.itags.org/microsoft-game/244795/«« Last Thread - Next Thread »»
    1. carroll.iain wrote:
      help me please

      Code, please.

      jimperry | Fri, 07 Sep 2007 17:03:00 GMT |

    2. today i attended to microsoft techdays academic track in lisbon, portugal.

      rob miles brilliantly introduced us to xna and in one of his code samples he shown how to create a background

      you can find the code samples in his website, here

      04 CheeseBreakout - Backdrop.zip > BackDrop.cs

      public override void Initialize()

      {

      Game1 parent = this.Game as Game1;

      content = parent.content;

      this.DrawOrder = 0;

      base.Initialize();

      }

      DrawOrder = 0; tells that texture should be placed in the background

      just trying to help, hope it does

      hda | Fri, 07 Sep 2007 17:04:00 GMT |

    3. If you are drawing both items in a single SpriteBatch, make sure the background is drawn first.

      MySpriteBatch.Begin();
      MySpriteBatch.Draw(Background... etc...);
      MySpriteBatch.Draw(Player... etc...);
      MySpriteBatch.End();

      If you are drawing them in 2 separate SpriteBatches, make sure the background SpriteBatch is drawn first

      BackgroundBatch.Begin();
      BackgroundBatch.Draw(Background... etc...);
      BackgroundBatch.End();

      PlayerBatch.Begin();
      PlayerBatch.Draw(Player... etc...);
      PlayerBatch.End();

      leec22 | Fri, 07 Sep 2007 17:05:00 GMT |

    4. thanks. its working grand now. im not to familar with xna or game programming so this is all new to me.

      my

      next problem is that although i can now see my character, i can see him

      inside a box. how can i make the box part blend in with the bcakround

      so that i can only see my character.
      does that make sense. im looking into it myself but would appriciate any help.

      carroll_iain | Fri, 07 Sep 2007 17:06:00 GMT |

    5. carroll.iain wrote:
      thanks. its working grand now. im not to familar with xna or game programming so this is all new to me.

      my next problem is that although i can now see my character, i can see him inside a box. how can i make the box part blend in with the bcakround so that i can only see my character.

      does that make sense. im looking into it myself but would appriciate any help.


      You need to make sure that the area around the character is actually transparent in the image. For this, you have to make sure you are saving the image in a format that supports transparency. PNG is favourite and is the format I would recommend. Depending on the paint package you are using, it could be done in different ways but basically it should be just a case of telling the package which colour you want as transparent.

      leec22 | Fri, 07 Sep 2007 17:07:00 GMT |

    6. ok. so do i do that in the paint program im using or is it a property i set in the xna studio.

      carroll_iain | Fri, 07 Sep 2007 17:08:00 GMT |

    7. If you make the box around the sprite magenta and call the SpriteBatch's Begin with the SpriteBlendMode.AlphaBlend paramter, you should be good.

      jimperry | Fri, 07 Sep 2007 17:09:00 GMT |

    8. sorry but that didnt work. i did what u said with the magenta but i can just see that now instead of the previous color. i set the SpriteBatch Begin with the parameter u said as well but no luck.

      thanks anyway.

      any other ideas

      carroll_iain | Fri, 07 Sep 2007 17:10:00 GMT |

    9. You still haven't shown us your code so it's hard to off advice.

      jimperry | Fri, 07 Sep 2007 17:11:00 GMT |

    10. it ok i got it working. i just used the Direct X SDK texture tool. and i didnt have to alter any code. i found the help on xna tutorials web site.

      carroll_iain | Fri, 07 Sep 2007 17:12:00 GMT |

    11. If you find out what the problem was, you can avoid using that tool. I found it a pain to keep using that. What paint software are you using?

      If you can tell me this, I can tell you the steps you need to go through to get the PNG with a transparent background, which will make life much easier.

      leec22 | Fri, 07 Sep 2007 17:13:00 GMT |