c# - ArgumentNullException was unhandled What is wrong? -


i have written class load xml file error message:

argumentnullexception unhandled method not accept null parameter. parameter name: texture

i error message in batch.draw():

public void draw(spritebatch batch) { batch.draw( texture, position, null, color.white, rotation, vector2.zero, scale, spriteeffects.none, 0f); } 

what wrong in sprite class? uploaded project here: http://depositfiles.com/files/kj4an4ef7

the problem that, error says, variable texture in sprite drawing code null.

the cause of problem is: call load() method load list of sprites xml file, won't reconstruct texture property of sprite class. thus, fix error, each sprite should call load() too.

that means, in loadcontent() method of game1 class, after sprites = content.load<list<sprite>>("levelinf"); line, this:

foreach(sprite sprite in sprites) { sprite.load(content); } 

now, each sprite have it's texture loaded.

ps: more c# /xna problem rather xml 1 :)


Comments

Popular posts from this blog

javascript - backbone.js Collection.add() doesn't `construct` (`initialize`) an object -

php - Get uncommon values from two or more arrays -

Adding duplicate array rows in Php -