这里ballList
是精灵列表。在触摸精灵时,图像会发生变化。
问题在于当触摸区域中存在两个精灵时,即在具有放置精灵的位置的列表中应该发生图像变化时,图像变化仅需要一个精灵,尽管循环运行对于精灵的数量,其位置在列表中。
如何解决这个问题?
void OnTouchBegin(List<CCTouch> arg1, CCEvent arg2) {
var target = arg2.CurrentTarget.BoundingBox;
location = arg1[0].Location;
CCRect touchArea = new CCRect(location.X, location.Y, 100, 100);
// positionList = TouchAreaContainsPoint(location);
var node = new CCDrawNode();
if (touchArea.ContainsPoint(location)) {
action1 = new CCSequence(new CCCallFunc(Callback1));
RunActionAsync(action1);
}
}
void Callback1() {
positionList = TouchAreaContainsPoint(location);
if (positionList.Count > 0) {
for (i = 0; i < positionList.Count; i++) {
CCPoint pos = positionList[i];
spriteEntity.PositionX = pos.X;
spriteEntity.PositionY = pos.Y;
this.AddChild(spriteEntity);
}
}
//throw new NotImplementedException();
}
CCPoint PlacePoints(int i) {
CCPoint position;
double x = (26.783879 * 19.692) / 180;
double y = (75.841477 * 19.692) / 360;
CCPoint userLocation = new CCPoint((float)x, (float)y);
position.X = 465 - userLocation.X;
position.Y = (float)(513.5 - userLocation.Y);
return position;
//throw new NotImplementedException();
}
List<CCPoint> TouchAreaContainsPoint(CCPoint location) {
for (i = 0; i < ballList.Count; i++) {
CCPoint position = PlacePoints(i);
float differenceX = Math.Abs(position.X - location.X);
float differenceY = Math.Abs(position.Y - location.Y);
if ((Math.Pow(differenceX,2) + Math.Pow(differenceY,2)) < Math.Pow(50.0,2)) {
positionList.Add(position);
} else {
continue;
}
}
return positionList;
//throw new NotImplementedException();
}