i need help
Can anyone help me?
How do I call a method from a different class?
Can anyone help me?
How do I call a method from a different class?
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();
}
}
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);
}
}
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.