[RESOLVIDO] Rectangle.IntersectsWith - C#

2 respostas
G

Olá!

Estou tentando checar se qualquer (any) Objeto Rectangle dentro da lista HeightMap, colide com (IntersectsWith) com o jogador:

foreach (Rectangle rec in HeightMap) { bool intersects = HeightMap.Any(rec.IntersectsWith(PlayerRectangle)); if(intersects) Console.Write("Algum retângulo da lista HeightMap está colidindo com o jogador!"); }

O problema é que recebo o seguinte erro:

P.S: RESUMIDO

Se alguém puder me ajduar, ficarei muito grato.

2 Respostas

Adelar

Olá,
rec.IntersectsWith(PlayerRectangle) retorna boolean… acho que só ele no if já verifica se houve intersecção.

Att.

Oenning

Eu acho que deveria ser assim:

bool intersects = HeightMap.Any(rec => rec.IntersectsWith(PlayerRectangle));
if(intersects) Console.Write("Algum retângulo da lista HeightMap está colidindo com o jogador!");

Pode remover o Loop neste caso, o próprio .Any vai fazer o loop e retornar se algum “rec” colide com PlayerRectangle.

Criado 26 de junho de 2010
Ultima resposta 26 de jun. de 2010
Respostas 2
Participantes 3