当前位置: 首页>>代码示例>>Java>>正文


Java Sprite.setRotation方法代码示例

本文整理汇总了Java中org.andengine.entity.sprite.Sprite.setRotation方法的典型用法代码示例。如果您正苦于以下问题:Java Sprite.setRotation方法的具体用法?Java Sprite.setRotation怎么用?Java Sprite.setRotation使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.andengine.entity.sprite.Sprite的用法示例。


在下文中一共展示了Sprite.setRotation方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: generateWall

import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
/**
 * Generate a wall at the desired position.
 * @param x the x position
 * @param y the y position
 * @param rotation the rotation of the sprite
 * @return The entity corresponding to the created wall.
 */
public Entity generateWall(float x, float y, float rotation) {
	final Sprite sWall = new Sprite(x, y , this.spriteLoader.getWallRegion(), this.vertextBufferObjectManager);
	sWall.setRotation(rotation);
	Entity wall = this.em.createEntity();
	this.em.addComponentToEntity(new SpriteComponent(sWall, true), wall);
	this.em.addComponentToEntity(new SolidComponent(), wall);

	return wall;
}
 
开发者ID:Callilf,项目名称:RotatingSentries,代码行数:17,代码来源:EntityFactory.java

示例2: generateEnemyShuriken

import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
/**
 * Generate a shuriken sent by an enemy.
 * @param enemySprite
 * @return
 */
public Entity generateEnemyShuriken(Sprite enemySprite) {
	float rotationDegre = enemySprite.getRotation();
	//Handle the fact the enemy sprites are oriented facing south.
	rotationDegre = (rotationDegre + 180)%360;
	double rotationRad = rotationDegre * Math.PI / 180d;
	float startX = (float) Math.sin(rotationRad);
	float startY = (float) Math.cos(rotationRad) * -1;
	
	TextureRegion shurikenProjectileTexture = spriteLoader.getProjShurikenTextureRegion();
	Couple<Float> enemyCenter = SpriteUtil.getCenter(enemySprite);
	final Sprite sShurikenProjectile = new Sprite(enemyCenter.getX() - shurikenProjectileTexture.getWidth() / 2f, 
			enemyCenter.getY() - shurikenProjectileTexture.getHeight() / 2f,
			shurikenProjectileTexture, this.vertextBufferObjectManager);
	sShurikenProjectile.setZIndex(13);
	sShurikenProjectile.setRotation(rotationDegre);
	Entity shurikenProjectile = this.em.createEntity();
	SpriteComponent scShurikenProj = new SpriteComponent(sShurikenProjectile, true);
	scShurikenProj.defineRectangularHitboxDiff(15, 5, 15, 20);
	this.em.addComponentToEntity(scShurikenProj, shurikenProjectile);
	this.em.addComponentToEntity(new SelfRotationComponent(15), shurikenProjectile);
	this.em.addComponentToEntity(new MoveTowardsComponent(10, startX, startY), shurikenProjectile);
	this.em.addComponentToEntity(new AttackComponent(1, 2), shurikenProjectile);
	gameArea.attachChild(sShurikenProjectile);
	scShurikenProj.setAttached(true);
	return shurikenProjectile;
}
 
开发者ID:Callilf,项目名称:RotatingSentries,代码行数:32,代码来源:EntityFactory.java

示例3: setOrientation

import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
/**
 * Make the sprite look in the direction of the dest. 
 * @param sprite the sprite
 * @param dest the destination
 */
public static void setOrientation(Sprite sprite, Sprite dest) {
	Couple<Float> directionalVector = MathUtil.computeDirectionalVector(getCenter(sprite), getCenter(dest));
	if (directionalVector.getX() != 0 && directionalVector.getY() != 0) {
		float angle = MathUtil.computeOrientationAngleFromDirectionalVector(directionalVector);
		sprite.setRotation(angle);
	}
}
 
开发者ID:Callilf,项目名称:RotatingSentries,代码行数:13,代码来源:SpriteUtil.java

示例4: generateProjectile

import org.andengine.entity.sprite.Sprite; //导入方法依赖的package包/类
/**
 * Generate a projectile
 * @param projectileType the type of projectile
 * @param sentry the sprite of the sentry which generate the projectile
 */
