本文整理汇总了Java中org.andengine.entity.sprite.Sprite.setX方法的典型用法代码示例。如果您正苦于以下问题:Java Sprite.setX方法的具体用法?Java Sprite.setX怎么用?Java Sprite.setX使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.andengine.entity.sprite.Sprite
的用法示例。
在下文中一共展示了Sprite.setX方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateDiamond
import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
/**
* Generate a diamond centered on the desired position.
* @param x the x position
* @param y the y position
* @return The entity corresponding to the created diamond.
*/
public Entity generateDiamond(float x, float y, float frequency) {
Sprite sDiamond = new Sprite(x , y, this.spriteLoader.getDiamondTextureRegion(), this.vertextBufferObjectManager);
sDiamond.setX(sDiamond.getX() - sDiamond.getWidth()/2);
sDiamond.setY(sDiamond.getY() - sDiamond.getHeight()/2);
Entity diamond = this.em.createEntity();
this.em.addComponentToEntity(new SpriteComponent(sDiamond, true), diamond);
Rectangle currLifeRect = new Rectangle(26, 242, 370, 80, this.vertextBufferObjectManager);
currLifeRect.setColor(0.8f, 0.2f, 0.2f);
Rectangle maxLifeRect = new Rectangle(26, 242, 370, 80, this.vertextBufferObjectManager);
maxLifeRect.setColor(0.79f, 0.79f, 0.79f);
this.em.addComponentToEntity(new DiamondComponent(frequency, 20, currLifeRect, maxLifeRect), diamond);
return diamond;
}
示例2: doInBackground
import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
@Override
protected Sprite doInBackground(final String... params) {
try {
ITexture mTexture = new BitmapTexture(engine.getTextureManager(), new IInputStreamOpener() {
@Override
public InputStream open() throws IOException {
URL url = new URL(params[0]);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setDoInput(true);
connection.connect();
InputStream input = connection.getInputStream();
return new BufferedInputStream(input);
}
});
mTexture.load();
textureRegionAnotherPlayer = TextureRegionFactory.extractFromTexture(mTexture);
if (GameManager.getInstance() != null && GameManager.getInstance().players != null &&
GameManager.getInstance().players.length > 0 && engine != null) {
IEntity entity = GameManager.getInstance().players[1].tabSprite;
Sprite user = new Sprite(0, 0, textureRegionAnotherPlayer, engine.getVertexBufferObjectManager());
user.setWidth(entity.getHeight() - 27);
user.setHeight(entity.getHeight() - 27);
user.setX(-13 + entity.getWidth() / 2);
user.setY(+4 + entity.getHeight() / 2);
return user;
}
} catch (IOException e) {
Debug.e(e);
}
return null;
}
示例3: centerSprite
import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
public static void centerSprite(Sprite sprite) {
sprite.setX((CAMERA_WIDTH / 2) - (sprite.getWidth() / 2));
sprite.setY((CAMERA_HEIGHT / 2) - (sprite.getHeight() / 2));
}
示例4: rightAlignSprite
import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
public static void rightAlignSprite( Sprite sprite){
sprite.setX(((CAMERA_WIDTH)*3)/5 - (sprite.getWidth() /2 ));
sprite.setY((CAMERA_HEIGHT / 2) - (sprite.getHeight() / 2));
}
示例5: placeCenter
import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
public void placeCenter(final Sprite pSprite, final Camera pCamera) {
pSprite.setX(pCamera.getWidth() / 2 - pSprite.getWidth() / 2);
}
示例6: generateSentry
import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
/**
* Generate a sentry at the middle of the screen.
* @param rotation the start rotation of the sentry
* @return The entity corresponding to the created sentry.
*/
public Entity generateSentry(int rotation) {
// Sprite compo
TiledTextureRegion sentryTexture = spriteLoader.getSentryTextureRegion();
final AnimatedSprite sSentry = new AnimatedSprite(gameArea.getWidth()/2 - sentryTexture.getWidth()/2, gameArea.getHeight()/2 - sentryTexture.getHeight()/2,
sentryTexture, this.vertextBufferObjectManager);
sSentry.setZIndex(11);
sSentry.setRotation(rotation);
sSentry.stopAnimation(0);
Entity sentry = this.em.createEntity();
SpriteComponent spriteComponent = new SpriteComponent(sSentry, true).defineRectangularHitbox(108, 10, 55, 70);
this.em.addComponentToEntity(spriteComponent, sentry);
this.em.addComponentToEntity(new SelfRotationComponent(3, 0.8f, 0.2f, rotation, true, true), sentry);
//Primary fire compo
Sprite primaryFireIcon = new Sprite(0, 0, spriteLoader.getFireIconPrimaryStandardTextureRegion(), this.vertextBufferObjectManager);
this.em.addComponentToEntity(new PrimaryShootingComponent(primaryFireIcon, ProjectileType.STANDARD, 0.5f,
SpriteAnimationEnum.SENTRY_STANDARD_SHOOT.getFrames(),
SpriteAnimationEnum.SENTRY_STANDARD_SHOOT.getFrameDurations()), sentry);
// //Secondary fire compo
// //Secondary shooting test :
// Sprite secondaryFireIcon = new Sprite(0, 0, spriteLoader.getFireIconSecondaryPiercingTextureRegion(), this.vertextBufferObjectManager);
// Text ammoText = new Text(0, 0, spriteLoader.getSecondaryAmmoFont(), "999", new TextOptions(HorizontalAlign.RIGHT), this.vertextBufferObjectManager);
// this.em.addComponentToEntity(new SecondaryShootingComponent(secondaryFireIcon, 50, ammoText, ProjectileType.PIERCING, 0.1f,
// SpriteAnimationEnum.SENTRY_STANDARD_SHOOT.getFrames(),
// SpriteAnimationEnum.SENTRY_STANDARD_SHOOT.getFrameDurations()), sentry);
//Secondary mine test :
Sprite secondaryMineIcon = new Sprite(0, 0, spriteLoader.getFireIconSecondaryMineTextureRegion(), this.vertextBufferObjectManager);
Sprite targetSprite = new Sprite(0, 0, spriteLoader.getTargetTextureRegion(), this.vertextBufferObjectManager);
Text ammoText = new Text(0, 0, spriteLoader.getSecondaryAmmoFont(), "999", new TextOptions(HorizontalAlign.RIGHT), this.vertextBufferObjectManager);
this.em.addComponentToEntity(new SecondaryMineComponent(secondaryMineIcon, 10, ammoText, targetSprite), sentry);
//AOE attack compo
Rectangle hitbox = (Rectangle)spriteComponent.getHitbox();
final AnimatedSprite sElectricAttack = new AnimatedSprite(0, 0, this.spriteLoader.getSentryElectricAttackTextureRegion(), this.vertextBufferObjectManager);
sElectricAttack.setX(hitbox.getX() + hitbox.getWidth()/2 - sElectricAttack.getWidth()/2);
sElectricAttack.setY(hitbox.getY() + hitbox.getHeight()/2 - sElectricAttack.getHeight()/2);
sElectricAttack.setVisible(false);
sSentry.attachChild(sElectricAttack);
final Sprite sElectricAttackIcon = new Sprite(0, 0, this.spriteLoader.getSkillElectricityTextureRegion(), this.vertextBufferObjectManager);
final Sprite sElectricAttackIconFrame = new Sprite(0, 0, this.spriteLoader.getSkillFrameTextureRegion(), this.vertextBufferObjectManager);
//Temp : placing the icon on the top right of the HUD
sElectricAttackIconFrame.setX(1508);
sElectricAttackIconFrame.setY(10);
sElectricAttackIcon.setX(1508);
sElectricAttackIcon.setY(10);
this.em.addComponentToEntity(new AOEAttackComponent(sElectricAttack, sElectricAttackIcon, sElectricAttackIconFrame, hitbox, 5, 2, this.vertextBufferObjectManager), sentry);
//Detectable compo
this.em.addComponentToEntity(new DetectableComponent(), sentry);
return sentry;
}