I’m looking for advice, and maybe a few examples. I’m trying to figure out how to create a CCSprite and have the player touch it as close to int aCertainAmountOfTime after it was created as possible. I want the player’s score to be determined by how close to the 1 second mark they hit the item, with a lower score for being too early or too late.
Would this be best solved by creating some sort of schedule update, or a tick? I’ve never done that, and I’m a bit confused about the logic of it. I understand the need, but not how to implement it.
I know this question is vague, but I’m a little bit lost, and any advice would be appreciated. Can someone share a basic example of when a scheduled update tick would be relevant, and how the code would look?
Thanks for dealing with my ambiguity =D
My solution is quite simple, you only need to add this to your CCSprite class’ init method:
Then update just counts the time since it was created (lifeTime is a float ivar declared in the class’ @interface):
When the user touches the sprite, just subtract 1 from lifeTime to get the time difference relative to 1 second:
If diff is negative, the player touched too early by this many seconds. If diff is positive, the player touched too late by this many seconds. And to get the absolute difference you’d use fabsf, ie basically it just removes the sign (if any):
Done.