android– 如何使用AndEngine在FlingSwipe方向(对角线)上移动Sprite

android– 如何使用AndEngine在FlingSwipe方向(对角线)上移动Sprite,第1张

概述我正在开发AndEngine的游戏.在那里我能够从右到左,从上到下移动一个对象,反之亦然.但是,我的问题是如何在Fling方向中移动Sprite对象?这意味着如果用户在任何方向上甩掉Sprite对象应该在fling的坐标上移动并且应该继续前进.如果有人可以提出建议,如何获得精确的X和Y坐标也可以,我可以设法自己在坐标上移动Sprite对象.您还可以看到VID

我正在开发AndEngine的游戏.在那里我能够从右到左,从上到下移动一个对象,反之亦然.但是,我的问题是如何在Fling方向中移动Sprite对象?这意味着如果用户在任何方向上甩掉Sprite对象应该在fling的坐标上移动并且应该继续前进.

如果有人可以提出建议,如何获得精确的X和Y坐标也可以,我可以设法自己在坐标上移动Sprite对象.

您还可以看到VIDEO – Pirates Subs

在视频中,来自FliNG的启动器是我正在寻找的,从任何方向.

提前致谢.
苏瑞萨哈尼.最佳答案好吧,你可以试试这个代码……

float slope = (y2 - y1) / (x2 - x1);float angle = (float) Math.atan(slope);float angleInDegree = (float) Math.todegrees(angle);c = y1 - (slope * x1);

对于所有方向,onFling()方法看起来像这样.

@OverrIDepublic boolean onFling(MotionEvent e1,MotionEvent e2,float veLocityX,float veLocityY) {float c;// Checks if lifeline is there or not and enable or disable Fling// Operation.float sx = 0,sy = 0;float x1 = e1.getX();float y1 = e1.getY();float x2 = e2.getX();float y2 = e2.getY();float slope = (y2 - y1) / (x2 - x1);float angle = (float) Math.atan(slope);float angleInDegree = (float) Math.todegrees(angle);c = y1 - (slope * x1);/*** bottom right to left top*/if (x1 > x2 && y1 > y2) {sx = CAMERA_WIDTH;sy = (slope * sx) + c;missile = new Missile(sx,sy,this.mFaceTextureRegionMissileleftToRight);missile.setVeLocity(-(float) (600 * (Math.cos(angle))),-(float) (600 * (Math.sin(angle))));scene.gettopLayer().addEntity(missile);missile.setRotation(angleInDegree + 180);}/*** left top corner to right*/else if (x2 > x1 && y2 > y1) {sx = -100;sy = (slope * sx) + c;missile = new Missile(sx,this.mFaceTextureRegionMissileleftToRight);missile.setVeLocity((float) (300 * (Math.cos(angle))),(float) (300 * (Math.sin(angle))));scene.gettopLayer().addEntity(missile);missile.setRotation(angleInDegree);}/*** left bottom corner to right up*/else if (x2 > x1 && y1 > y2) {sx = -100;sy = (slope * sx) + c;missile = new Missile(sx,(float) (300 * (Math.sin(angle))));scene.gettopLayer().addEntity(missile);missile.setRotation(angleInDegree);}/*** Right corner to left bottom down*/else if (x1 > x2 && y2 > y1) {sx = CAMERA_WIDTH;sy = (slope * sx) + c;missile = new Missile(sx,this.mFaceTextureRegionMissileleftToRight);missile.setVeLocity((float) (-600 * (Math.cos(angle))),-(float) (600 * (Math.sin(angle))));scene.gettopLayer().addEntity(missile);missile.setRotation(angleInDegree + 180);}return false;}
总结

以上是内存溢出为你收集整理的android – 如何使用AndEngine在Fling / Swipe方向(对角线)上移动Sprite全部内容,希望文章能够帮你解决android – 如何使用AndEngine在Fling / Swipe方向(对角线)上移动Sprite所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://www.outofmemory.cn/web/1139853.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-31
下一篇 2022-05-31

发表评论

登录后才能评论

评论列表(0条)

保存