0

質問のタイトルがわかりにくかったら申し訳ありませんが、私の下手な英語では、はっきりと質問する方法が見つかりません。

しかし、私はそれを長い道のりで説明することができます。

だから、私が自分の世界をデザインすれば(そして世界とは、ゲーム全体を意味する、それは1つのレベルになる)10.000x10.000 ...それは非常に十分であることに気づきました。 5 で最大 50x50、大したことはありません。)

それで、マップ全体を10.000x10.000(または512x512のトンとしましょう)の画像にしないのはなぜだと思いましたか?しかし、1 つ質問があります。「対話」できるものはほとんどありません。それらは(つまり、私の「world.jpg」にあるものを意味します)常に同じ場所にとどまりますが、プレーヤー(実際にはご存知のようにスプライトです)は移動するため、私の10.000x10.000は「動く"。

下の写真を見てください。黒い点が「プレーヤー」で、赤い点がドアです。

彼が世界の果てに行かない限り、世界は常に黒い点を中心にしています。ご覧のとおり (写真のパート 1 とパート 2 を参照)、彼が少し東に移動すると、赤い点が移動したように見えます。10.000x10.000 の画像を移動しました。それが、10kx10k pic のものが動くという意味です。

とにかく、しかし、写真の最後の部分でわかるように、彼が赤い点に近づいたとき、私は「アクション」をしたいです

どうやってするの ?

-以下の部分は、実際には主な質問とは関係ありません

彼が移動したときに世界に現れる別のスプライトの代わりに 10kx10 pic を使用することは有用ですか? しかし、それをしたい場合は、彼が近くにいるかどうかを確認するだけでなく、彼にスプライトを表示する必要があるかどうかを判断するために彼のポイントも確認します.

欲しいコーディネートが来たら自分の物を見せた方が使いやすいですか、それとも大きな写真1枚でもいいですか?

ありがとう。

4

3 に答える 3

1

赤い点の半径内で衝突検出を求めている場合。次のテストを使用するだけです (疑似コード、私は C# を書きません :-)

if( (player.GetPosition() - point.GetPosition()).length() < radius )
{ /* Do code here */ }

これにより、プレーヤーがドットの特定の半径内にあるかどうかが検出され、その後、必要なアクションを実行できます。

お役に立てれば!:)

于 2011-07-25T10:51:11.880 に答える
1

このようなマップの構造をお勧めします..

public class Map
{
     public MapPoint[,] mapPoints;       //the map
     public Player player;               //the player/user object
     public Vector2 DrawHeroPosition;    
     //where at the screen the player is going to be drawn
     public Vector2 RangeStart;          
     //what part of the map who is going to be drawn
     public int SizeX;     //number of mapPoints the screen can contain at one time 
     public int SizeY;     //number of mapPoints the screen can contain at one time 

     //MapPoint represents a specific 512x512 point (mapPoint) its position at
     //the map but also includes the sprite that is going to be drawn and objects
     //that the player can interact with at that place (like the door)

     //the player object includes reference to where in the world it is place

     public Map(ContentManager theContentManager, int x, int y)
     {
        MapSizeX = x;
        MapSizeY = y;
        int ScreenSizeX = 9;
        int ScreenSizeY = 9;
        mapPoints = new MapPoint[MapSizeX , MapSizeY];

        //ad code for generating/creating map...
        //important that you store the MapPoints position inside each mapPoint

        player = new Player(mapPoints[0,0]);  //crate a player who knows where he is
    }

