XNAには2つのクラスがあります。XNAでクラスを取得してお互いに「話す」
maingame.cs と player.cs私maingame.csで
は私はマウスがある場所に描画された矩形を持って、私はクリックするためにこれを使用しています。私のplayer.csにはプレーヤーのスプライトの矩形があります。
私は問題はplayerRectangleがPlayer.CSにあり、mouseRectangleがあるということである
if (ButtonState.Pressed == mouseState.LeftButton && mouseRectangle.Intersects(playerRectangle))
{
//draw something
}
のようなものを持つことができるように、お互いにこの2つのクラス「話」を作るためにどのよう見当がつかないmaingame.CS
どのようにしてこれら2つを互いに話すことができますか?私は何時間もグーグルで運がありませんでした。
Player.CS私はMainGame.CSで私のマウスの矩形が
を行うことによって、それをクリックすることができるようにそれを作るしようとしているusing System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
namespace PlanetDefence
{
class Battleship
{
//Textures
Texture2D playerBattleshipTexture;
//Rectangles
Rectangle playerBattleshipRectangle;
//Integers
public Battleship(Texture2D newPlayerBattleshipTexture, Rectangle newPlayerBattleshipRectangle)
{
playerBattleshipTexture = newPlayerBattleshipTexture;
playerBattleshipRectangle = newPlayerBattleshipRectangle;
newPlayerBattleshipRectangle = new Rectangle(100, 100, 100, 100);
}
public void Update()
{
}
public void Draw(SpriteBatch spriteBatch)
{
//Draw the player Battleship
spriteBatch.Draw(playerBattleshipTexture, playerBattleshipRectangle, Color.White);
}
}
}
のように見えます
if (ButtonState.Pressed == mouseState.LeftButton && mouseRectangle.Intersects(playerBattleshipRectangle))
{
playerBattleship.Draw(spriteBatch);
}
さて、リファレンスを正確に追加するにはどうすればよいですか? – Algalogica
@Algalogica - 私は説明しました。 – Oded
ありがとうございました。回答が編集されました。 – Algalogica