libgdx学习之图片翻转

在看libgdx的cuboc的游戏源码遇到了图片翻转的两种形式,初次接触游戏编程,研究了半天才弄明白,衰

1.调用函数TextRegion.flip(boolean x,boolean y)

x、y轴进行翻转;

TextRegion text=new TextRegion(new Texture(Gdx.files.internal("a.jpg"));
text.flip(true,flase);

 原图


x轴翻转以后



y轴翻转

text.flip(false,true)

原图 

y翻转后

x、y轴翻转

text.flip(true,true)

 原图 

x、y轴翻转以后



flip函数适用于90和180对称旋转的情况,当然用SpriteBatch.draw的rotation功能也能实现类似的效果

2.SpriteBatch.draw()

函数定义

public void draw (TextureRegion region, float x, float y, float originX, float originY, float width, float height,
float scaleX, float scaleY, float rotation){
}

 参数说明:

region:绘制纹理

x:位置坐标x

y:位置坐标y

originX:与x的x轴偏移量

originY:与y的y轴的偏移量

width:宽度

height:长度

scaleX:扩展倍数

scaleY:扩展倍数

rotation:翻转角度 逆时针方向为正(刚开始看成顺时针了,想了半天没想明白)

旋转原理

ex=originX+x

ey=originY+y

以(ex,ey)为原点,如果rotation为正,则逆时针旋转rotation度,为负,则顺时针旋转|rotation|度

猜你喜欢

转载自macken.iteye.com/blog/1828278