Please do not post the same thing multiple times. The board software automatically flags certain posts as needing moderator attention. This happens the most often for new users. I'm pretty sure this is made clear at the time you attempt to post. Posting the same thing over and over again just makes that many more posts the moderators have to weed through later. This makes us sad. Don't make us sad. If your post/thread doesn't appear, just wait a while. Don't post it again. If it hasn't shown up by the next day, then you can try again. I normally go through posts in the mornings, and try to check a few times throughout the day, but I'm not here 24/7. There will typically be a significant delay before posts are approved. Just be patient.
Hi, I have been working on a game where the player should be able to make a path or a line that a sprite should follow.
I already have a somewhat working code I have a mutable array (to record touch locations) and a draw method (to draw the line) It works but I just can't get a line of code working which is supposed to be where the magic happens to move the sprite through the locations recorded in the array please take a look at my code thanks.
-(void) ccTouchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { //remove objects each time the player makes a new path [toucharray removeAllObjects]; }
// 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 < [toucharray count]; i+=2) { CGPoint start = CGPointFromString([toucharray objectAtIndex:i]); CGPoint end = CGPointFromString([toucharray objectAtIndex:i+1]); ccDrawLine(start, end); } }
this is the part I'm having problems with. this line should be able to move the sprite but I always get a message "Passin 'id' to parameter of incompatible type 'CGPoint' aka 'struct CGPoint'" it highlights [toucharray objectAtIndex:0] I don't understand if my draw method uses my array and works perfectly why won't this line read from my array too? moreover I don't really ger the ccpAdd(ccpMult) I don't understand well what it does if someone would help me or point me in the right direction I would appreciate it a lot!
Replies
ccpAdd(a, b) works like ccp(a.x + b.x, a.y + b.y)
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesomealthough I'm still stuck trying to move the sprite position according to the location stored in the array.
Does anyone know if the reason why it's not working is because of the way I'm storing the CGPoint locations in the array?
// touches to the touch array
[toucharray addObject:NSStringFromCGPoint(new_location)];
[toucharray addObject:NSStringFromCGPoint(oldTouchLocation)];
and then using this line to move the sprite
_sprite.position = ccpAdd(ccpMult([toucharray objectAtIndex:currentIndex], progress), ccpMult([toucharray objectAtIndex:currentIndex+1], 1-progress));
or is there any other way to actually do this? thanks
- Spam
- Abuse
- Troll
0 • Off Topic Insightful Disagree Dislike Like Awesome