[英]How to rotate sprite continuously at a defined speed? And general questions about game programming
我有一個渲染的圖像:
public void render(float delta) {
batch.begin();
batch.draw(new Sprite(new Texture("img1.png"), 64, 64), x, y);
batch.end()
其中x和y用於根據屏幕分辨率將精靈居中放置在屏幕中間。
我知道我可以使用rotate(float degrees)
來旋轉它,但是如何連續進行呢? 我想我需要以某種方式使用增量時間,例如x += 50 * Gdx.graphics.getDeltaTime();
但這不會使其連續旋轉。 圖像將顯示一幀,然后再跳到另一幀(似乎是逐幀轉換)。
如果我想讓(一個)精靈進行多次碰撞檢測(例如, 這里的每個彩色弧的反應都不同,是否可以在與弧一起移動的頂部上覆蓋一個不可見的圓並在該圓上使用數學運算來解決此問題?每個彩色圓弧都有一個單獨的子圖形,有沒有更簡單的方法?
對於游戲,可以不使用布局/ XML來設計關卡(也就是對所有內容進行硬編碼)嗎? 這是否會使使應用程序兼容多個屏幕分辨率變得更加困難?
我對此並不陌生,所以我希望這些問題有意義。
以這種方式永遠旋轉精靈
public class TestGame extends Game {
SpriteBatch spriteBatch;
Sprite ball;
Texture ballTex;
private int spriteRotationSpeed=1;
@Override
public void create() {
spriteBatch=new SpriteBatch();
ballTex=new Texture("image/bone.png");
ball=new Sprite(ballTex);
ball.setSize(50,50);
ball.setOrigin(25,25);
ball.setPosition(0,0);
}
@Override
public void render() {
super.render();
Gdx.gl.glClearColor(1,1,1,1);
gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
spriteBatch.begin();
ball.draw(spriteBatch);
spriteBatch.end();
rotateSprite();
}
private void rotateSprite(){
float rotation=ball.getRotation();
rotation+=spriteRotationSpeed;
if(rotation>360)
rotation-=360;
ball.setRotation(rotation);
}
@Override
public void resize(int width, int height) {
super.resize(width, height);
}
@Override
public void dispose() {
super.dispose();
ballTex.dispose();
spriteBatch.dispose();
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.