弹丸/子弹方向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.

相关问答

更多

Visual Studio 2008中Boost.Python的链接器错误(A linker error of Boost.Python in Visual Studio 2008)

最后,我解决了这个问题。 将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 ...

我在哪里可以获得有关Visual Studio中的C / C ++链接器的信息?(Where can I get information about the C/C++ linker in Visual Studio?)

有关连接器的一般理解,请阅读“连接器和装载器”一书。 您可以在线阅读: 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/l...

如何在Visual Studio中取消链接器对象名称?(How to undecorate linker object names in Visual Studio?)

关于__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 wher...

mpich2 visual studio 2013链接器错误(mpich2 visual studio 2013 linker error)

您需要再添加一个依赖项--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...

使用directX和Visual Studio 2010的链接器错误(Linker Errors using directX and Visual Studio 2010)

除非在Visual Studio中使用特殊设置,否则窗口化可执行文件以WinMain函数开头,而不是常规main函数。 因此,您应该创建一个控制台应用程序,使用WinMain ,或使用该设置来使用常规main函数。 请注意,实际创建窗口不需要以WinMain开头。 它只是一个Visual Studio约定。 使用常规main菜单的选项位于“项目设置”对话框中的“链接器 - >高级”下。 它被称为“入口点”,并且要使用常规main,您可以使用“mainCRTStartup”作为值。 如果您坚持使用W...

两个相同名称的文件在Visual Studio中给出链接器错误(Two files of the same name give linker error in Visual Studio [duplicate])

我相信问题来自于以下事实:所有.obj文件都写入同一个文件夹,因此编译这两个源文件的输出会发生冲突。 我认为至少有两种可能的解决方案: 1)为每个输入文件夹使用不同的输出目录(构建目录)2)为每个(或只有一个)源文件创建自定义对象文件名 我不确定第一个选项,但是对于第二个选项,您应该能够右键单击解决方案资源管理器中的源文件,选择“属性”,并找到一些配置设置以覆盖输出(.obj )为该源文件创建的文件。 I believe the problem comes from the fact that a...

使用FFMPEG与Visual Studio 2013 Express的链接器错误(Linker error using FFMPEG with Visual Studio 2013 Express)

您似乎正在尝试将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 configura...

Visual Studio 2008链接器错误:ALINK操作失败(80070005):访问被拒绝(Visual Studio 2008 linker error: ALINK operation failed (80070005) : Access is denied)

将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...

visual studio Linker Error(visual studio Linker Error)

这是由头文件中的实现引起的常见问题。 会发生什么是你的fmQueue.cpp编译单元编译,并定义构造函数。 之后,main.cp编译并定义相同的函数(因为它们在包含的头文件中可见)。 因此,当链接器尝试将2个编译单元链接在一起时,它会检测到双重定义。 所以,这就是你应该在.cpp文件中实现函数的原因。 另一种解决方案是解耦头依赖性。 您可以在队列的标头中转发声明Node类,并且实际上只在队列的cpp文件中包含标头。 It's a common problem that's caused by ha...

Windows 7上的glew和Visual Studio链接器错误(Linker error with glew and Visual Studio on windows 7)

这不是#include(头文件)的问题。 “未解析的外部符号”错误是因为链接器无法找到(解析)您调用的这些GLEW方法(直接或间接)。 通常通过向链接器选项添加类似于:-lGLEW或-lglew32的内容来修复此问题,以便链接器可以访问此库的“已编译代码”。 这也可以通过代码开头的pragma命令来完成,但是此技巧仅适用于Visual Studio,如果您尝试将代码与gcc链接,则无法使用。 但无论如何,您必须确保在链接器的库路径中找到有问题的文件(此处为glew32.lib)。 It is no...

相关文章

更多

Phaser开源2d引擎 javascript/html5游戏框架

原文来自:http://html6game.com/thread-1023-1-1.shtml 转自: ...

幻世(OurDream)2D图形引擎易语言汉化版更新提示

幻世引擎的易语言汉化专版到目前为止已经累积了多个BUG,其中多个BUG是影响引擎功能使用的问题,我将会 ...

幻世(OurDream)2D图形引擎大更新——炫丽粒子特效强势回归!

本次更新终于让各位期待已久的绚丽粒子系统特效强势回归到幻世当中了。凭借新引擎强大而又高效的绘图,新的粒 ...

