- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
在我的游戏中,我在特定 Action 中出现一系列硬币。一旦我触摸硬币,硬币就必须一个接一个地平滑地(像飞行一样)移动到屏幕的一个角落。我正在创建和绘制硬币数组,如下所示:
private Coin coins[] = new Coin[10];//coin array
for(int i=0;i<coins.length;i++) {
coins[i]=objectFactory.createCoin();//creating object array of coins
}
抽金币
for(int i=0;i<coins.length;i++) {
coinTexture = coinAnimation.getKeyFrame(animationTime, true);
batch.draw(coinTexture,coins[i].getX(), coins[i].getY());
}
用于检测硬币上的触摸:
if(Gdx.input.isTouched()) {
Vector3 touchPos = new Vector3();
touchPos.set(Gdx.input.getX(), Gdx.input.getY(), 0);
game.camera.unproject(touchPos);
for(int i=0;i<coins.length;i++){
Rectangle textureBounds=new Rectangle(coins[i].getX(),coins[i].getY(),coins[i].getWidth(),coins[i].getHeight());
if(textureBounds.contains(touchPos.x,touchPos.y)) {
System.out.println("u touched the coin!!!!!!!!");
}
}
}
我现在想使用Universal TweenEngine在触摸到屏幕一角时对其进行补间。我对补间引擎的概念完全陌生。我无法找到任何有关如何使用补间引擎实现此效果的有用文档。任何帮助将不胜感激。
最佳答案
在项目中添加补间引擎,将这些依赖项注入(inject)核心模块
compile 'com.github.arcnor:universal-tween-engine:6.3.4'
compile 'com.github.arcnor:universal-tween-engine:6.3.4:sources'
这些 Artifact 可在 https://jitpack.io
中找到,因此请在项目中添加此存储库。
repositories {
maven { url "https://jitpack.io" }
}
创建CoinAccessor
public class CoinAccessor implements TweenAccessor<Coin> {
public static final int POS_XY = 1;
public static final int CPOS_XY = 2;
@Override
public int getValues(Coin target, int tweenType, float[] returnValues) {
switch (tweenType) {
case POS_XY:
returnValues[0] = target.getX();
returnValues[1] = target.getY();
return 2;
case CPOS_XY:
returnValues[0] = target.getX() + target.getWidth()/2;
returnValues[1] = target.getY() + target.getHeight()/2;
return 2;
default: assert false; return -1;
}
}
@Override
public void setValues(Coin target, int tweenType, float[] newValues) {
switch (tweenType) {
case POS_XY: target.setPosition(newValues[0], newValues[1]);
break;
case CPOS_XY: target.setPosition(newValues[0] - target.getWidth()/2, newValues[1] - target.getHeight()/2);
break;
default: assert false;
}
}
}
使用 Coin
注册 CoinAccessor
并更新 TweenManager
。
当硬币正确接触时
Tween.to(coin[i], CoinAccessor.POS_XY, 0.8f).target(targetX,targetY).start(tweenManager);
编辑
对于注册,有相同的静态方法registerAccessor
。
Tween.registerAccessor(Coin.class, new CoinAccessor());
在游戏的更新/渲染方法中调用 TweenManager
的 update()
方法来更新补间管理器。
TweenManager tweenManager = new TweenManager();
tweenManager.update(dt); // this call should be in render/update method
关于java - 在 touch-LibGdx 上将对象数组元素补间到一个角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43992849/
根据 Android docs ,activity生命周期如下: onCreate() onStart() onResume() onPause() onStop() onDestroy() 问题是,
我有一门类(class)有很多专栏,但这个问题只需要其中三个: ---------------------------------------- | start_date | start_time
给定在同一个 Tomcat 6 上运行的两个 Web 应用程序。如果您从一个应用程序到另一个应用程序进行 http 调用,Tomcat 是否会“短路”此调用,或者它会在调用之前一直在 interweb
我是一名优秀的程序员,十分优秀!