弹丸/子弹方向Cocos2d(Projectiles/Bullets direction Cocos2d)
我正在关注一个简单的cocos2d游戏的教程。
但是在该教程中,用户触发的子弹只在一个方向上
我能做些什么来让它在所有方向上发射,而不仅仅是单方面?
这是方向的代码。
int offX = location.x - projectile.position.x; int offY = location.y - projectile.position.y; [self addChild:projectile]; int realX = winSize.width + (projectile.contentSize.width/2); float ratio = (float) offY / (float) offX; int realY = (realX *ratio) + projectile.position.y; CGPoint realDest = ccp(realX, realY); int offRealX = realX - projectile.position.x; int offRealY = realY - projectile.position.y; float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY)); float velocity = 480/1; float realMoveDuration = length/velocity; [projectile runAction:[Sequence actions:[MoveTo actionWithDuration:realMoveDuration position:realDest], [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]];
所有的帮助将不胜感激。 谢谢
i am following a tutorial on a simple cocos2d game.
however on that tutorial the bullets that the user fires is only on one direction
what can i do to make it fire on all directions not just one sided?
here is the code of the direction.
int offX = location.x - projectile.position.x; int offY = location.y - projectile.position.y; [self addChild:projectile]; int realX = winSize.width + (projectile.contentSize.width/2); float ratio = (float) offY / (float) offX; int realY = (realX *ratio) + projectile.position.y; CGPoint realDest = ccp(realX, realY); int offRealX = realX - projectile.position.x; int offRealY = realY - projectile.position.y; float length = sqrtf((offRealX*offRealX)+(offRealY*offRealY)); float velocity = 480/1; float realMoveDuration = length/velocity; [projectile runAction:[Sequence actions:[MoveTo actionWithDuration:realMoveDuration position:realDest], [CallFuncN actionWithTarget:self selector:@selector(spriteMoveFinished:)], nil]];
all help will be greatly appreciated. Thanks
原文:https://stackoverflow.com/questions/8529581
最满意答案
这是由头文件中的实现引起的常见问题。
会发生什么是你的fmQueue.cpp编译单元编译,并定义构造函数。 之后,main.cp编译并定义相同的函数(因为它们在包含的头文件中可见)。
因此,当链接器尝试将2个编译单元链接在一起时,它会检测到双重定义。所以,这就是你应该在.cpp文件中实现函数的原因。
另一种解决方案是解耦头依赖性。 您可以在队列的标头中转发声明Node类,并且实际上只在队列的cpp文件中包含标头。It's a common problem that's caused by having an implementation in a header file.
What happens is that your fmQueue.cpp compilation unit compiles, and defines the constructor functions. After that, the main.cp compiles and defines the same functions (because they are visible in the included header file).
So when the linker tries to link the 2 compilation units together it detects the double definition.So, that's why you should implement functions in the .cpp file.
Another solution would be to decouple the header dependency. You can forward declare the Node class in the queue's header, and only actually include the header in the queue's cpp file.
相关问答
更多-
Visual Studio 2008中Boost.Python的链接器错误(A linker error of Boost.Python in Visual Studio 2008)[2024-02-21]
最后,我解决了这个问题。 将D:\ Py27Test \ App \ include添加到编译器包含路径 将D:\ Py27Test \ App \ libs添加到链接器库路径 似乎如果我不包含Python.h,它将链接到默认库文件。 所以在我添加这些路径后,它现在可以工作了。 Finally, I solved this problem. Add D:\Py27Test\App\include to compiler include paths Add D:\Py27Test\App\libs to li ... -
有关连接器的一般理解,请阅读“连接器和装载器”一书。 您可以在线阅读: http : //www.iecc.com/linker/ 。 我认为仅对Windows可执行文件进行深入研究将非常有用: http://msdn.microsoft.com/en-us/magazine/cc301805.aspx http://msdn.microsoft.com/en-us/magazine/cc301808.aspx 当然还有文档: http : //msdn.microsoft.com/en-us/librar ...
-
关于__imp_ldap_value_free_len形式的名称要认识到的重要一点是删除__imp_前缀并找出剩余符号名称的来源。 确实在Wldap32.dll中有一个ldap_value_free_len(你链接到Wldap32.lib)。 The important thing to realize about names of the form __imp_ldap_value_free_len is to drop the __imp_ prefix and figure out where the ...
-
您需要再添加一个依赖项--cxx.lib 该库包含c ++的所有必要绑定。 您可以查看MPICH2 / examples / cxxpi.vcproj以发现需要链接此库。 You need to add one more additional dependency - cxx.lib This library contains all necessary bindings for c++. You may just look into MPICH2/examples/cxxpi.vcproj to disc ...
-
除非在Visual Studio中使用特殊设置,否则窗口化可执行文件以WinMain函数开头,而不是常规main函数。 因此,您应该创建一个控制台应用程序,使用WinMain ,或使用该设置来使用常规main函数。 请注意,实际创建窗口不需要以WinMain开头。 它只是一个Visual Studio约定。 使用常规main菜单的选项位于“项目设置”对话框中的“链接器 - >高级”下。 它被称为“入口点”,并且要使用常规main,您可以使用“mainCRTStartup”作为值。 如果您坚持使用WinMai ...
-
两个相同名称的文件在Visual Studio中给出链接器错误(Two files of the same name give linker error in Visual Studio [duplicate])[2021-08-24]
我相信问题来自于以下事实:所有.obj文件都写入同一个文件夹,因此编译这两个源文件的输出会发生冲突。 我认为至少有两种可能的解决方案: 1)为每个输入文件夹使用不同的输出目录(构建目录)2)为每个(或只有一个)源文件创建自定义对象文件名 我不确定第一个选项,但是对于第二个选项,您应该能够右键单击解决方案资源管理器中的源文件,选择“属性”,并找到一些配置设置以覆盖输出(.obj )为该源文件创建的文件。 I believe the problem comes from the fact that all yo ... -
使用FFMPEG与Visual Studio 2013 Express的链接器错误(Linker error using FFMPEG with Visual Studio 2013 Express)[2022-12-12]
您似乎正在尝试将32位应用程序与64位库链接。 从http://ffmpeg.zeranoe.com/builds/下载32位库,或为您的解决方案创建x64配置。 It seems that you are trying to link a 32-bit application with 64-bit libraries. Download 32-bit libraries from http://ffmpeg.zeranoe.com/builds/ or create x64 configuration ... -
将FileMon作为工具箱中的一个工具总是很好:它可以记录每个文件操作,并且有助于显示链接器想要处理什么文件。 (在sysinternals.com上查找) It's always good to have FileMon as a tool in your toolkit: it can log every file operation, and will help showing what exactly the linker wants to do with what file. (Find it a ...
-
这是由头文件中的实现引起的常见问题。 会发生什么是你的fmQueue.cpp编译单元编译,并定义构造函数。 之后,main.cp编译并定义相同的函数(因为它们在包含的头文件中可见)。 因此,当链接器尝试将2个编译单元链接在一起时,它会检测到双重定义。 所以,这就是你应该在.cpp文件中实现函数的原因。 另一种解决方案是解耦头依赖性。 您可以在队列的标头中转发声明Node类,并且实际上只在队列的cpp文件中包含标头。 It's a common problem that's caused by having ...
-
Windows 7上的glew和Visual Studio链接器错误(Linker error with glew and Visual Studio on windows 7)[2022-07-22]
这不是#include(头文件)的问题。 “未解析的外部符号”错误是因为链接器无法找到(解析)您调用的这些GLEW方法(直接或间接)。 通常通过向链接器选项添加类似于:-lGLEW或-lglew32的内容来修复此问题,以便链接器可以访问此库的“已编译代码”。 这也可以通过代码开头的pragma命令来完成,但是此技巧仅适用于Visual Studio,如果您尝试将代码与gcc链接,则无法使用。 但无论如何,您必须确保在链接器的库路径中找到有问题的文件(此处为glew32.lib)。 It is not a p ...