删除 RECT 作为碰撞检测的跟踪点

问题描述 投票:0回答:0

具有 SHAPES 和周围的 RECT 以检测对象之间的碰撞。 RECT 和 SHAPES 同时在 CANVAS 上移动。仅绘制 SHAPES - RECT 不可见。现在... 我正在使用 RECT 作为画布上移动对象(形状)的轨迹。后进先出类根据最新“信息素”在画布上的位置丢弃最旧的 RECT。根据主机的移动,在后进先出堆栈中排在第一位。 其他对象(形状)使用碰撞检测来跟踪轨迹。 *如何从画布中删除褪色的 RECT 以节省内存并避免意外碰撞? *

将“死”RECTS 设置为默认位置似乎不是一个好主意...... 寻找类似的东西: g.DrawRectangle(pen, 100,100, 100, 200); g.dispose();

我的形状(鲍勃)

public Species(int _index, Genome _genome)
        {
            this.Alive = true;
            this.EmitSignal = false;
            this.Challange = false;
            this.Index = _index;
            this.Age = 0;
            this.Fitness = 0;
            this.Speed = P.SPEED;
            this.Loc = FindBirthLoc(_index);
            this.LastMove = MoveDir();
            this.Genepool = _genome;
            this.BobNet = MakeBobNet(Genepool);
            this.BobSig = new Species.LIFOBuffer<Rect>(P.SIGFADE);
            peeps.Add(this);
        }

我的后进先出堆栈:

public class LIFOBuffer<T> : LinkedList<T>
        {
            private int capacity;
            private LinkedListNode<T> node;
            public LIFOBuffer(int capacity)
            {
                this.capacity = capacity;
            }
            public T Add(T item)
            {
                if (Count == capacity)
                {
                    node = Last;
                    RemoveLast();
                    AddFirst(item);
                    return node.Value;
                }
                else
                {
                    AddFirst(item);
                    return default(T);
                }
            }
        }

BOB 被 Vector _p 移动,留下新的痕迹:

public static Rect SetSignal(Species _Bob , Vector _p)
        {
            Rect _rsig = new Rect((Point)_p, P.SIGSIZE);
            Rect _deadsig = _Bob.BobSig.Add(_rsig);
            return _deadsig;
        }

此例程“生成”新的 RECT,但缺少删除 _deadsig。

c# canvas collision-detection rect
© www.soinside.com 2019 - 2024. All rights reserved.