• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag
 

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Confused about floats
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Confused about floats


  • Subject: Confused about floats
  • From: Amy Heavey <email@hidden>
  • Date: Tue, 5 Oct 2010 10:17:31 +0100

I've got two float values (x and y) that I'm using to change the coordinates of a drawing action that is being looped through. I can add a value to x and it draws the next image along, but I want to test the value of x and if it is out of bounds I want to reset it to zero and increase y, so I get a grid of images drawn.

For some reason, even though I can do
x = x+128;
and it moves the image accross, x seems to be null so I can't test against it, my if statement ' if (x > 300){' always fails.


This must be something really simple I just can't see it this morning? I'd appreciate any help.

Many Thanks

Amy

Full code being used:

//select all images for kit
NSArray* kitImages = [kit valueForKeyPath:@"kitItems.kitItemProduct.productImage"];

//set coordinates to x,y -> 0,0 to start
float x = 0;
float y = 0;
//for each image
NSEnumerator *imageLoop = [kitImages objectEnumerator];
NSString *imgPath;
while ((imgPath = [imageLoop nextObject])) {
NSImage *img = [[NSImage alloc]initWithContentsOfFile:imgPath];

//apply image to view
[targetImage lockFocus];
[img drawInRect:NSMakeRect(x,y,100,100)
fromRect:NSMakeRect(x,y,100,100)
operation:NSCompositeCopy
fraction:1];


		[targetImage unlockFocus];

//set new coordinates
x = x+100;

//if coordinates are too wide, start new row - if x>300, reset x to 0 and add 100 to y
if(x > 300){
x = 0;
y = y+100;
}

}

NSBitmapImageRep *bmpImageRep = [[NSBitmapImageRep alloc]initWithData: [targetImage TIFFRepresentation]];

[targetImage addRepresentation:bmpImageRep];

NSData *data = [bmpImageRep representationUsingType: NSJPEGFileType
properties: nil];
[data writeToFile: kitimagePath
atomically: NO];
//link images to kit
[kit setValue:kitimagePath forKey:@"kitImage"];
}




_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Confused about floats
      • From: Corbin Dunn <email@hidden>
  • Prev by Date: Re: allKeys and allValues
  • Next by Date: FSCatalogSearch miss file
  • Previous by thread: Re: allKeys and allValues
  • Next by thread: Re: Confused about floats
  • Index(es):
    • Date
    • Thread