我正在通电制作游戏。我有3个通电。当上电启动时,我使用一个整数来标识它是哪一个,1,2或3,0表示没有活动的通电。一旦我启动加电,我希望它在一段时间间隔后,例如10秒过期。如何将标识符整数重置为0?在一段时间间隔后更改一个整数值ios
例如,一次加电会加快船的运行速度。这是我的更新方法。
-(void) update:(ccTime)dt
{
if (powerupIdentifier == 0)
{
shipSpeed = 100;
}
if (powerupIdentifier == 1)
{
shipSpeed = 200;
}
CCArray* touches = [KKInput sharedInput].touches;
if ([touches count] == 1)
{
//MAKES SHIP MOVE TO TAP LOCATION
KKInput * input = [KKInput sharedInput];
CGPoint tap = [input locationOfAnyTouchInPhase:KKTouchPhaseBegan];
ship.position = ccp(ship.position.x, ship.position.y);
if (tap.x != 0 && tap.y != 0)
{
[ship stopAllActions]; // Nullifies previous actions
int addedx = tap.x - ship.position.x;
int addedy = tap.y - ship.position.y;
int squaredx = pow(addedx, 2);
int squaredy = pow(addedy, 2);
int addedSquares = squaredx + squaredy;
int distance = pow(addedSquares, 0.5);
[ship runAction: [CCMoveTo actionWithDuration:distance/shipSpeed position:tap]];//makes ship move at a constant speed
}
}
}
你可以在这里粘贴一些相关的代码,所以我们可以更好地理解方法你正在使用的时间? – heinst