Objective-C - Position Object with CGPoint from another Method -
hello have got question. hope me. not understand… have method returnpointfromarray have array values (e.g. 50.0, 100.0). want random , want use cgpoint p in method drawobjectwithpoint position object (object class) random value.
but drawobjectwithpoint method says cgpoint p ist 0.0, 0,0 or says "use of undeclared identifier p or "instance variable hides…" .
i tried same principle test int , works.
i don´t know i´m doing wrong.
it great if me , explain i´m doing wrong.
thanks lot.
.h -(void)returnpointfromarray; -(void)drawobjectwithpoint; .m -(void)returnpointfromarray { nsarray *points = []; //random points nsuinteger *randomindex = arc4random() % [points count]; nsvalue *val = [points objectatindex:randomindex]; cgpoint p = [val cgpointvalue]; } -(void)drawobjectwithpoint { object *myobject [[object alloc]init]; cgpoint pnew = p; myobject.position = [self addchild:myobject]; }
you can this: edited: (this how yo declare in .h file)
in .h file
#import <uikit/uikit.h> @interface myclass : uiviewcontroller { cgpoint p; } -(void)returnpointfromarray; -(void)drawobjectwithpoint; @end in .m file
-(void)returnpointfromarray { nsarray *points = []; //random points nsuinteger *randomindex = arc4random() % [points count]; nsvalue *val = [points objectatindex:randomindex]; p = [val cgpointvalue]; // change here } -(void)drawobjectwithpoint { object *myobject [[object alloc]init]; cgpoint pnew = p; myobject.position = [self addchild:myobject]; }
Comments
Post a Comment