- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我希望以与 this video 中相同的方式移动 Sprite .我正在使用 AndEngine。我如何使用 AndEngine Box2D 物理扩展来移动忍者( Sprite ),完成移动和跳跃。
这是我的 MainActivity1.class:
public class MainActivity1 extends BaseGameActivity {
Scene scene;
private TiledTextureRegion mPlayerTextureRegion;
private BoundCamera mBoundChaseCamera;
private static final int CAMERA_WIDTH = 1024;
private static final int CAMERA_HEIGHT = 600;
private BitmapTextureAtlas mBitmapTextureAtlas;
private BitmapTextureAtlas mBitmapTextureAtlasp;
private BitmapTextureAtlas mBitmapTextureAtlashm;
private TextureRegion mhomeTextureRegion;
private BitmapTextureAtlas mBitmapTextureAtlas1;
AnimatedSprite player;
private Body playerBody;
private PhysicsWorld mPhysicsWorld;
private BitmapTextureAtlas sheetBitmapTextureAtlas1;
private BitmapTextureAtlas sheetBitmapTextureAtlasplaybtn1;
private TiledTextureRegion mTargetTextureRegionplaybtn1;
public void onLoadComplete() {
// TODO Auto-generated method stub
}
public Engine onLoadEngine() {
// TODO Auto-generated method stub
final Display display = getWindowManager().getDefaultDisplay();
int cameraWidth = display.getWidth();
int cameraHeight = display.getHeight();
// Toast.makeText(this, "The tile the player is walking on will be highlighted.", Toast.LENGTH_LONG).show();
this.mBoundChaseCamera = new BoundCamera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
return new Engine(new EngineOptions(true, ScreenOrientation.LANDSCAPE, new RatioResolutionPolicy(cameraWidth, cameraHeight), this.mBoundChaseCamera));
}
public void onLoadResources() {
// TODO Auto-generated method stub
mBitmapTextureAtlas = new BitmapTextureAtlas(512, 512,
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
mBitmapTextureAtlas1 = new BitmapTextureAtlas(1024, 1024,
TextureOptions.BILINEAR_PREMULTIPLYALPHA);
this.sheetBitmapTextureAtlasplaybtn1 = new BitmapTextureAtlas(512, 512);
mTargetTextureRegionplaybtn1 = BitmapTextureAtlasTextureRegionFactory
.createTiledFromAsset(sheetBitmapTextureAtlasplaybtn1, this,
"gfx/gameplay_stormstrike_full.png", 0, 212,1, 1);
this.mBitmapTextureAtlasp = new BitmapTextureAtlas(512, 512, TextureOptions.DEFAULT);
this.mPlayerTextureRegion = BitmapTextureAtlasTextureRegionFactory.createTiledFromAsset(this.mBitmapTextureAtlasp, this, "gfx/storm_strike.png", 0, 0, 1, 1); // 72x128
mTargetTextureRegion1 = BitmapTextureAtlasTextureRegionFactory
.createTiledFromAsset(sheetBitmapTextureAtlas1, this,
"gfx/kolobok_04_walk.png", 0, 212,12, 1);
this.mEngine.getTextureManager().loadTexture(this.sheetBitmapTextureAtlas);
this.mEngine.getTextureManager().loadTexture(this.sheetBitmapTextureAtlas1);
BitmapTextureAtlasTextureRegionFactory.createFromAsset(this.mBitmapTextureAtlashm, this, "gfx/loading_ipad.png", 0, 0);
mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas);
mEngine.getTextureManager().loadTexture(sheetBitmapTextureAtlasplaybtn1);
mEngine.getTextureManager().loadTexture(mBitmapTextureAtlasp);
mEngine.getTextureManager().loadTexture(mBitmapTextureAtlas1);
mEngine.getTextureManager().loadTexture(mBitmapTextureAtlashm);
}
public Scene onLoadScene() {
// TODO Auto-generated method stub
this.mEngine.registerUpdateHandler(new FPSLogger());
scene = new Scene();
scene.setBackground(new ColorBackground(0, 0, 0.8784f));
this.mPhysicsWorld = new FixedStepPhysicsWorld(30, new Vector2(0, 0), false, 8, 1);
final Sprite help = new Sprite(50, 70, mProjectileTextureRegionhelp);
scene.attachChild(help);
help.setVisible(false);
player = new AnimatedSprite(100, 200, 150,150,this.mPlayerTextureRegion)
{
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
switch(pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
playerBody.setLinearVelocity(10f,-10f);
break;
case TouchEvent.ACTION_MOVE:
break;
case TouchEvent.ACTION_UP:
break;
}
return true;
}
};
scene.attachChild(player);
scene.registerTouchArea(player);
projectilesToBeAdded.add(player);
AnimatedSprite playerbtn = new AnimatedSprite(10, 200, this.mTargetTextureRegionplaybtn1)
{
@Override
public boolean onAreaTouched(final TouchEvent pSceneTouchEvent, final float pTouchAreaLocalX, final float pTouchAreaLocalY) {
switch(pSceneTouchEvent.getAction()) {
case TouchEvent.ACTION_DOWN:
playerBody.applyForce(new Vector2(200,-1500), new Vector2(playerBody.getWorldCenter()));
break;
case TouchEvent.ACTION_MOVE:
break;
}
return true;
}
};
scene.attachChild(playerbtn);
scene.registerTouchArea(playerbtn);
final FixtureDef carFixtureDef = PhysicsFactory.createFixtureDef(10.0f, 0.5f, 0.5f);
this.playerBody = PhysicsFactory.createBoxBody(this.mPhysicsWorld, this.player, BodyType.DynamicBody, carFixtureDef);
this.mPhysicsWorld.registerPhysicsConnector(new PhysicsConnector(this.player, this.playerBody, true,false));
scene.setTouchAreaBindingEnabled(true);
this.scene.registerUpdateHandler(this.mPhysicsWorld);
return scene;
}
}
最佳答案
示例视频中发生的 Action 涉及几个不同的概念。您应该通读 AndEngine 示例。特别是,看看这两个:
要开始跳跃,您需要在忍者的物理 body 上调用 applyForce()。你需要在忍者和他弹跳的表面上产生摩擦力来产生弹跳。根据下面的评论,我将提供一些额外的定义。顺便说一下,这些不是我的,它们来自 the manual .
The fixture density is used to compute the mass properties of the parent body. The density can be zero or positive. You should generally use similar densities for all your fixtures. This will improve stacking stability. The mass of a body is not adjusted when you set the density. You must call ResetMassData for this to occur.
In kinematics, velocity is the rate of change of the position of an object, equivalent to a specification of its speed and direction of motion. Speed describes only how fast an object is moving, whereas velocity gives both how fast and in what direction the object is moving.
Friction is used to make objects slide along each other realistically. Box2D supports static and dynamic friction, but uses the same parameter for both. Friction is simulated accurately in Box2D and the friction strength is proportional to the normal force (this is called Coulomb friction). The friction parameter is usually set between 0 and 1, but can be any non-negative value. A friction value of 0 turns off friction and a value of 1 makes the friction strong. When the friction force is computed between two shapes, Box2D must combine the friction parameters of the two parent fixtures. This is done with the geometric mean:
float32 friction;
friction = sqrtf(shape1->friction * shape2->friction);
So if one fixture has zero friction then the contact will have zero friction.
关于android - 如何在 AndEngine 中同时弹跳、移动和跳跃 Sprite ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14998787/
我是一个 JS 菜鸟。我正在进入浏览器游戏编程,并想制作一个球掉落和弹跳的快速示例以供学习。由于某种原因,当我创建 jsfiddle 时,我的代码实际上不起作用,我的 div id="ball"的 o
我正在努力寻找为此目的的插件/插件,它是我项目的关键部分,我忽略了它,现在它咬了我。 我需要 jQuery 弹跳的变体,它使 div 无限期地围绕父 div/包装器弹跳。 实际上,我将拥有一个屏幕,用
我的 Nib 底部有一个 UIView。我希望它的高度能够增长,但让它看起来好像它没有移动位置,只是在增长。然后将高度缩小回原来的高度,除了高度之外不进行任何移动。不幸的是,它在 y 位置上反弹。它会
我做错了什么?我的技能栏正在跳舞。加载后我想修复它们。 在这里检查我的笔:http://codepen.io/anon/pen/KdEeWW $(window).scroll(function() {
我有一个有 2 列的表格,其中一列具有设定的宽度,第二列占据页面的其余部分。 在第一列中,我有另一个包含 2 个 tr 元素的表(这是由 asp 生成的) 如此处所示的表格:http://jsfidd
我正在使用 jQuery 构建基于标准 ul>li 结构的下拉导航。 一切都运行良好,但是,当我到达三元级别项目时,slideToggle 函数会导致“反弹”并且永远不会显示子 UL 由于有相当多的代
大家好,谢谢大家的帮助, 我想做的事情相当简单,我想显示一个跟随我的弹跳/反射 Raycast 的线渲染器。 这是我目前所拥有的。 private LineRenderer lr; public i
我试图对齐中间圆圈中的文本并让它们在圆圈悬停时弹跳(即文本) 这里是: http://jsfiddle.net/cJ3se/ 希望有人能帮忙 丹佛 最佳答案 将元素中的单行文本垂直居中的最简单方法是将
这很难解释,我来试一试。 我目前有一个从右向左无休止地滑动的图像背景,就像传送带一样。图像用完时会重复。 我试图让图像/动画在重复之前反弹(反向)。所以图像慢慢地向一个方向滑动,然后慢慢地向另一个方向
我想知道为什么我的弹跳动画在 JSFiddle 中不起作用但在我的开发网站上工作。请检查这个有什么问题。在我的开发站点中,箭头会弹跳但不会像我的 CSS 类中所说的那样旋转。 .active.ongo
我正在使用Pymunk模拟安装在细长腿顶部枢轴上的盒子的物理特性,该腿固定在地面上。连接盒子和腿的枢轴是 PivotJoint 和 SimpleMotor 的组合,模拟原始伺服系统,用户可以打开和关闭
我正在开发一个带有 ScrollView 的应用程序。不是很明显有更多内容,并且没有滚动指示器( ScrollView 被分页)。 所以,为了给用户一个“嘿,这里有东西……”,我想让 ScrollVi
我的应用程序中有启用了垂直弹跳的 UIScrollView。我需要屏幕底部的弹跳,但没有在屏幕顶部启用。 我不知道如何用以下方法检测 ScrollView : (void)scrollViewWi
我的网站有问题,我在其中使用带有 jQuery UI 的 jQuery,在登录框上创建弹跳效果。 但是,我对带有登录框的 div 有问题,因为它在屏幕左侧弹跳,当它应该在中间弹跳时,它在完成弹跳后
当网页内容大于视口(viewport)时,我正在尝试实现一种解决方案,以防止 iOS 版 Safari 中的 iOS 反弹效果。 我正在处理的页面在结构上非常具体,与此页面非常相似 http://ne
第一次在这里发帖,如有任何标记问题请见谅。写帖子用SOF框架不习惯。 我试图让一些社交图标在悬停时在我的网站上跳动。我从 jQuery UI 抓取代码进行测试并进行了一些小的编辑,但是我遇到了页面上可
我有一个 UIScrollView,我想在滚动时弹跳,但目前它能够弹跳,尽管内容大小与框架相同。如果内容大小和框架大小相同,如何阻止它弹跳?有没有比重写 setContentSize 和 setFra
我的网页最右侧有一个 div (RightSide),它位于另一个 div (TopBanner) 的正下方。即使用户向下滚动,TopBanner div 也会保持其在屏幕顶部的准确位置。正是我想要的
我有一个带分页的水平 UIScrollView。有两个按钮。一个向左滚动 scrollView,另一个向右滚动。 左边的代码: - (IBAction)goLeftAction:(id)sender
我正在尝试创建自定义垂直 UIScrollView,它可以处理具有不同页面高度的多个页面。 假设: 页面高度等于或大于屏幕高度 如果页面高于屏幕高度,它会像往常一样滚动 UIScrollView –
我是一名优秀的程序员,十分优秀!