protected void createCachedAnimations(Map<String, Integer> map) {
int i = 0;
for (Map.Entry<String, Integer> entry : map.entrySet()) {
String animationName = entry.getKey();
int frameCounter = entry.getValue();
// calculate duration per frame
float durationPerFrame = this.sumDuration / frameCounter;
// get regions
Array<TextureAtlas.AtlasRegion> regions = this.atlas.findRegions(animationName);
// create animation
Animation<TextureRegion> anim = new Animation<>(durationPerFrame, regions, Animation.PlayMode.LOOP);
// add animation to map
this.animationMap.put(animationName, anim);
i++;
}
}
java类com.badlogic.gdx.graphics.g2d.Animation的实例源码
AtlasAnimationComponent.java 文件源码
项目:SpaceChaos
阅读 24
收藏 0
点赞 0
评论 0
AnimationTextureUtils.java 文件源码
项目:SpaceChaos
阅读 24
收藏 0
点赞 0
评论 0
public static Animation<TextureRegion> createAnimationFromTexture(Texture texture, float duration, int rows,
int cols) {
// split texture into texture regions
TextureRegion[][] tmp = TextureRegion.split(texture, texture.getWidth() / cols, texture.getHeight() / rows);
TextureRegion[] frames = new TextureRegion[cols * rows];
int index = 0;
for (int i = 0; i < rows; i++) {
for (int j = 0; j < cols; j++) {
frames[index++] = tmp[i][j];
}
}
// create new animation
Animation<TextureRegion> animation = new Animation<TextureRegion>(duration, frames);
return animation;
}
MobAnimationController.java 文件源码
项目:miniventure
阅读 26
收藏 0
点赞 0
评论 0
TextureRegion pollAnimation(float delta) {
// update the animation
animationTime += delta;
// fetch the current frame
String textureName = state.name().toLowerCase() + "-" + mob.getDirection().name().toLowerCase();
Animation<TextureRegion> ani = animations.get(textureName);
if(animationTime > ani.getAnimationDuration()) animationTime = 0; // reset the animationTime to prevent any possibility of overflow
TextureRegion frame = ani.getKeyFrame(animationTime, true);
// reset the animation
prevState = state;
state = requestedAnimations.poll();
if(state == null) state = AnimationState.IDLE;
if(state != prevState)
animationTime = 0; // if we're going to render a new animation, we should start it from the beginning, I think. Though, I could see this not ending up being a good idea... NOTE: this is not just set to zero because it seems this causes a divide by zero error when fetching the keyframe.
requestedAnimations.clear();
return frame;
}
BaseSprite.java 文件源码
项目:TH902
阅读 20
收藏 0
点赞 0
评论 0
/**
* @param color
* 0 - blue; 1 - red; 2 - green; 3 - yellow
*/
public static Entity Create(Vector2 position, int color, int maxhp, Component... Ves) {
if (color < 0 || color > 3) {
throw new IllegalArgumentException("Color of the enemy (sprite) should be between 0 and 3!");
}
Entity entity = Entity.Create();
Transform transform = new Transform(position, new Vector2(0.5f, 0.5f));
entity.AddComponent(transform);
BaseSprite component = new BaseSprite();
component.selfColor = color;
component.animation = new AnimationDrawable();
if (texture != ResourceManager.enemies.get(0)) {
texture = ResourceManager.enemies.get(0);
regions = TextureRegion.split(texture, texture.getWidth() / 12, texture.getHeight() / 4);
}
component.animation.setAnimation(new Animation<TextureRegion>(1, regions[color]));
EnemyHP hp = new EnemyHP(maxhp);
entity.AddComponent(hp);
entity.AddComponent(new EnemyJudgeCircle(48 * transform.scale.x, hp));
entity.AddComponent(new EnemyChaseable(hp));
entity.AddComponent(component);
for (Component tmpc : Ves) {
entity.AddComponent(tmpc);
}
return entity;
}
Pony.java 文件源码
项目:Ponytron
阅读 26
收藏 0
点赞 0
评论 0
public void init() {
CURRENT_STATE = PONY_STATE.STANDING;
isFacingRight = false;
runAnimation = new Animation(FRAME_DURATION, AssetDoctor.getTextureRegion_ATLAS("pony_01"), AssetDoctor.getTextureRegion_ATLAS("pony_02"));
runAnimation.setPlayMode(Animation.PlayMode.LOOP);
cheerAnimation = new Animation(FRAME_DURATION, AssetDoctor.getTextureRegion_ATLAS("pony_cheer_00"), AssetDoctor.getTextureRegion_ATLAS("pony_cheer_01"), AssetDoctor.getTextureRegion_ATLAS("pony_cheer_02"));
cheerAnimation.setPlayMode(Animation.PlayMode.LOOP_PINGPONG);
currentSprite = new Sprite(AssetDoctor.getSprite("pony"));
resizeSprite(currentSprite);
moveToX = x;
moveToY = y;
}
BulletRenderer.java 文件源码
项目:arcadelegends-gg
阅读 20
收藏 0
点赞 0
评论 0
@Override
public void inserted(int entityId, RenderSystem renderSystem) {
RenderComponent render = renderSystem.getMapperRender().get(entityId);
PositionComponent position = renderSystem.getMapperPosition().get(entityId);
if (render.animations.size == 0) {
for (Map.Entry<String, RenderComponent.RenderTemplate.AnimationTemplate> entry : render.renderTemplate.animationTemplates.entrySet()) {
TextureRegion texture = renderSystem.getLevelAssets().get(entry.getValue().texture);
TextureRegion[][] tmp = texture.split(
+texture.getRegionWidth() / entry.getValue().frameColumns,
+texture.getRegionHeight() / entry.getValue().frameRows);
TextureRegion[] frames = new TextureRegion[entry.getValue().frameColumns * entry.getValue().frameRows];
int index = 0;
for (int i = 0; i < entry.getValue().frameRows; i++) {
for (int j = 0; j < entry.getValue().frameColumns; j++) {
frames[index++] = tmp[i][j];
}
}
render.animations.put(entry.getKey(), new Animation<TextureRegion>(entry.getValue().frameDuration, new Array<>(frames), Animation.PlayMode.LOOP));
}
}
Decal decal = Decal.newDecal(render.width, render.height, render.getCurrentKeyFrame(renderSystem.getStateTime()), render.transparent);
decal.rotateX(renderSystem.getWorldDegree());
decal.setPosition(position.position.x, position.position.y, 0);
renderSystem.getDecalMap().put(entityId, decal);
}
Entity.java 文件源码
项目:Hackerman
阅读 34
收藏 0
点赞 0
评论 0
/**
* Creates a player and assigns a texture to it.
* Creates an animation by splitting the given sprite sheet into an array of TILE_WIDTHxTILE_HEIGHT dimension.
* ERROR should be 9x4 but ends up being 4x2
* @param playerTexture
* @param dynamicEntity
*/
public Entity(Texture playerTexture, DynamicEntity dynamicEntity) {
int orientation = dynamicEntity.getDirection().getCode();
TextureRegion[][] playerTextures = TextureRegion.split(playerTexture,TILE_WIDTH,TILE_HEIGHT);
this.dynamicEntity = dynamicEntity;
switch (orientation) {
case Direction.UP:
animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[0][0], playerTextures[0][1], playerTextures[0][2],playerTextures[0][3],playerTextures[0][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
break;
case Direction.DOWN:
animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[2][0], playerTextures[2][1], playerTextures[2][2],playerTextures[2][3],playerTextures[2][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
break;
case Direction.LEFT:
animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[1][0], playerTextures[1][1], playerTextures[1][2],playerTextures[1][3],playerTextures[1][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
break;
case Direction.RIGHT:
animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[3][0], playerTextures[3][1], playerTextures[3][2],playerTextures[3][3],playerTextures[3][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
break;
default:
animation = new Animation<TextureRegion>(FRAME_DURATION,playerTextures[0][0], playerTextures[0][1], playerTextures[0][2],playerTextures[0][3],playerTextures[0][4]);//,playerTextures[0][5],playerTextures[0][6],playerTextures[0][7],playerTextures[0][8]);
}
animation.setPlayMode(Animation.PlayMode.LOOP);
}
Animator.java 文件源码
项目:StarshipFighters
阅读 33
收藏 0
点赞 0
评论 0
public void initialize() {
// Load SpriteSheet
spriteSheet = new Texture(Gdx.files.internal(filePath));
// Extract Sprites
TextureRegion[][] tmp = TextureRegion.split(spriteSheet, spriteSheet.getWidth() / frameCols, spriteSheet.getHeight() / frameRows);
// Place into 1D array
animationSprites = new TextureRegion[columnCutOff * rowCutOff];
int index = 0;
for (int i = 0; i < rowCutOff; i++) {
for (int j = 0; j < columnCutOff; j++) {
animationSprites[index++] = tmp[i][j];
}
}
// Load animation frames
animationTextureRegion = new Animation<TextureRegion>(frameLengthTime, animationSprites);
}
GameState.java 文件源码
项目:KyperBox
阅读 26
收藏 0
点赞 0
评论 0
public GameState(String name, String tmx, StateManager manager) {
this.tmx = tmx;
setManager(manager);
if(name!=null)
this.name = name;
else
this.name = "";
sprites = new ObjectMap<String, Sprite>();
animations = new ObjectMap<String, Animation<String>>();
fonts = new ObjectMap<String, BitmapFont>(); //TODO: test load to avoid repeats
particle_effects = new ObjectMap<String, ParticleEffectPool>();
pvalues = new Array<String>();
time_scale = 1f;
shaders = new ObjectMap<String, ShaderProgram>();
svalues = new Array<String>();
}
JumpBall.java 文件源码
项目:libGdx-xiyou
阅读 22
收藏 0
点赞 0
评论 0
private void init() {
mSkillAtlas = MyGdxGame.assetManager.getTextureAtlas(Constant.FIREBALL_WIDGET);
//升龙斩动画初始化
mRJumpAtkRegions = new TextureAtlas.AtlasRegion[4];
for (int i = 0; i < mRJumpAtkRegions.length - 1; i++) {
mRJumpAtkRegions[i] = new TextureAtlas.AtlasRegion(mSkillAtlas.findRegion("jumpHit" + (i + 1)));
}
mRJumpAtkRegions[3] = new TextureAtlas.AtlasRegion(mSkillAtlas.findRegion("jumpHit3"));
mLJumpAtkRegions = new TextureAtlas.AtlasRegion[4];
for (int i = 0; i < mLJumpAtkRegions.length - 1; i++) {
mLJumpAtkRegions[i] = new TextureAtlas.AtlasRegion(mSkillAtlas.findRegion("jumpHit" + (i + 1)));
mLJumpAtkRegions[i].flip(true, false);
}
mLJumpAtkRegions[3] = mLJumpAtkRegions[2];
mRJumpAtkAni = new Animation(1 / 12f, mRJumpAtkRegions);
mLJumpAtkAni = new Animation(1 / 12f, mLJumpAtkRegions);
}
CellView.java 文件源码
项目:retro-reversi
阅读 22
收藏 0
点赞 0
评论 0
public CellView(GamePresenter presenter, int x, int y, int boardX, int boardY) {
this.presenter = presenter;
actorX = x;
actorY = y;
this.boardX = boardX;
this.boardY = boardY;
setBounds(actorX, actorY, tile.getWidth(), tile.getHeight());
previousPiece = presenter.getCurrentPiece(boardX, boardY);
addListeners();
ICONS.put('B', black);
ICONS.put('W', white);
ICONS.put('X', suggestion);
ICONS.put('-', null);
System.arraycopy(blackFramesTmp[0], 0, blackFrames, 0, 7);
System.arraycopy(whiteFramesTmp[0], 0, whiteFrames, 0, 7);
blackAnimation = new Animation<TextureRegion>(0.09f, blackFrames);
whiteAnimation = new Animation<TextureRegion>(0.09f, whiteFrames);
}
BossEnemy.java 文件源码
项目:GangsterSquirrel
阅读 24
收藏 0
点赞 0
评论 0
/**
* Sets up the enemy in the game
* @param screen the play screen
* @param spawnPositionX the spawn position as tile index on the x axis
* @param spawnPositionY the spawn position as tile index on the y axis
*/
public BossEnemy(PlayScreen screen, float spawnPositionX, float spawnPositionY) {
super(screen, spawnPositionX, spawnPositionY);
playScreen = screen;
// Set gameplay variables of super class for this specific type of enemy
damageMinMax = new int[] { 10, 20 };
health = 50;
horizontalMoveImpulseVelocity = 0.1f;
horizontalMaxMovementVelocity = 0.5f;
// Animation set up
flyFrames = new Array<>();
for(int i = 0; i < 12; i++) {
flyFrames.add(new TextureRegion(screen.getEnemyBossTextureAtlas().findRegion("bird"), 0, i * ENEMY_PIXEL_HEIGHT, ENEMY_PIXEL_WIDTH, ENEMY_PIXEL_HEIGHT)
);
}
flyAnimation = new Animation<TextureRegion>(0.2f, flyFrames);
currentAnimation = "bird_fly";
stateTime = 0;
setBounds(getX(), getY(), ENEMY_PIXEL_WIDTH / MainGameClass.PPM, ENEMY_PIXEL_HEIGHT / MainGameClass.PPM + getHeight() / 2);
}
Explosion.java 文件源码
项目:space-travels-3
阅读 23
收藏 0
点赞 0
评论 0
public Explosion(float x, float y, float width, float height, TextureAtlas textureAtlas)
{
this.physicsComponent = new PhysicsComponent(
x,
y,
0f,
(height + width) / 4f,
new GameEntityGroup(GameEntityGroup.GroupOverride.NONE),
this.getClass(),
false,
PhysicsComponentType.DYNAMIC);
this.graphicComponent = new AnimatedGraphicComponent(
textureAtlas,
Constants.Visual.EXPLOSION_LIFETIME,
width,
height,
this.physicsComponent,
Animation.PlayMode.NORMAL);
this.sound = AssMan.getGameAssMan().get(AssMan.getAssList().explosionSound);
this.sound.play(SettingsManager.getSettings().volumeFX);
}
ScheduleSubView.java 文件源码
项目:ld37
阅读 20
收藏 0
点赞 0
评论 0
public Animation getAnimation(String image, int frameCount, float frameDuration) {
TextureRegion[] frames = new TextureRegion[frameCount];
for (int i = 0; i < frameCount; ++i) {
frames[i] =
new TextureRegion(
new Texture(
Gdx.files.internal(
PATH_PREFIX+image+String.format("%04d", i)+PATH_SUFFIX
)
)
);
}
Animation animation = new Animation(frameDuration, frames);
return animation;
}
AddEffectVisualizer.java 文件源码
项目:dice-heroes
阅读 23
收藏 0
点赞 0
评论 0
@Override public IFuture<Void> visualize(final AddEffect result) {
final Array<TextureAtlas.AtlasRegion> regions = Config.findRegions("animation/effect-" + result.ability.name);
if (regions.size == 0)
return Future.completed();
final WorldObjectView view = visualizer.viewController.getView(result.getTarget());
final AnimationSubView subView = new AnimationSubView(0.1f, regions, Animation.PlayMode.LOOP);
subView.getActor().setPosition(1, 2);
subView.priority = 1;
view.addSubView(subView);
visualizer.viewController.world.dispatcher.add(Creature.REMOVE_EFFECT, new EventListener<EffectEvent>() {
@Override public void handle(EventType<EffectEvent> type, EffectEvent event) {
if (event.effect != result.effectToApply || event.creature != result.creatureToAddEffect)
return;
visualizer.viewController.world.dispatcher.remove(Creature.REMOVE_EFFECT, this);
SoundManager.instance.playMusicAsSound("boss-protection-loss");
subView.getActor().addAction(Actions.alpha(0, DURATION));
subView.getActor().addAction(Actions.delay(DURATION, Actions.run(new Runnable() {
@Override public void run() {
view.removeSubView(subView);
}
})));
}
});
return Future.completed();
}
ChainLink.java 文件源码
项目:cgc-game
阅读 21
收藏 0
点赞 0
评论 0
public ChainLink(Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType pEntityType, Body attachedBody)
{
super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody);
//Determine half-values for use with rendering logic
// These numbers are calculated based on the texture dimensions of the associated art asset.
// The relationship is: 1.0f in world space is 96x96 in pixels (see art asset to get dimensions)
// By default, half-width and half-height are calculated based on the base image's dimensions
// when rotated/aligned horizontally.
//this.halfHeight = -0.104166667f;
//this.halfWidth = -0.15625f;
rotation = body.getAngle() * Data.RADDEG;
}
Helicopter.java 文件源码
项目:cgc-game
阅读 24
收藏 0
点赞 0
评论 0
public Helicopter(CGCWorld theWorld, Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType entityType, Body body)
{
super(newLowAnimation, newMidAnimation, newHighAnimation, entityType, body);
gameWorld = theWorld;
Gdx.app.log("In the pipe", "five by five");
rotation = 90;
//SoundManager.playSound("helicopter", false);
hoverTask = new Timer.Task() {
public void run()
{
stopped = false;
returnTrip = true;
getBody().setLinearVelocity(new Vector2(4,0));
}
};
hoverClock = new CGCTimer(hoverTask, hoverTime, false, "hoverClock");
body.setLinearVelocity(new Vector2(4, 0));
}
SpotlightCop.java 文件源码
项目:cgc-game
阅读 24
收藏 0
点赞 0
评论 0
public SpotlightCop(CGCWorld theWorld, Animation newLowAnimation,
Animation newMidAnimation, Animation newHighAnimation,
EntityType pEntityType, Body attachedBody, short pID,
float cameraPosX, float cameraPosY)
{
super(theWorld, newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody, pID);
body.getFixtureList().get(0).setSensor(true);
// Create spotlight
Body b = CGCWorld.getBF().createCircle(cameraPosX, cameraPosY,
2.1f, BodyType.DynamicBody, BodyFactory.CAT_INTERACTABLE, BodyFactory.MASK_INTERACTABLE);
b.getFixtureList().get(0).setSensor(true);
b.setFixedRotation(true);
spotlight = new Spotlight(null, null, TextureAnimationDrawer.spotlightAnim,
EntityType.TARGETER, b, CGCWorld.getCamera(), getPID());
b.setUserData(spotlight);
spotlight.addToWorldLayers(CGCWorld.getLH());
alive = true;
lowState = AnimationState.STAND;
}
RookieCop.java 文件源码
项目:cgc-game
阅读 28
收藏 0
点赞 0
评论 0
public RookieCop(CGCWorld theWorld, Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType pEntityType, Body attachedBody, short pID)
{
super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType, attachedBody, pID);
gameWorld = theWorld;
maxGrabStrength = MAX_GRAB_STRENGTH_BASE + Math.round(((float)(Math.random() * 2) - 1.0f) * MAX_GRAB_RANGE);
currentGrabStrength = maxGrabStrength;
noGrab = false;
setCoins(0);
grabCooldownTask = new Timer.Task()
{
public void run()
{
currentGrabStrength = maxGrabStrength;
noGrab = false;
}
};
grabCooldownTimer = new CGCTimer(grabCooldownTask, grabCooldown, false, "grabCooldownTimer");
}
GameScreen.java 文件源码
项目:123Dor
阅读 19
收藏 0
点赞 0
评论 0
private Animation getAnimation(Cowboy.State state, String side){
if(state.equals(Cowboy.State.SHOOT)){
if(side.equals("left"))
return shotLeftAnimation;
else
return shotRightAnimation;
}else if(state.equals(Cowboy.State.LOSE)){
if(side.equals("left"))
return dieLeftAnimation;
else
return dieRightAnimation;
}else if(state.equals(Cowboy.State.WIN)){
if(side.equals("left"))
return winLeftAnimation;
else
return winRightAnimation;
}else{
return null;
}
}
Prisoner.java 文件源码
项目:cgc-game
阅读 39
收藏 0
点赞 0
评论 0
public Prisoner(CGCWorld theWorld, Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType pEntityType, Body attachedBody, short pID)
{
super(newLowAnimation, newMidAnimation, newHighAnimation,
pEntityType, attachedBody, pID);
gameWorld = theWorld;
towerContacts = new Array<GuardTower>();
lightContacts = new Array<Spotlight>();
sensorContacts = new Array<Sensor>();
grabbedByArray = new Array<RookieCop>();
keyID = (int) (playerID+1);
maxStamina = MAX_STAMINA_BASE + Math.round(((float)(Math.random() * 2) - 1.0f) * MAX_STAMINA_RANGE);
currentStamina = maxStamina;
}
Sheriff.java 文件源码
项目:cgc-game
阅读 39
收藏 0
点赞 0
评论 0
public Sheriff(Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType pEntityType,
Body attachedBody, Boss bo, float startAlpha)
{
super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType,
attachedBody, startAlpha);
boss = bo;
fireTask = new Timer.Task()
{
public void run()
{
fire();
}
};
fireTimer = new CGCTimer(fireTask, fireTime, true, "fireTimer");
do
{
target = CGCWorld.getPrisoners().random();
}while(!target.isAlive() || target == null);
TimerManager.addTimer(fireTimer);
}
Assets.java 文件源码
项目:Battle-City-Multiplayer
阅读 27
收藏 0
点赞 0
评论 0
public static Animation createAnimation(TextureAtlas atlas,
String regionName, float frameDuration, Animation.PlayMode mode) {
ArrayList<TextureRegion> frames = new ArrayList<>();
int idx = 0;
TextureAtlas.AtlasRegion region;
while ((region = atlas.findRegion(regionName, idx)) != null) {
frames.add(region);
idx++;
}
TextureRegion[] regions = new TextureRegion[idx];
Animation anim = new Animation(frameDuration, frames.toArray(regions));
anim.setPlayMode(mode);
return anim;
}
GameEntity.java 文件源码
项目:cgc-game
阅读 34
收藏 0
点赞 0
评论 0
public GameEntity(Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType pEntityType, Body attachedBody)
{
lowAnimation = newLowAnimation;
midAnimation = newMidAnimation;
highAnimation = newHighAnimation;
entityType = pEntityType;
alpha = 1.0f;
lowStateTime = 0.0f;
midStateTime = 0.0f;
highStateTime = 0.0f;
recalcHalfDimensions();
scaled = false;
body = attachedBody;
transformMod = new Vector3(0, 0, 1);
// These numbers are calculated based on the texture dimensions of the associated art asset.
// The relationship is: 1.0f in world space is 96x96 in pixels (see art asset to get dimensions)
// By default, half-width and half-height are calculated based on the base image's dimensions
// when rotated/aligned horizontally.
scaling = new Vector2(1.0f, 1.0f);
}
AnimationDrawable.java 文件源码
项目:TerraLegion
阅读 18
收藏 0
点赞 0
评论 0
public AnimationDrawable(SpriteSheet sheet) {
final int startX = 0;
final int startY = 0;
final int frames = 3;
Array<TextureRegion> tempSpritesUp = AnimationDrawable.grabSprites(sheet, startX, startY, frames);
Array<TextureRegion> tempSpritesDown = AnimationDrawable.grabSprites(sheet, startX, startY + 2, frames);
Array<TextureRegion> tempSpritesLeft = AnimationDrawable.grabSprites(sheet, startX, startY + 1, frames, true);
Array<TextureRegion> tempSpritesRight = AnimationDrawable.grabSprites(sheet, startX, startY + 1, frames);
AnimationDrawable.addMiddleReversed(tempSpritesUp, false);
AnimationDrawable.addMiddleReversed(tempSpritesDown, false);
AnimationDrawable.addMiddleReversed(tempSpritesLeft, false);
AnimationDrawable.addMiddleReversed(tempSpritesRight, false);
animations.put(Type.WALK_DOWN, new Animation(1f / (frames * 1.5f), tempSpritesDown));
animations.put(Type.WALK_UP, new Animation(1f / (frames * 1.5f), tempSpritesUp));
animations.put(Type.WALK_LEFT, new Animation(1f / (frames * 1.5f), tempSpritesLeft));
animations.put(Type.WALK_RIGHT, new Animation(1f / (frames * 1.5f), tempSpritesRight));
for(Animation animation : animations.values()) {
animation.setPlayMode(Animation.PlayMode.LOOP);
}
setAnimationByType(Type.WALK_DOWN); // default animation
}
RiderBullet.java 文件源码
项目:cgc-game
阅读 23
收藏 0
点赞 0
评论 0
public RiderBullet(Animation newLowAnimation, Animation newMidAnimation,
Animation newHighAnimation, EntityType pEntityType,
Body attachedBody, Vector2 target, Vector2 targetOffset, boolean deathBullet) {
super(newLowAnimation, newMidAnimation, newHighAnimation, pEntityType,
attachedBody, target, targetOffset);
kill = deathBullet;
if (kill)
{
Flight_Speed = 1.0f;
}
else
{
Flight_Speed = 2.0f;
}
}
ActionInterval.java 文件源码
项目:cocos2d-java
阅读 15
收藏 0
点赞 0
评论 0
/** Creates the action with an Animation and will restore the original frame when the animation is over.
*
* @param animation A certain animation.
* @param modifier true : reset sprite size to frame; false:use sprite size
* @return An autoreleased Animate object.
*/
public static Animate create(Animation animation, boolean modifierSprite) {
Animate ret = new Animate();
if(ret.initWithAnimation(animation, modifierSprite)) {
return ret;
}
return null;
}
ActionInterval.java 文件源码
项目:cocos2d-java
阅读 20
收藏 0
点赞 0
评论 0
public Animate reverse() {
final TextureRegion[] srcRegions = _animation.getKeyFrames();
final int n = srcRegions.length;
TextureRegion[] newRegions = new TextureRegion[n];
for(int i = 0; i < n; ++i) {
newRegions[i] = srcRegions[n - 1 - i];
}
Animation newAnimation = new Animation(_animation.getFrameDuration(), newRegions);
newAnimation.setPlayMode(_animation.getPlayMode());
return Animate.create(newAnimation);
}
ActionInterval.java 文件源码
项目:cocos2d-java
阅读 21
收藏 0
点赞 0
评论 0
/** initializes the action with an Animation and will restore the original frame when the animation is over */
public boolean initWithAnimation(Animation animation, boolean modifierSprite) {
if (animation == null) {
CCLog.error("Animate", "Animate::initWithAnimation: argument Animation must be non-nullptr");
return false;
}
if(super.initWithDuration(animation.getAnimationDuration())) {
_currFrameIndex = 0;
_modifierSprite = modifierSprite;
_animation = animation;
return true;
}
return false;
}
FiniteActionTests.java 文件源码
项目:cocos2d-java
阅读 17
收藏 0
点赞 0
评论 0
public void onEnter() {
super.onEnter();
Texture t = CC.LoadImage("walkanim.png");
TextureRegion[] ts = t.splitRowCol(1, 4); //
for(int i = 0; i < 4; ++i) {
Sprite.createWithSpriteFrame(ts[i]).addTo(this).setPosition(100 + 100 * i, 200);
}
Animation animation = new Animation(3/30f, ts);
Sprite spriteAnimation = (Sprite) Sprite.create().addTo(this);
//修正sprite大小等动画 size设置无效
spriteAnimation.runAction(RepeatForever.create(
Animate.create(animation, true)));
spriteAnimation.setContentSize(100, 100);
spriteAnimation.setPosition(600, 320);
//不修正sprite大小的动画
Sprite spriteAnimation2 = (Sprite) Sprite.create().addTo(this);
spriteAnimation2.runAction(RepeatForever.create(
Animate.create(animation)));
spriteAnimation2.setContentSize(100, 100);
spriteAnimation2.setPosition(800, 320);
}