SpriteKit:检测旋转节点的重叠?

时间:2015-04-28 20:33:57

标签: ios objective-c iphone swift sprite-kit

假设nodeA是nodeB的子节点。更改nodeB的zRotation值会有效地旋转nodeA,但nodeA的位置(因为它相对于nodeB)保持不变。

现在假设nodeA已从nodeB中删除,但其位置在屏幕中保持不变。 nodeC被添加到nodeB并旋转。

如何检测nodeC和nodeA之间的重叠? SKNode as described here中的containsPoint无法正常工作,因为nodeC和nodeA位置都不会因轮换而发生变化。

1 个答案:

答案 0 :(得分:2)

您可以测试与function [features,weights] = MI(features,labels,Q) if nargin <3 Q = 12; end edges = zeros(size(features,2),Q+1); for k = 1:size(features,2) minval = min(features(:,k)); maxval = max(features(:,k)); if minval==maxval continue; end quantlevels = minval:(maxval-minval)/500:maxval; N = histc(features(:,k),quantlevels); totsamples = size(features,1); N_cum = cumsum(N); edges(k,1) = -Inf; stepsize = totsamples/Q; for j = 1:Q-1 a = find(N_cum > j.*stepsize,1); edges(k,j) = quantlevels(a); end edges(k,j+2) = Inf; end S = zeros(size(features)); for k = 1:size(S,2) S(:,k) = quantize(features(:,k),edges(k,:))+1; end I = zeros(size(features,2),1); for k = 1:size(features,2) I(k) = computeMI(S(:,k),labels,0); end [weights,features] = sort(I,'descend'); %% EOF function [I,M,SP] = computeMI(seq1,seq2,lag) if nargin <3 lag = 0; end if(length(seq1) ~= length(seq2)) error('Input sequences are of different length'); end lambda1 = max(seq1); symbol_count1 = zeros(lambda1,1); for k = 1:lambda1 symbol_count1(k) = sum(seq1 == k); end symbol_prob1 = symbol_count1./sum(symbol_count1)+0.000001; lambda2 = max(seq2); symbol_count2 = zeros(lambda2,1); for k = 1:lambda2 symbol_count2(k) = sum(seq2 == k); end symbol_prob2 = symbol_count2./sum(symbol_count2)+0.000001; M = zeros(lambda1,lambda2); if(lag > 0) for k = 1:length(seq1)-lag loc1 = seq1(k); loc2 = seq2(k+lag); M(loc1,loc2) = M(loc1,loc2)+1; end else for k = abs(lag)+1:length(seq1) loc1 = seq1(k); loc2 = seq2(k+lag); M(loc1,loc2) = M(loc1,loc2)+1; end end SP = symbol_prob1*symbol_prob2'; M = M./sum(M(:))+0.000001; I = sum(sum(M.*log2(M./SP))); function y = quantize(x, q) x = x(:); nx = length(x); nq = length(q); y = sum(repmat(x,1,nq)>repmat(q,nx,1),2); 交叉的节点。但在这种情况下,节点需要位于同一节点树中。也许你不应该在测试之前从nodeB中删除nodeA?