弹丸/子弹方向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)
我在哪里可以获得有关Visual Studio中的C / C ++链接器的信息?(Where can I get information about the C/C++ linker in Visual Studio?)
如何在Visual Studio中取消链接器对象名称?(How to undecorate linker object names in Visual Studio?)
mpich2 visual studio 2013链接器错误(mpich2 visual studio 2013 linker error)
使用directX和Visual Studio 2010的链接器错误(Linker Errors using directX and Visual Studio 2010)
两个相同名称的文件在Visual Studio中给出链接器错误(Two files of the same name give linker error in Visual Studio [duplicate])
使用FFMPEG与Visual Studio 2013 Express的链接器错误(Linker error using FFMPEG with Visual Studio 2013 Express)
Visual Studio 2008链接器错误:ALINK操作失败(80070005):访问被拒绝(Visual Studio 2008 linker error: ALINK operation failed (80070005) : Access is denied)
visual studio Linker Error(visual studio Linker Error)
Windows 7上的glew和Visual Studio链接器错误(Linker error with glew and Visual Studio on windows 7)
相关文章
更多Phaser开源2d引擎 javascript/html5游戏框架
幻世(OurDream)2D图形引擎易语言汉化版更新提示
幻世(OurDream)2D图形引擎大更新——炫丽粒子特效强势回归!
Obama says economy moving in right direction
Cocos-html5 初识
3d引擎列表
java3d的前景
JOGL 处理3D图形
About Unity3D 4.1.2 (to continue…)
想开发3D引擎
最新问答
更多python的访问器方法有哪些
使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
透明度错误IE11(Transparency bug IE11)
linux的基本操作命令。。。
响应navi重叠h1和nav上的h1链接不起作用(Responsive navi overlaps h1 and navi links on h1 isn't working)
在C中读取文件:“r”和“a +”标志的不同行为(Reading a File in C: different behavior for “r” and “a+” flags)
NFC提供什么样的带宽?(What Kind of Bandwidth does NFC Provide?)
元素上的盒子阴影行为(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
Copyright ©2023
peixunduo.com All
Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!
Laravel检查是否存在记录(Laravel Checking If a Record Exists)
设置base64图像的大小javascript - angularjs(set size of a base64 image javascript - angularjs)
Copyright ©2023 peixunduo.com All Rights Reserved.粤ICP备14003112号
本站部分内容来源于互联网,仅供学习和参考使用,请莫用于商业用途。如有侵犯你的版权,请联系我们(neng862121861#163.com),本站将尽快处理。谢谢合作!