0

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();
}
4

0 回答 0