public Entity generateProjectile(ProjectileType projectileType, Sprite sentry) {
	float rotationDegre = sentry.getRotation();
	double rotationRad = rotationDegre * Math.PI / 180d;
	float rayonSentry = sentry.getWidth() / 2;
	float startX = (float) Math.sin(rotationRad);
	float startY = (float) Math.cos(rotationRad) * -1;
	
	switch (projectileType) {
	case STANDARD:
		TextureRegion standardTexture = spriteLoader.getProjStdTextureRegion();
		final Sprite sStandardProjectile = new Sprite(gameArea.getWidth()/2 + startX * rayonSentry - standardTexture.getWidth()/2f, 
				gameArea.getHeight()/2 + startY * rayonSentry - standardTexture.getHeight()/2f, standardTexture, this.vertextBufferObjectManager);
		sStandardProjectile.setZIndex(13);
		Entity standardProjectile = this.em.createEntity();
		SpriteComponent scStdProj = new SpriteComponent(sStandardProjectile, true);
		this.em.addComponentToEntity(scStdProj, standardProjectile);
		this.em.addComponentToEntity(new MoveTowardsComponent(15, startX, startY), standardProjectile);
		this.em.addComponentToEntity(new DefenseComponent(1, 1, false), standardProjectile);
		gameArea.attachChild(sStandardProjectile);
		scStdProj.setAttached(true);
		return standardProjectile;
	case PIERCING:
		TextureRegion piercingProjectileTexture = spriteLoader.getProjPiercingTextureRegion();
		final Sprite sPiercingProjectile = new Sprite(gameArea.getWidth()/2 + startX * rayonSentry - piercingProjectileTexture.getWidth()/2f, 
				gameArea.getHeight()/2 + startY * rayonSentry - piercingProjectileTexture.getHeight()/2f, piercingProjectileTexture, this.vertextBufferObjectManager);
		sPiercingProjectile.setZIndex(13);
		sPiercingProjectile.setRotation(rotationDegre);
		Entity piercingProjectile = this.em.createEntity();
		SpriteComponent scPiercingProj = new SpriteComponent(sPiercingProjectile, true);
		this.em.addComponentToEntity(scPiercingProj, piercingProjectile);
		this.em.addComponentToEntity(new MoveTowardsComponent(25, startX, startY), piercingProjectile);
		this.em.addComponentToEntity(new DefenseComponent(5, 2, false), piercingProjectile);
		gameArea.attachChild(sPiercingProjectile);
		scPiercingProj.setAttached(true);
		return piercingProjectile;
	case SHURIKEN:
		TextureRegion shurikenProjectileTexture = spriteLoader.getProjShurikenTextureRegion();
		final Sprite sShurikenProjectile = new Sprite(gameArea.getWidth()/2 + startX * rayonSentry - shurikenProjectileTexture.getWidth()/2f, 
				gameArea.getHeight()/2 + startY * rayonSentry - shurikenProjectileTexture.getHeight()/2f, shurikenProjectileTexture, this.vertextBufferObjectManager);
		sShurikenProjectile.setZIndex(13);
		sShurikenProjectile.setRotation(rotationDegre);
		Entity shurikenProjectile = this.em.createEntity();
		SpriteComponent scShurikenProj = new SpriteComponent(sShurikenProjectile, true);
		this.em.addComponentToEntity(scShurikenProj, shurikenProjectile);
		this.em.addComponentToEntity(new SelfRotationComponent(10), shurikenProjectile);
		this.em.addComponentToEntity(new MoveTowardsComponent(10, startX, startY), shurikenProjectile);
		this.em.addComponentToEntity(new DefenseComponent(7, 2, false), shurikenProjectile);
		gameArea.attachChild(sShurikenProjectile);
		scShurikenProj.setAttached(true);
		return shurikenProjectile;
	default:
		throw new IllegalArgumentException("Undefined projectile " + projectileType);
	}
}
 
开发者ID:Callilf,项目名称:RotatingSentries,代码行数:60,代码来源:EntityFactory.java


注:本文中的org.andengine.entity.sprite.Sprite.setRotation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。