c# - field is never assigned to and will always have default value nulls -
i'm getting error sorry goofed need alter values , dont know how quetion how alter values null
field never assigned , have default value nulls
in next code, indicated:
graphicsdevicemanager graphics; spritebatch spritebatch; // ling gives me field never assigned , alwayhave defult value nulls c# texture2d mariotexture; int marioypos=100; int marioxpos=100; int mariowidth=64; int marioheight=64; // , line give me field never assigned , alwayhave defult value nulls c# texture2d pongballfinaltexture; int pongballfinalypos=50; int pongballfinalxpos=50; int pongballfinalwidth=32; int pongballfinalheight=32; graphics.graphicsdevice.clear (color.cornflowerblue); spritebatch.begin (); spritebatch.draw (mariotexture, new rectangle (marioxpos, marioypos, mariowidth, marioheight), color.white); base.draw (gametime); spritebatch.draw (pongballfinaltexture, new rectangle (pongballfinalxpos, pongballfinalypos, pongballfinalwidth, pongballfinalheight), color.white); base.draw (gametime); spritebatch.end ();
well, in code posted, never assign value 2 fields giving error, declare them. using uninitialized variables not allowed in c#. these 2 have null value because that's default variables of object types other basic language types described in default values table (c# reference).
to create work, need assign values, same positions , sizes there. e.g. straight in declaration:
texture2d mariotexture = new texture2d(graphics.graphicsdevice, mariowidth, marioheight); texture2d pongballfinaltexture = new texture2d(graphics.graphicsdevice, pongballfinalwidth, pongballfinalheight); or later in program, separate declaration, before used:
texture2d mariotexture; texture2d pongballfinaltexture; ... mariotexture = new texture2d(graphics.graphicsdevice, mariowidth, marioheight); pongballfinaltexture = new texture2d(graphics.graphicsdevice, pongballfinalwidth, pongballfinalheight); using basic constructor. it's example, have know how want build textures, assign them.
c# null
No comments:
Post a Comment