- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在为 iphone 制作 Cocos2d 游戏,我有我的主要游戏模式 Game
,它继承自 CCLayer
。
我正在尝试创建另一种游戏模式 MathGame
,它继承自 Game
,但是当我尝试编译时,我在 MathGame 中遇到了这个错误.h
:
Attempting to use the forward class 'Game' as superclass of 'MathGame'
即使 MathGame
的实现和接口(interface)为空,我也会收到错误消息。只有当我尝试将 MathGame.h
包含在另一个文件中时才会发生这种情况。
这是游戏类的代码:
// Game.h
#import "cocos2d.h"
#import <GameKit/GameKit.h>
#import "SplashScreenLayer.h"
@interface Game : CCLayer
// A bunch of stuff
@end
新游戏类型:
// MathGame.h
#import "Game.h"
@interface MathGame : Game
@end
以及包含两者的主菜单:
// SplashScreen.h
#import "cocos2d.h"
#import "Game.h"
#import "MathGame.h"
#import "HowToPlayLayer.h"
#import "AboutLayer.h"
@interface SplashScreenLayer : CCLayer
// A bunch of stuff
@end
我在网上找不到任何有用的东西。有什么想法吗?
最佳答案
您只需要一个导入周期:
Game
导入 SplashScreenLayer
SplashScreenLayer
导入 MathGame
MathGame
导入 Game
您的解决方案:
保留 MathGame
中的 import
,并将其他导入更改为 @class .
总结一下:
// Game.h#import "cocos2d.h"#import <GameKit/GameKit.h>@class SplashScreenLayer;@interface Game : CCLayer // A bunch of stuff@endThe new game type:// MathGame.h#import "Game.h"@interface MathGame : Game@endAnd the main menu that includes both:// SplashScreen.h#import "cocos2d.h"#import "HowToPlayLayer.h"#import "AboutLayer.h"@class Game;@class MathGame;@interface SplashScreenLayer : CCLayer // A bunch of stuff@end
上面回答了你的问题,让我解释一些我从阅读前向减速和导入周期中已经知道的事情:
首先,去阅读它们吧!它们是 Objective-C 的一个非常重要的部分,你不想错过它!
其次,只要您需要该类作为私有(private)变量或方法参数,就使用@class。将导入用于继承和strong 属性。
第三,不要忘记在实现文件中#import
你转发的类!
关于objective-c - Cocos2d 中的 "Attempting to use the forward class ' 游戏 ' as superclass of ' MathGame '",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11819764/
尝试从对话框中的 EditText 获取 Edit Text 的值,但一次又一次地出现此错误 Attempt to invoke virtual method 'android.text.Editab
最近尝试了一下最新的Laravel(6.4)。正在尝试实现基于 API 的简单登录功能。没有使用 Passport 或 Tymon 的 JWT 等任何软件包。我使用了非常基本的身份验证(只需在用户表中
最近尝试了一下最新的Laravel(6.4)。正在尝试实现基于 API 的简单登录功能。没有使用 Passport 或 Tymon 的 JWT 等任何软件包。我使用了非常基本的身份验证(只需在用户表中
我在我的 PC 上运行 cifar10 网络,在完成训练和运行评估脚本后出现以下错误: 2016-06-01 14:37:14.238317: precision @ 1 = 0.000 Traceb
我正在使用 ng2-toastr 并收到以下错误 https://www.npmjs.com/package/ng2-toastr Attempt to use a destroyed view: d
env file:环境文件: APP_ENV=localAPP_DEBUG=trueAPP_KEY= ...........DB_HOST=srv3.linuxisrael.co.ilDB_D
当我登录管理员时,我正在尝试对 api 进行多重保护身份验证,我得到了跟随错误 BadMethodCallException Method Illuminate\Auth\Req uestGuard:
我开始在 Lua 中进行编程,并在运行脚本时出现此错误: attempt to index upvalue 'base' (a function value) 这可能是因为我还没有掌握一些非常基本的东
我试图在 Oozie 工作流中聚合一些数据。但是聚合步骤失败。 我在日志中发现了两个兴趣点:第一个是一个似乎重复出现的错误(?): 容器完成后,它会被杀死,但会以非零退出代码 143 退出。 它完成了
我的问题是当我调用函数时: [self performSegueWithIdentifier: @"FinalPlayPT" sender: self]; 它有效,但我有这个警告: Warning:
项目背景 项目整体采用的是springboot+mybatis 方式。有一次做数据查询的时候。console突然报:DataIntegrityViolationException: Error att
我在使用 Jobs 发送电子邮件的 Ubuntu Server 上设置了 Laravel 项目。 下面是我在 中的 laravel-worker 文件/etc/supervisor/laravel-w
尝试运行我的 React 应用程序时收到以下错误: ./src/components/App/App.js Attempted import error: 'combineReducers' is n
我的编码功能是这样的: fn encode_login(packet: &str) { let bytes = packet.as_bytes(); for (i, &element)
如果一个版本号大于另一个版本号,我的 msbuild 需要采取有条件的操作。我尝试像下面这样编写代码,但发现出现错误(也在下面)。我哪里出错了?
我是 Lua 的新手,并试图让事情在我的脑海中进行排序。我试过这个代码: function newCarousel(images) local slideToImage = function(
我正在使用 entrust用于在 Laravel 5.3 中管理基于角色的权限,并自然地为不同的用户类型使用手动/自定义登录。 Auth::attempt()可以吗?处理外表关系?基本上,我想做这样的
我谷歌了一遍又一遍,但没有对我有用的信息。 情况是这样的:1.产品有 active 。2.我通过测试账号来测试我的apk。3.我已经上传了一整天的apk。 但是当我想为应用程序中的项目付款时,goog
我正在尝试使用 groovy 解析日期字符串,但遇到了问题。这是字符串的样子和不起作用的逻辑。 def dateString = "2017-01-01T12:00:00Z" def date = D
我正在使用 ParseFacebookUtils 从 Facebook 登录我的应用。 LoginActivity 的 onCreate: protected void onCreate(Bundle
我是一名优秀的程序员,十分优秀!