首页 \ 问答 \ 弹丸/子弹方向Cocos2d(Projectiles/Bullets direction Cocos2d)

弹丸/子弹方向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
更新时间:2024-04-23 19:04

最满意答案

这是由头文件中的实现引起的常见问题。
会发生什么是你的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.

相关问答

更多
  • 最后,我解决了这个问题。 将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 ...
  • 我相信问题来自于以下事实:所有.obj文件都写入同一个文件夹,因此编译这两个源文件的输出会发生冲突。 我认为至少有两种可能的解决方案: 1)为每个输入文件夹使用不同的输出目录(构建目录)2)为每个(或只有一个)源文件创建自定义对象文件名 我不确定第一个选项,但是对于第二个选项,您应该能够右键单击解决方案资源管理器中的源文件,选择“属性”,并找到一些配置设置以覆盖输出(.obj )为该源文件创建的文件。 I believe the problem comes from the fact that all yo ...
  • 您似乎正在尝试将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 ...
  • 这不是#include(头文件)的问题。 “未解析的外部符号”错误是因为链接器无法找到(解析)您调用的这些GLEW方法(直接或间接)。 通常通过向链接器选项添加类似于:-lGLEW或-lglew32的内容来修复此问题,以便链接器可以访问此库的“已编译代码”。 这也可以通过代码开头的pragma命令来完成,但是此技巧仅适用于Visual Studio,如果您尝试将代码与gcc链接,则无法使用。 但无论如何,您必须确保在链接器的库路径中找到有问题的文件(此处为glew32.lib)。 It is not a p ...

相关文章

更多

最新问答

更多
  • CSS修复容器和溢出元素(CSS Fix container and overflow elements)
  • SQL多个连接在与where子句相同的表上(SQL Multiple Joins on same table with where clause)
  • nginx 80端口反向代理多个域名,怎样隐藏端口的
  • xcode提醒样式,swift 3(xcode alert style, swift 3)
  • 在Chrome控制台中调试JavaScript(debugging javascript in Chrome console)
  • Javascript - 试图围绕自定义事件(Javascript - Trying to wrap my head around custom events)
  • 边栏链接不可点击(Sidebar links aren't clickable)
  • 使用recpatcha gem时如何显示其他表单错误?(How do I display other form errors when using the recpatcha gem?)
  • boost.python避免两次注册内部类,但仍然在python中公开(boost.python Avoid registering inner class twice but still expose in python)
  • Android 现在软件很少吗?以后会多起来吗
  • 如何在ActiveAdmin 0.5.0中为资源全局指定预先加载?(How to specify eager loading globally for a resource in ActiveAdmin 0.5.0?)
  • matlab代码为黄金比例持续分数(matlab code for golden ratio continued fraction)
  • Android浏览器触摸事件位置(Android browser touch event location)
  • 将cURL输出分配给Bash中的变量(Assign output to variable in Bash)
  • 我如何在MVC视图上没有时间获取当前日期(how i can get current date without time on MVC view)
  • sql连接函数(sql join of function)
  • 为什么在Xamarin Media插件中使用ImageSource.FromStream而不是FromFile?(Why use ImageSource.FromStream instead of FromFile in Xamarin Media plugin?)
  • 这段代码是否真的可以防止SQL注入?(Will this code actually work against SQL-injection? [duplicate])
  • 信阳方远计算机学校大专证被国家认可么
  • React / Rails AJAX POST请求返回404(React/Rails AJAX POST request returns 404)
  • Android与php服务器交互(Android interact with php server)
  • 自动刷新QTableWidget可能吗?(Refresh QTableWidget automatically possible?)
  • JVM / Compiler优化对象的未使用属性(optimization of unused properties of object by JVM / Compiler)
  • 插入表格时,乌克兰字符会更改为问号(Ukrainian character change to question mark when insert to table)
  • 在头文件中包含异常类(Including an exception class in a header file)
  • 完成c#中的执行后关闭sqlcmd(Close sqlcmd after finishing executing in c#)
  • 使用软导航栏正确检测屏幕尺寸(Detecting screensize correctly with soft navigation bar)
  • Typescript:从输入更新值(Typescript : update value from input)
  • 如何在执行某些行后仅在断点处停止?(How to only stop at a breakpoint after some line was executed?)
  • 以未定义的元素在JSON中循环(loop in JSON with undefined elements)