3

What I'm doing is create a SKTexture based on the full image

SKTexture *fullTexture = [SKTexture textureWithImageNamed:@"fullImage"];

I want to use the full width of the fullTexture, but only a portion of height of the texture, BUT, starting from the TOP of the full image.

After figuring out that the width seems to be in percentage, I used the following code:

SKTexture *croppedTexture = [SKTexture textureWithRect: CGRectMake(0,0,1,percentageY)

can somebody give me the correct float values for CGRectMake to CROP, beginning from the TOP LEFT, with full witdt and only a portion (fixed number of points/pixels) from the Y ?

OR another way to achieve what I am trying to do?

Thanks

Updated the question with visible example of what I need:

enter image description here

stvn
  • 1,148
  • 1
  • 8
  • 24
  • You haven't specified what problem you are experiencing – Andrey Gordeev Feb 19 '14 at 08:29
  • I'm not experience a problem, I just don't know the exact values to use to achieve what I want. You can see it as a problem that: the image crop starts from the bottom of the image and cuts a portion of the top of the image, but I want to start cutting from the TOP but I don't know how to do this. – stvn Feb 19 '14 at 09:44

1 Answers1

1

Try CGRectMake(0,1-percentageY,1,percentageY) instead of CGRectMake(0,0,1,percentageY)

Andrey Gordeev
  • 30,606
  • 13
  • 135
  • 162
  • tried playing with the values myself but this one did not give me the correct result. This seems to give me no image at all. – stvn Feb 19 '14 at 10:16
  • the Y portion of the CGRectMake seems to only work upward. Changing my percentageY by -percentageY gives me an exception tho: 'NSInvalidArgumentException', reason: 'Invalid size specified: {56.5, -695.99998557567596}' So I wish it was that simple. – stvn Feb 19 '14 at 10:27
  • Check my updated answer :). Also, are you sure that `percentageY` lies between 0 and 1 ? How do you calculate it? – Andrey Gordeev Feb 19 '14 at 10:30
  • Oh by, but of course! subtracting the Y percentage from the height did the trick. Very confusing if you ask me. Anyways, thanks alot, it's working now! – stvn Feb 19 '14 at 10:40