Obama says economy moving in right direction

President Barack Obama talks about the latest repor ...

Cocos-html5 初识

Cocos html5 项目环境的搭建。按照官网的文档搭建。(cocos html5 v2.2.3、w ...

3d引擎列表

免费引擎 Agar - 一个高级图形应用程序框架,用于2D和3D游戏。 Allegro lib ...

java3d的前景

奥运后一直在找工作,本来是做WEB方面的工作。 就像北京今天的天气一样,最近IT也是冷的要命。 工 ...

JOGL 处理3D图形

GLAutoDrawable&nbsp

About Unity3D 4.1.2 (to continue…)

Here are something that need to take care of when y ...

想开发3D引擎

想制作3D引擎,希望高手给推荐一本好书。 需要什么IDE? 需要什么语言?JAVA/C++/C#. ...

最新问答

更多

python的访问器方法有哪些

使用方法: class A(object): def foo(self,x): #类实例方法 print "executing foo(%s,%s)"%(self,x) @classmethod def class_foo(cls,x): #类方法 print "executing class_foo(%s,%s)"%(cls,x) @staticmethod def static_foo(x): #静态方法 print "executing static_foo(%s)"%x调用方法: a =

使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)

我认为你必须将两个TableGetway传递给UserTable构造。 你必须改变Module.php看看: public function getServiceConfig() { return array( 'factories' => array( 'User\Model\UserTable' => function($sm) { $userTableGateway = $sm->get('UserTable

透明度错误IE11(Transparency bug IE11)

这是一个渲染错误,由使用透明度触发,使用bootstrap用于在聚焦控件周围放置蓝色光环的box-shadow属性。 可以通过添加以下类覆盖来解决它。 .form-control:hover { -webkit-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); -moz-box-shadow: 0px 0px 5px 0px rgba(0,0,255,1); box-shadow: 0px 0px 4px 0px rgba(0,0,255,1)

linux的基本操作命令。。。

ls 显示目录 mkdir 建立目录 cd 进入目录

响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)

将z-index设置为.main-nav这将解决您的重叠问题 .main-nav { position:relative; z-index:9; } set z-index to .main-nav This will fix your overlaping issue .main-nav { position:relative; z-index:9; }

在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)

这是因为模式规范"a"打开一个文件以便追加,文件指针在末尾。 如果您尝试从此处读取,则由于文件指针位于EOF,因此没有数据。 您应该打开"r+"进行阅读和写作。 如果在写入之前读取整个文件,则在写入更多数据时,文件指针将正确定位以追加。 如果这还不够,请探索ftell()和fseek()函数。 That is because the mode spec "a" opens a file for appending, with the file pointer at the end. If you

NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)

支持空中接口的数据速率是一回事。 在消除协议开销,等待eeprom写入以及所有需要时间的其他内容之后,您看到的数据速率是完全不同的故事。 长话短说,从标签读取或进行对等传输时的实际数据速率峰值约为2.5千字节/秒。 取决于具体的标签或对等技术,它可能比这慢很多。 The supported data-rates of the air-interface are one thing. The data-rate that you see after removing protocol overhe

元素上的盒子阴影行为(box-shadow behaviour on elements)

它看起来像只在Windows上的Chrome的错误。 我在Google Canary (Chrome 63)中也进行了测试,问题依然存在,所以有可能它不会很快修复。 这个问题是由overflow: auto引起的overflow: auto ,在你的情况下,它可以很容易地通过删除或设置为可见(默认)来解决。 但是 ,将鼠标悬停在右侧(顶部和底部)时,会出现滚动条。 一个解决方案可以设置overflow: hidden的身体,所以预期的结果是所需的。 我想指出,这不是一个很好的解决方案,但我建议暂

Laravel检查是否存在记录(Laravel Checking If a Record Exists)

这取决于您是否要以后与用户合作,或仅检查是否存在。 如果要使用用户对象(如果存在): $user = User::where('email', '=', Input::get('email'))->first(); if ($user === null) { // user doesn't exist } 如果你只想检查 if (User::where('email', '=', Input::get('email'))->count() > 0) { // user found

设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)

$scope.getData= function () { var reader = new FileReader(); reader.onload = $('input[type=file]')[0].files; var img = new Image(); img.src =(reader.onload[0].result); img.onload = function() { if(this.width > 640