package com.example;
import android.content.Context;
import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.entity.layer.ILayer;
import org.anddev.andengine.entity.shape.IShape;
import org.anddev.andengine.entity.sprite.AnimatedSprite;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.TextureOptions;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.opengl.texture.region.TextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TiledTextureRegion;
import org.anddev.andengine.util.modifier.IModifier;
/**
* Created with IntelliJ IDEA.
* User: wulong
* Date: 14-1-22
* Time: 下午3:39
* To change this template use File | Settings | File Templates.
*/
public class AnimationSprite {
private static final String TAG = AnimationSprite.class.getName();
// 总的图片纹理区域
private TiledTextureRegion tiledTextureRegion;
// 测试用的动画精灵
private AnimatedSprite animatedSprite;
public AnimationSprite(Context pCtx,
Engine pEngine,
ILayer pLayer,
String[] pAssetsPicNameList,
final float pX,
final float pY,
final int pWidth,
final int pHeight) {
int canvasWidth = 2;
int canvasHeight = 2;
while (canvasWidth < pWidth * pAssetsPicNameList.length) {
canvasWidth = canvasWidth * 2;
}
while (canvasHeight < pHeight) {
canvasHeight = canvasHeight * 2;
}
Texture bitmapTextureAtlas = new Texture(canvasWidth, canvasHeight, TextureOptions.BILINEAR_PREMULTIPLYALPHA);
TextureRegion[] childTextureRegions = new TextureRegion[pAssetsPicNameList.length];
for (int i = 0; i < pAssetsPicNameList.length; i++) {
childTextureRegions[i] = TextureRegionFactory.createFromAsset(bitmapTextureAtlas,
pCtx,
pAssetsPicNameList[i],
i * pWidth, 0);
}
tiledTextureRegion = new TiledTextureRegion(bitmapTextureAtlas
, 0, 0
, pWidth * pAssetsPicNameList.length
, bitmapTextureAtlas.getHeight()
, pAssetsPicNameList.length, 1);
pEngine.getTextureManager().loadTexture(bitmapTextureAtlas);
animatedSprite = new AnimatedSprite(pX, pY, tiledTextureRegion);
animatedSprite.setVisible(false);
pLayer.addEntity(animatedSprite);
}
public void addShapeModifier(final IModifier<IShape> pShapeModifier) {
animatedSprite.addShapeModifier(pShapeModifier);
}
public void setVisible(boolean visible) {
animatedSprite.setVisible(visible);
}
public void animate(long pDuration) {
animatedSprite.animate(pDuration);
}
public void setPosition(final float pX, final float pY) {
animatedSprite.setPosition(pX, pY);
}
public void setWidth(final float pWidth) {
animatedSprite.setWidth(pWidth);
}
public boolean isVisible() {
return animatedSprite.isVisible();
}
public void setHeight(final float pHeight) {
animatedSprite.setHeight(pHeight);
}
public float getX() {
return animatedSprite.getX();
}
public float getY() {
return animatedSprite.getY();
}
public float getWidth() {
return animatedSprite.getWidth();
}
public float getHeight() {
return animatedSprite.getHeight();
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
andengine封装动画精灵类
共30个文件
xml:14个
png:7个
properties:3个
4星 · 超过85%的资源 需积分: 10 70 下载量 129 浏览量
2014-01-23
12:15:55
上传
评论 1
收藏 719KB RAR 举报
温馨提示
封装了个andengine的动画精灵类,可以直接传入多张小图片的名称,直接生成动画精灵
资源推荐
资源详情
资源评论
收起资源包目录
dy_tmp.rar (30个子文件)
dy_tmp
res
values
strings.xml 112B
layout
main.xml 472B
ant.properties 696B
build.xml 3KB
assets
game_mole5.png 13KB
game_mole6.png 14KB
game_mole1.png 10KB
game_mole2.png 11KB
game_mole4.png 12KB
bground.png 8KB
game_mole3.png 11KB
dy_tmp.iml 3KB
proguard.cfg 1KB
src
com
example
AnimationSprite.java 4KB
MyActivity.java 3KB
.idea
uiDesigner.xml 9KB
scopes
scope_settings.xml 143B
misc.xml 4KB
vcs.xml 173B
.name 6B
copyright
profiles_settings.xml 115B
modules.xml 263B
encodings.xml 171B
compiler.xml 803B
workspace.xml 33KB
inspectionProfiles
ant.xml 170B
local.properties 443B
project.properties 360B
AndroidManifest.xml 838B
libs
andengine.jar 764KB
共 30 条
- 1
资源评论
- 调节气氛的女程序员2014-12-19还不错,可惜不是我想要的样子
- 我心若自由2016-06-24应该能用,给点力哦
水星灭绝
- 粉丝: 239
- 资源: 53
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功