我的 C 布尔值数组在我第二次运行具有该数组的 Cocos2d 场景时没有保持它们的值。应用程序第一次启动时,c 数组工作正常并按预期响应,但是在场景被解除分配然后重新运行后,c 数组不会保留分配给它的值。我在下面的代码中做错了什么吗?
//.h
@interface GameplayLayer : CCLayer {
bool playerLog[4];
Hero *hero;
}
//.m
@implementation
- (void)ccKeyDown:(NSEvent*)keyDownEvent{
// Get pressed key (code)
UInt16 keyCode = [keyDownEvent keyCode];
// Set pressed key to true
if (keyCode == 123) playerLog[0] = TRUE; // Left
if (keyCode == 124) playerLog[1] = TRUE; // Right
if (keyCode == 126) playerLog[2] = TRUE; // up
if (keyCode == 125) playerLog[3] = TRUE; // down
// Other keys
if (keyCode == 27) { } // Escape
}
- (void)ccKeyUp:(NSEvent*)keyUpEvent
{
UInt16 keyCode = [keyUpEvent keyCode];
// Set pressed key to true
if (keyCode == 123) playerLog[0] = FALSE; // Left
if (keyCode == 124) playerLog[1] = FALSE; // Right
if (keyCode == 126) playerLog[2] = FALSE; // up
if (keyCode == 125) playerLog[3] = FALSE; // down
// Other keys
if (keyCode == 27) { } // Escape
}
-(void)update:(ccTime)delta {
if (playerLog[0] == TRUE) {//false on the second run when key is pushed down}