i need help

Can anyone help me?

How do I call a method from a different class?

[80 byte] By [Mrperson] at [2007-12-26]
# 1

Very strange question :)

first example (static method):

class MyClass

{

public static void MyMethod()

{

}

}

class AnotherMyClass

{

public AnotherMyClass()

{

MyClass.MyMethod();

}

}

second example:

class MyClass

{

public void MyMethod()

{

}

}

class AnotherMyClass

{

MyClass myClass;

public AnotherMyClass()

{

myClass=new MyClass();

myClass.MyMethod();

}

}

Xadja at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 2
Time to get a good book on c# and object oriented programming..... :|
PeterD. at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 3
/me wonders what this has to do with GSE
JimPerry at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 4

As well as the answers above you can also inject it into the constructor

public class Foo
{
public static FooMethod(){}
}

public class Bar
{
Foo _Foo;
public Bar(Foo foo)
{
_Foo = foo;

// call method on Foo
_Foo.FooMethod();
}
}

public class Bat
{
public Bat()
{
Foo foo = new Foo();

// inject foo into Bar
Bar bar = new Bar(foo);
}
}

Fluxtah at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...
# 5
The above posters are correct in both their answer and their suggestions that maybe you should take a step back and fine tune your C# development skills before pushing ahead with your game.

The question you asked was a valid one, but a very simple one. While XNA has made game development easier, it hasn't removed the need for you to understand development. I worry that you are just going to unnecessarily frustrate yourself trying to learn game development while learning basic development concepts in general.

With that said, I don't think it will take you long to get up to speed. You don't need to be a C# expert to make a game with XNA, you just need to have a grasp on the syntax of the language and basic ideas of development strategies in general.

You can look online for some C# training, or you could get some books on learning C# .NET. The language has been out for a while now, so picking some beginning C# books up should be relatively inexpensive. You can also try and look for some community classes in your area. Often, they will offer some computer training (including development training) for free or at a very reasonable price. You can also see if any local colleges offer some classes on development.

Whichever method you choose, you're just going to make your game development go much easier once you understand the language you're developing with. Good luck on brushing up on those skills and I'm looking forward to seeing your first game.

GeorgeClingerman at 2007-9-4 > top of Msdn Tech,Game Technologies: DirectX, XNA, XACT, etc.,XNA Game Studio Express...