cocos2d iphone - object is moving in the accelerometer -


i want create 1 game in cocos2d in 1 object running .

i want move object left , right base on device accelerometer. getting value of accelerometer , update location of object. can see new location in log. object not moving it's possion. here code have writen in app .

- (void) accelerometer:(uiaccelerometer *)accelerometer didaccelerate:(uiacceleration *)acceleration1 {  acceleration = acceleration1; cgpoint position = mainplayer.position;  if(acceleration.y < -0.25) {  // tilting device right     position.y -= 0.25; } else if (acceleration.y > 0.25) {  // tilting device left     position.y += 0.25; } else {  } //    newposition = position;  ccaction *action = [ccmoveto actionwithduration:0.01 position:position]; [mainplayer runaction:action];  //    mainplayer.position = ccp(position.x, position.y); } 

i have try both way setting position direct , using action.

dose 1 knows why problem occure or setting need accelerometer work.

please give link such kind example.

try using moveby instead of moveto:

 - (void) accelerometer:(uiaccelerometer *)accelerometer didaccelerate:(uiacceleration *)acceleration1 {      acceleration = acceleration1;     cgpoint position = ccp(0,0);      if(acceleration.y < -0.25) {  // tilting device right         position.y = 0.25;     } else if (acceleration.y > 0.25) {  // tilting device left         position.y = 0.25;     }      ccaction *action = [ccmoveby actionwithduration:0.01 position:position];     [mainplayer runaction:action];   } 

Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -