XNA中组件之间的变量的访问与赋值问题

来源:互联网 发布:金蝶k3数据引出无反应 编辑:程序博客网 时间:2024/06/05 05:46

When we are developing XNA, getting hang of using XNA Component is very necessary. And I have come across many problems in these days.

Problem. How to realize to swap parameters among different Components ?

Solution: Of course we have a main function and the game start from this .cs file. e.g. we want to give parameter a1 in Component cA to parameter b1 in class cB. 

         First, instantiate cA and cB as A and B in main file. 

         Second, realize the swapping in Update() function. Often, we code like this " B.b1 = A.a1". But I get an error tip like this"无法修改类中的结构体成员的属性,提示错误返回值不是一个变量";  In this case, we should declare the b1 like this:

         public parameterType b1;

 public parameterType _b1

        {

             get{return b1;}

             set{b1 = value};

        }

Then the error is solved!

There is still a long way to go...