Tag: libgdx

加载TextureAtlas的状态

我在基于LibGdx的游戏中使用TextureAtlas。 随着Atlas的大小增加,加载时间增加,因此显示我在游戏中设置的动画有延迟。 因此,我希望获得TextureAtlas的加载过程的状态。 1.无论如何获得状态? 2.任何听众?

触摸时删除精灵

精灵每秒产生一次,当它被触摸时,它应被移除。 这就是我做的: //Render the sprites and making them move: public void draw(SpriteBatch batch) { for(Sprite drawEnemy:enemies) { drawEnemy.draw(batch); drawEnemy.translateY(deltaTime * movement); touchInput(drawEnemy.getX(),drawEnemy.getY(), drawEnemy.getWidth(),drawEnemy.getHeight(),drawEnemy); } } //Detecting the touch input: public void touchInput(float x,float y,float w,float h,Sprite sprite){ float touchX=Gdx.input.getX(); float touchY=Gdx.input.getY(); if(Gdx.input.justTouched()){ if(touchX > x && touchX < x+w ){ enemyIterator.remove(); Pools.free(sprite); } } } […]

libgdx在受伤时改变精灵色

我正在使用libgdx做一个小平台游戏,我想让敌人用红色闪烁,而玩家用武器伤害他们。 我已经尝试改变精灵颜色和精灵批量颜色没有成功,它只用其中一个纹理融化新颜色。 sprite.setColor(Color.RED); spriteBatch.draw(sprite); 我想要达到的效果是: 从精灵纹理变为全红色,然后再返回。 我认为与混合function有关,但我不确定。 我想避免为我游戏中的每个怪物制作一些红色精灵。 有人知道如何实现这种效果吗?

如何让玩家通过相机摧毁?

我一直遇到一些麻烦,让玩家通过相机被摧毁。 在我的应用程序中,我让相机跟随播放器(球)。 但是相机只能向上跟随球。 所以我想要完成的是,当玩家(球)到达界面的底部(屏幕)时,它就会被摧毁。 在它被摧毁之后,如果出现一个新的活动(新屏幕),那就说“游戏结束”会很好。 非常感谢你的大力支持。 应用程序的界面 包com.luca.tuninga; import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.Input; import com.badlogic.gdx.math.MathUtils; import com.badlogic.gdx.math.Vector2; import com.badlogic.gdx.physics.box2d.*; public class MyGdxGame extends ApplicationAdapter { public static float APP_FPS = 60f; public static int V_WIDTH = 480; public static int V_HEIGHT = 640; Box2DDebugRenderer b2dr; World world; Body […]

Android / Java – GoogleMaps上的自定义视图FragmentActivity未显示

我试图在自定义视图中绘制一些Stuff进行测试,该视图被添加到GoogleMaps FragmentActivity中。 但不知何故,当我在模拟器中运行它时,似乎我的CustomView不绘图。我尝试使用新的RelativeLayout和MapLayout。 有任何想法吗 ? 我做错了什么 ? 下面是我的主要GoogleMaps FragmentActivity代码,由Android模板自动生成: public class GoogleMaps extends FragmentActivity implements OnMapReadyCallback { private GoogleMap mMap; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.google_maps); // Obtain the SupportMapFragment and get notified when the map is ready to be used. SupportMapFragment mapFragment = (SupportMapFragment) getSupportFragmentManager() .findFragmentById(R.id.map); mapFragment.getMapAsync(this); //RelativeLayout relativeLayout = new RelativeLayout(this); […]

如何在群组上实施Fling

我想在一些动画完成之后将一些图像丢弃,并且动画在窗口内运行: 红色的那个在另一个之上,我尝试的是: if (xDn – xUp > 0) { Timeline.createSequence() .beginParallel() .push(Tween.to(GBMImage, SpriteAccessor.X, 0.2f) .target(170f)) end().start(tweenManager); } 其中xDn和XUp是ontouchDown和ontouchUp x值。 左右移动图像。 现在问题出现在左边,fling图像越过后窗,我想要进入红色窗口。 其次,上面的代码适用于单个图像,我无法理解如何将其应用于组,

LibGdx 2半屏“按钮”

(Android)所以我是LibGdx的新手,我正在尝试编写这个chrome dino迷你游戏..当用户触摸屏幕的左侧时我想做动作1,当他触摸右边时做动作2手边的屏幕,我该怎么办?

使用视差屏幕

我想在我的游戏代码中使用视差屏幕使用libgdx,其中屏幕在y方向上移动。 我的游戏代码是…… public class ParallaxLayer{ public TextureRegion region ; public Vector2 parallaxRatio; public Vector2 startPosition; public Vector2 padding ; public ParallaxLayer(TextureRegion region,Vector2 parallaxRatio,Vector2 padding){ this(region, parallaxRatio, new Vector2(0,0),padding); } public ParallaxLayer(TextureRegion region,Vector2 parallaxRatio,Vector2 startPosition,Vector2 padding){ this.region = region; this.parallaxRatio = parallaxRatio; this.startPosition = startPosition; this.padding = padding; } } public class ParallaxBackground { private ParallaxLayer[] […]

LibGdx,如何处理触摸事件?

我是LibGdx新手,并试图使我的iceCream图像可触摸。 我想知道如何设置输入过程(通过触摸屏幕)。 我需要再上一堂课吗? 当我尝试将输入过程实现到我的Prac1类时,JAVA不允许我在不改变类抽象的情况下实现。 具体来说,我喜欢在用户触摸图像时制作它,它会计算触摸次数。 这是我的代码,谢谢你的帮助。 import com.badlogic.gdx.ApplicationAdapter; import com.badlogic.gdx.Gdx; import com.badlogic.gdx.graphics.GL20; import com.badlogic.gdx.graphics.OrthographicCamera; import com.badlogic.gdx.graphics.Texture; import com.badlogic.gdx.graphics.g2d.SpriteBatch; public class Prac1 extends ApplicationAdapter { int w,h,tw,th =0; OrthographicCamera camera; SpriteBatch batch; Texture img; @Override public void create () { w = Gdx.graphics.getWidth(); h = Gdx.graphics.getHeight(); camera = new OrthographicCamera(w, h); camera.position.set(w/2, h/2, 0); camera.update(); batch […]

Libgdx如何通过电话方向在多个轴上旋转3D模型

我正在尝试使用手机的加速度计一次在多个轴上旋转3D模型。 当我这样做时,我使用setToRotation()但是,这一次只能做一个轴。 例如: ModelInstance modelInstance = instances.first(); //ROLL modelInstance.transform.setToRotation(Vector3.Z, phoneAccel.y*9); //PITCH modelInstance.transform.setToRotation(Vector3.X, phoneAccel.z*9); 手机处于强制横向模式。 我得到了我想要旋转的模型的实例。 我根据Gdx.input.getAccelerometerX/Y/Z()设置了Vector3 phoneAccel 。 在上面的示例中,两行代码都正常工作,但只能独立工作。 当我尝试使用两者(一个接一个)时,第一次旋转(ROLL)被移除。 我原本认为两个旋转矩阵将累积,即Z轴应用旋转,然后X轴应用旋转。 我是否需要创建自己的累积旋转矩阵,然后在最后应用它? 有什么想法吗? 干杯