从另一个类调用向量 2

本文关键字:向量 调用 另一个 | 更新日期: 2023-09-27 18:37:04

我正在做一个小游戏来适应XNA。现在我在从另一个类调用变量时遇到了问题。我有一个Game1和一个Player类,现在我想在我的Game1班中调用球员位置。存储在名为 playerPositionVector2中的位置

public class Player
{
    //Playerinformation
    #region
    Texture2D playerImage;
    Vector2 playerPosition, tempCurrentFrame;
    float moveSpeed;
    float speed = 0.2f;
    #endregion
}
public class Game1 : Microsoft.Xna.Framework.Game
{//Here i need the playerPosition, because i want to use it in the game class }

我希望你明白我想要什么,可以帮助我。

从另一个类调用向量 2

正如穆罕默德所建议的,你应该声明:

public Vector2 playerPosition { get; set; }

或者,如果您只想读取该值而不修改它,只需执行以下操作:

public Vector2 playerPosition { get; private set; }

当然,在Game1中,您必须声明一个Player player变量(并调用其构造函数),以便您可以使用player.playerPosition访问该变量。