Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to make a sprite follow a trail?
    primarykey
    data
    text
    <p>I'm making a game where the player draws a line and then a sprite should follow and run on it. I have a mutable array and also a draw method which works well. but I'm having trouble figuring out a way to move the sprite. I have tried different approaches but I can't get the iterator to work.</p> <p>It's supposed to work by iterating through the array. which is populated with CGPoint locations previously stored. I try to move the sprite in ccTouchedEnded but it highlights [toucharray objectAtIndex:0] and says "passing 'id' to parameter of incompatible type 'CGPoint (aka 'struct CGPoint')"</p> <pre><code> -(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //remove objects each time the player makes a new path [toucharray removeAllObjects]; } -(void) ccTouchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { UITouch *touch = [ touches anyObject]; CGPoint new_location = [touch locationInView: [touch view]]; new_location = [[CCDirector sharedDirector] convertToGL:new_location]; CGPoint oldTouchLocation = [touch previousLocationInView:touch.view]; oldTouchLocation = [[CCDirector sharedDirector] convertToGL:oldTouchLocation]; oldTouchLocation = [self convertToNodeSpace:oldTouchLocation]; // add touches to the touch array [toucharray addObject:NSStringFromCGPoint(new_location)]; [toucharray addObject:NSStringFromCGPoint(oldTouchLocation)]; } -(void)draw { glEnable(GL_LINE_SMOOTH); for(int i = 0; i &lt; [toucharray count]; i+=2) { CGPoint start = CGPointFromString([toucharray objectAtIndex:i]); CGPoint end = CGPointFromString([toucharray objectAtIndex:i+1]); ccDrawLine(start, end); } } -(void) ccTouchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{ // here is the line I can't get to work to move the sprite _sprite.position = ccpAdd(ccpMult([toucharray objectAtIndex:0], progress), ccpMult([toucharray objectAtIndex:0+1], 1-progress)); } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload