-1

In SpriteKit, I can use touch locatons to record "Hits" in a target, where center of the target, "bulls eye" have the coordinates (0,0). After plenty of shooting, I will fetch all hits as an array with CGPoints. Since the target is 500 x 500 points (SKScene, sks-file), all hits can have a x position from -250 to +250 and likewise for y position.

Target

In the attatched photo, the hits are registered as points at around (150, 150).

The problem arises when I will use the famous LFHeatMap https://github.com/gpolak/LFHeatMap.

+ (UIImage *)heatMapWithRect:(CGRect)rect 
                       boost:(float)boost 
                      points:(NSArray *)points 
                     weights:(NSArray *)weights;

The LFHeatMap generates a UIImage based on the array, which I add to a UIImageView. The problem is that the UIViews has the x and y values arranged differently from SKScenes

func setHeatMap() {

        let points = getPointsFromCoreData()
        let weigths = getWeightsFromCoreData()

        var rect = CGRectMake(0, 0, 500, 500)
        rect.origin = CGPointMake(-250, -250)


        let image = 
LFHeatMap.heatMapWithRect(rect, boost: 1, points: points, weights: weights)
        heatMapView.contentMode = UIViewContentMode.ScaleAspectFit
        heatMapView.image = image
    }

enter image description here

Lowering the shots makes the heat move higher.

How can I solve this? Either All points have to be converted to fit another coordinate system, or the coordiate of the CGrect making the heatmap, must be changed. How can this be done?

Tom Tallak Solbu
  • 559
  • 6
  • 20

1 Answers1

1

This was embarrasingly easy when the solution first occured. Run a loop trough the points array, and multiply the point.y with -1... Then all the valus on the y-axis is correct.

Tom Tallak Solbu
  • 559
  • 6
  • 20