level 10
动画有三个状态 “左行” “右行” 和“空闲”
1. 当摇杆左拨动 即konb x <0 人物播放左行动画 并且左移动且 X 与 0之间的绝对值越大 人物移动速度越快
2. 当摇杆右拨动 即 konb x >0 人物播放右行动画 并且右移动 且 X 与 0之间的绝对值越大人物移动速度越快
3. 当摇杆左+上拨动 即konb x <0 Y>0 人物播放左行动画 并且左上移动且 X,Y 与 0之间的绝对值越大 人物移动速度越快
4. 其余同理..
5. 当摇杆左+下拨动 即konb x <0 Y<0 人物播放左行动画 并且左下移动且 X,Y 与 0之间的绝对值越大 人物移动速度越快
6. 当X轴无变动时候(即便Y轴有变动)播放 “空闲”动画 (若Y轴有变动,改变人物Y轴坐标)
之前弄了能播放动画却无法改变坐标
现在搞了一晚上能改变坐标却不能播放移动时候的动作动画
2014年10月21日 16点10分
1
level 10
哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈 已经解决 可以安心睡觉了
package com.mygdx.game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Animation.PlayMode;
import com.badlogic.gdx.graphics.g2d.Batch;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Actor;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad;
import com.badlogic.gdx.scenes.scene2d.ui.Touchpad.TouchpadStyle;
import com.badlogic.gdx.scenes.scene2d.utils.TextureRegionDrawable;
public class Mario extends Actor{
public static float statetime;
public static final int FRAME_ROWS = 4;
public static final int FRAME_COLS = 5;
Texture texture;
TextureRegion currentFrame;
Animation aniRight;
Animation aniLeft;
Animation aniIdle;
Texture texture_background;
Texture killerTexture;
Texture textureSprite;
Texture padTexture;
TextureRegion textureSpriteR;
Sprite sprite;
SpriteBatch batch ;
TextureRegionDrawable background;
TextureRegionDrawable knobRegion;
Touchpad touchpad;
TouchpadStyle touchpadStyle;
int speed =3;
int x;
int y;
enum STATE { // 枚举 state 的可能状态
Left,Right,Idle
}
STATE state;
public Mario(float x,float y){
this.setX(x);
this.setY(y);
state=STATE.Idle;
this.show();
}
public void show(){
texture = new Texture(Gdx.files.internal("data/1.png"));//引入
TextureRegion[][] split = TextureRegion.split(texture, texture.getWidth()/FRAME_COLS, texture.getHeight()/FRAME_ROWS);//分割
TextureRegion[][] miror = TextureRegion.split(texture, texture.getWidth()/FRAME_COLS, texture.getHeight()/FRAME_ROWS);//翻转
for(TextureRegion[] region1:miror){//翻转操作 先 遍历 遍历region1到mirror
for(TextureRegion region2:region1){//遍历region1到 region2
region2.flip(true, false);//翻转 具体请查看构造
// 创建类动画并且翻转 处理图片素材
}
}//右边
TextureRegion[] regionR= new TextureRegion[4];
//regionR[0] = split[0][3];
//regionR[1] = split[1][3];
//regionR[2] = split[2][3];//这段是过程
//regionR[3] = split[3][3];
regionR[0] = split[0][4];
regionR[1] = split[1][4];
regionR[2] = split[2][4];
regionR[3] = split[3][4];
aniRight =new Animation(0.1f,regionR);
aniRight.setPlayMode(PlayMode.LOOP);
TextureRegion[] regionL= new TextureRegion[4];
//regionL[0] = split[0][1];
//regionL[1] = split[1][1]; //这段是过程
//regionL[2] = split[2][1];
//regionL[3] = split[3][1];
regionL[0] = split[0][0];
regionL[1] = split[1][0];
regionL[2] = split[2][0];
regionL[3] = split[3][0];
aniLeft =new Animation(0.1f,regionL);
aniLeft.setPlayMode(PlayMode.LOOP);
TextureRegion[] regionI= new TextureRegion[4];
regionI[0] = split[0][2];
regionI[1] = split[1][2];
regionI[2] = split[2][2];
regionI[3] = split[3][2];
aniIdle =new Animation(0.1f,regionI);
aniIdle.setPlayMode(PlayMode.LOOP);
textureSprite=new Texture(Gdx.files.internal("data/s6.png"));
textureSpriteR =new TextureRegion(textureSprite,0,0,256,256);
texture_background = new Texture(Gdx.files.internal("data/bga3.png"));
padTexture = new Texture(Gdx.files.internal("data/s5.jpg"));
killerTexture = new Texture(Gdx.files.internal("data/s8.png"));
background = new TextureRegionDrawable(new TextureRegion(texture_background, 0,0, 256,256));
knobRegion =new TextureRegionDrawable(new TextureRegion(padTexture , 0, 0, 128, 128));
touchpadStyle=new TouchpadStyle(background, knobRegion);
touchpad=new Touchpad(15, touchpadStyle);
batch=new SpriteBatch();
sprite=new Sprite();
sprite.setRegion(textureSpriteR, 0, 0, 256, 256);
sprite.setSize(256, 256);
sprite.setOrigin(128, 128);
sprite.setPosition(0, 0);
touchpad.setPosition(100, 100);
}
public void update(){
if(touchpad.isTouched()){
this.x += touchpad.getKnobPercentX()*speed ;
this.y += touchpad.getKnobPercentY()*speed ;
if(touchpad.getKnobPercentX()*speed>0){
state=STATE.Right;
sprite.setRotation(sprite.getRotation()-1);
}else if(touchpad.getKnobPercentX()*speed<0){
state=STATE.Left;
sprite.setRotation(sprite.getRotation()+1);
}
}else if(touchpad.isTouched()==false){
state=STATE.Idle;
this.x += touchpad.getKnobPercentX()*speed ;
this.y += touchpad.getKnobPercentY()*speed ;
}
}
public void aniCheck(){
if (state==STATE.Left){
currentFrame=aniLeft.getKeyFrame(statetime,true);
}else if(state==STATE.Right){
currentFrame=aniRight.getKeyFrame(statetime,true);
}else if(state==STATE.Idle){
currentFrame=aniIdle.getKeyFrame(statetime,true);
}
}
@Override
public void draw(Batch batch, float parentAlpha) {
statetime+=Gdx.graphics.getDeltaTime();
this.update();
this.aniCheck();
batch.draw(currentFrame, this.x, this.y);
sprite.draw(batch);
}
@Override
public void act(float delta) {
// TODO Auto-generated method stub
super.act(delta);
}
}
2014年10月21日 18点10分
2
回复 sand1050 :这个怎么做
2014年10月22日 05点10分
回复 sand1050 :怪不得 之前在batch 绘制外层外形框的时候有延迟卡顿 要知道我CPU 3.8g 还卡 这简直是unbelievable
2014年10月22日 06点10分
回复 sand1050 :偶在想偶这外框旋转是不是应该用 RotateAction 来做
2014年10月22日 07点10分
level 10
public void update(){
if(touchpad.isTouched()){
this.x += touchpad.getKnobPercentX()*speed ;
this.y += touchpad.getKnobPercentY()*speed ;
if(touchpad.getKnobPercentX()*speed>0){
state=STATE.Right;
sprite.setRotation(sprite.getRotation()-1);
//后面这段代码没有生效
}else if(touchpad.getKnobPercentX()*speed<0){
state=STATE.Left;
sprite.setRotation(sprite.getRotation()+1);
}
2014年10月22日 06点10分
4