gpt4 book ai didi

android - AndEngine 和 Box2D 中的 Spring 墙

转载 作者:行者123 更新时间:2023-11-30 03:57:41 24 4
gpt4 key购买 nike

我在我的游戏中使用 Box2D,但我想要一个漂亮的 Spring 墙来插入玩家触摸。它看起来像这样(3 帧): enter image description here

问题:如何实现?我可以将墙效果附加到动画 Sprite 吗?

最佳答案

答案是:棱柱关节。我将图像分为两部分:静态和动态(移动条)。下面的代码用于创建棱柱关节,就像我问题中的图像一样:

//prismatic joint
final Sprite springFrameT = new Sprite(pX, pY, mSpringFrameTRegion, getVertexBufferObjectManager());
final Sprite springBarT = new Sprite(pX, pY + mSpringFrameTRegion.getHeight()-mSpringBarTRegion.getHeight(),
mSpringBarTRegion, getVertexBufferObjectManager());
mMainScene.attachChild(springFrameT);
mMainScene.attachChild(springBarT);
mMapSprites.add(springFrameT);
mMapSprites.add(springBarT);

final Body springFrameBody = PhysicsFactory.createBoxBody(mPhysicsWorld, springFrameT, BodyType.StaticBody, FIXTURE_DEF);
final Body springBarBody = PhysicsFactory.createBoxBody(mPhysicsWorld, springBarT, BodyType.DynamicBody, SPRING_FIXTURE_DEF);
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(springFrameT, springFrameBody, false, false));
mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(springBarT, springBarBody, true, true));

final PrismaticJointDef prismaticJointDef = new PrismaticJointDef();
prismaticJointDef.initialize(springFrameBody, springBarBody, springFrameBody.getWorldCenter(), // new Vector2(springFrameT.getWidth(), springFrameT.getHeight()/2),
new Vector2(0, 1.0f));
prismaticJointDef.lowerTranslation = -0.5f;
prismaticJointDef.upperTranslation = 0.5f;
prismaticJointDef.enableLimit = true;
prismaticJointDef.enableMotor = true;
prismaticJointDef.maxMotorForce = 100.0f;
prismaticJointDef.motorSpeed = 100000f;
prismaticJointDef.collideConnected = false;
this.mPhysicsWorld.createJoint(prismaticJointDef);

关于android - AndEngine 和 Box2D 中的 Spring 墙,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13092234/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com