Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/304.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使离开屏幕的对象(在全屏模式下)向左,再向右(反之亦然)显示?_C#_Visual Studio_Visual Studio 2015_Panel_Game Physics - Fatal编程技术网

C# 如何使离开屏幕的对象(在全屏模式下)向左,再向右(反之亦然)显示?

C# 如何使离开屏幕的对象(在全屏模式下)向左,再向右(反之亦然)显示?,c#,visual-studio,visual-studio-2015,panel,game-physics,C#,Visual Studio,Visual Studio 2015,Panel,Game Physics,我正在做一个乒乓球游戏,除了球不是从左右两边的墙壁上弹下来,我希望它能穿过墙壁,在另一边重新出现。老实说,我就是不知道如何正确地做到这一点。以下是我目前掌握的一行代码: if (Ball.Right > Playground.Left) { Ball.Left = (Playground.Right + 26); } if (Ball.Left <

我正在做一个乒乓球游戏,除了球不是从左右两边的墙壁上弹下来,我希望它能穿过墙壁,在另一边重新出现。老实说,我就是不知道如何正确地做到这一点。以下是我目前掌握的一行代码:

                if (Ball.Right > Playground.Left)
            {
                Ball.Left = (Playground.Right + 26);
            }
            if (Ball.Left < Playground.Right)
            {
                Ball.Left = (Playground.Left - 1);
            }
if(Ball.Right>playder.Left)
{
球。左=(操场。右+26);
}
如果(球左<操场右)
{
Ball.Left=(playder.Left-1);
}

当球是乒乓球时,操场将是一个面板,当游戏开始时,它将填满屏幕。请帮帮我,我已经为这个游戏工作了一段时间,但似乎无法理解这部分+26是为了防止球因其宽度而妨碍边路,这也适用于-1。

你应该在球离开屏幕后设置位置

if (Ball.Right > Playground.Right)
        {
            Ball.Left = 0;
        }
        if (Ball.Left < Playground.Left)
        {
            Ball.Left = Playground.Right - 1;
        }
if(Ball.Right>playde.Right)
{
左=0;
}
如果(球左<操场左)
{
Ball.Left=操场。Right-1;
}