    public void Update()
    {
       //in the update method you do a lot of things like movement and so
       //set what part of the map the game should draw if the game for example
       //can show 9x9 512points at a single time

       //give range value from the players position
        RangeStart.X = player.PositionX;

        //test if the maps position is in the left corner of the map
        //if it is draw the map from the start..(RangeStart.X = 0)
        if (player.PositionX - (ScreenSizeX / 2) < 0) { RangeStart.X = 0; }
        //if not draw the hero in the mitle of the screen
        else
        {
            RangeStart.X = player.PositionX - (ScreenSizeX / 2);
        }
        //if the hero is in the right corer, fix his position
        while (RangeStart.X + ScreenSizeX > MapSizeX)
        {
            RangeStart.X--;
        }

        //the same thing for the Y axle
        RangeStart.Y = player.PositionY;
        if (player.PositionY - (ScreenSizeY / 2) < 0) { RangeStart.Y = 0; }
        else
        {
            RangeStart.Y = player.PositionY - (ScreenSizeY / 2);
        }
        while (RangeStart.Y + ScreenSizeY > MapSizeY)
        {
            RangeStart.Y--;
        }

        //time to set the position of the hero...
        //he works like the opposite of the range, if you move what part of the map
        //you draw you dont change the heros draw position, if you dont move the range
        //you have to move the hero to create the illusion of "moment"

        //if you are in the left part you have to move the heros draw position..
        if (player.PositionX - (ScreenSizeX / 2) < 0) 
        { DrawHeroPosition.X = player.PositionX; }

        //if you are in the right part
        else if (player.PositionX+1 > MapSizeX - (ScreenSizeX / 2))
        {
            DrawHeroPosition.X = player.PositionX - (MapSizeX - ScreenSizeX);
        }

        //if you aint in a corner, just place the hero in the middle of the map
        else
        {
            DrawHeroPosition.X = (ScreenSizeX / 2);
        }


        //the same thing for Y
        if (player.PositionY - (ScreenSizeY / 2) < 0) 
        { DrawHeroPosition.Y = player.PositionY; }
        else if (player.PositionY+1 > MapSizeY - (ScreenSizeY / 2))
        {
            DrawHeroPosition.Y = player.PositionY - (MapSizeY - ScreenSizeY);
        }
        else
        {
            DrawHeroPosition.Y = (ScreenSizeY / 2);
        }

    }

    public void Draw()
    {

        int x = (int)RangeStart.X;
        int y = (int)RangeStart.Y;

        for(int counterX = 0; x < ((MapSizeX)); x++, counterX++)
        {
            for (int counterY = 0; y < (MapSizeY); y++, counterY++)
            {
               if (mapPoints[x, y] != null)
               {
                 mapPoints[x, y].Draw(spriteBatch, mapPoints[counterX,counterY].positonInMatrix);
                 //mapPoints[counterX,counterY] = where to draw
                 //mapPoints[x, y] = what to draw
               }
            }
            y = (int)RangeStart.Y;
        }
    }
}

MapPoint クラス内で描画する方法...

public void Draw(SpriteBatch theSpriteBatch, Vector2 positonOnScreen)
    {
        positonOnScreen = new Vector2(positonOnScreen.X * base.Scale * 16,
        positonOnScreen.Y * base.Scale * 16);

        //base.Scale is just a variable for have the ability to zoom in/out
        //16 represents the original size of the picture (16x16 pixels)

        theSpriteBatch.Draw(mSpriteTexture, new Rectangle((int)positonOnScreen.X,
        (int)(positonOnScreen.Y), 64, 64),new Rectangle(0, 0, 16, 16), Color.White);
     }
于 2011-07-25T09:11:25.853 に答える
0

わかりました、あなたの質問について私が理解していることから、プレーヤーに操作してもらいたいさまざまなオブジェクトを含む大きな画像がありますか? つまり、画像ファイル自体には、プレイヤーが操作するドアや丘などがあります。

これは正直なところ悪い考えなので、誤解しているといいのですが。背景画像を一般的なものにして、ゲーム内のすべてのインタラクティブ オブジェクト クラスを作成する方がはるかに優れています。これを行うと、距離 (円の衝突) に基づいて、または定義したバウンディング ボックスに基づいて、互いに交差する動作をオブジェクト クラスに含めることができます。

サークル衝突:

if (Math.Abs(Vector2.Distance(player.Position - obj.Position)) < player.Radius + obj.Radius)
    //do the action

長方形衝突:

if (player.Bounds.Intersects(obj.Bounds))
   //do the action

また、10,000 x 10,000 ピクセルの画像の作成を計画している場合、XNA コンテンツ パイプラインは 1 辺が 4,000 ピクセルを超える画像をインポートしないことを理解してください。

プレーヤーが画像の背景のピクセルと対話するように設定されている場合は、インタラクティブなオブジェクトの位置の配列を手動で作成するか、Texture2D.GetData() メソッドを使用してすべてのピクセルの色を読み込むことができます。処理のための画像 -- ただし、特に大きなテクスチャや多数のテクスチャの場合、これには長い時間がかかることに注意してください。

于 2011-07-25T21:48:18.093 に答える