Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,869 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,629 people online right now. Registration is fast and FREE... Join Now!




A Field initializer cannot reference the nonstatic field, method, or p

 
Reply to this topicStart new topic

A Field initializer cannot reference the nonstatic field, method, or p, XNA with C#

rgfirefly24
30 Jul, 2008 - 06:45 AM
Post #1

D.I.C Regular
Group Icon

Joined: 7 Apr, 2008
Posts: 332



Thanked: 5 times
Dream Kudos: 150
My Contributions
ok, so i'm working on creating the image in the middle of the viewport. To do this i am using the this.graphics.ToggleFullScreen() to set fullscreen, then attempting to use graphics.GraphicsDevice.Viewport.Height and width.

csharp

protected override void Initialize()
{
// TODO: Add your initialization logic here
player1 = new Player1();
this.graphics.ToggleFullScreen();
player1.setposition(graphics.GraphicsDevice.Viewport.Height, graphics.GraphicsDevice.Viewport.Width);


base.Initialize();
}


now the player1.setposition function takes in those two arguments and sets them equal to the Vector2 position:

csharp

private float positionwidth = 0;
private float positionheight = 0;
public Vector2 Position = new Vector2((positionwidth/2),(positionheight/2));
private Texture2D CardTexture1;

public void setposition(float inheight, float inwidth)
{
this.positionwidth = inwidth;
this.positionheight = inheight;
}


when i try and build it givies me the error

A field initializer cannot reference the nonstatic field, method, or property positionwidth and positionheight.

not sure exactly what it means.
User is offlineProfile CardPM
+Quote Post

rgfirefly24
RE: A Field Initializer Cannot Reference The Nonstatic Field, Method, Or P
30 Jul, 2008 - 10:10 AM
Post #2

D.I.C Regular
Group Icon

Joined: 7 Apr, 2008
Posts: 332



Thanked: 5 times
Dream Kudos: 150
My Contributions
so i figured out that apparently when using Vector2D with variable x and y that you have to do it within the function that is being called by the other class. The whole setting local variables from outside the class doesnt cut it here.


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/3/08 07:49PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month