Back to project page ssniper-andengine.
The source code is released under:
Apache License
If you think the Android project ssniper-andengine listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.cladophora.ssniper.entity; /* w w w .j ava 2s . co m*/ import com.cladophora.ssniper.BaseActivity; import com.cladophora.ssniper.HUDManager; import com.cladophora.ssniper.SpriteManager; import com.cladophora.ssniper.scene.GameScene; import org.andengine.entity.modifier.LoopEntityModifier; import org.andengine.entity.modifier.RotationModifier; import org.andengine.entity.primitive.Rectangle; import org.andengine.entity.sprite.Sprite; import org.andengine.opengl.vbo.VertexBufferObjectManager; import org.andengine.util.color.Color; /** * Created by jmar on 12/29/13. */ public class Reticle { public static Rectangle center; public static Reticle instance; public static Rectangle top; public static Rectangle right; public static Rectangle bottom; public static Rectangle left; public static Sprite reloadIndicator; public final static float RETICLE_RADIUS = 24; public final static float RETICLE_CENTERSIZE = 1; public final static float RETICLE_INNERRADIUS = 8; public final static float reloadIconRotationSpeed = 2; private final static RotationModifier iconRotator = new RotationModifier(reloadIconRotationSpeed, 0, 360); private final static LoopEntityModifier loopRotation = new LoopEntityModifier(iconRotator); private Reticle() { init(); } public static Reticle getSharedInstance() { if (instance == null) { instance = new Reticle(); //Log.d("com.cladophora.ssniper.Reticle.getSharedInstance()", String.valueOf(instance.hashCode())); } return instance; } public static void setColor(Color color) { center.setColor(color); top.setColor(color); right.setColor(color); bottom.setColor(color); left.setColor(color); } public static void hide() { center.setVisible(false); } public static void show() { center.setVisible(true); } public static void setVisible(boolean visibility) { if (top == null || right == null || bottom == null || left == null) { init(); } if (visibility) { center.setVisible(true); } top.setVisible(visibility); right.setVisible(visibility); bottom.setVisible(visibility); left.setVisible(visibility); } public static void init() { createReticleEntities(); attachReticleChildren(); setColor(Color.RED); setVisible(true); Reticle.center.setZIndex(BaseActivity.CAMERA_HEIGHT * 2); } private static void attachReticleChildren() { top.detachSelf(); right.detachSelf(); bottom.detachSelf(); left.detachSelf(); center.attachChild(top); center.attachChild(right); center.attachChild(bottom); center.attachChild(left); top.setPosition(0, -(RETICLE_INNERRADIUS + RETICLE_RADIUS)); right.setPosition(RETICLE_INNERRADIUS, 0); bottom.setPosition(0, RETICLE_INNERRADIUS); left.setPosition(-(RETICLE_INNERRADIUS + RETICLE_RADIUS), 0); } private static void createReticleEntities() { final VertexBufferObjectManager vbom = BaseActivity.getSharedInstance().getVertexBufferObjectManager(); center = new Rectangle(0, 0, RETICLE_CENTERSIZE, RETICLE_CENTERSIZE, vbom); top = new Rectangle(0, 0, RETICLE_CENTERSIZE, RETICLE_RADIUS, vbom); right = new Rectangle(0, 0, RETICLE_RADIUS, RETICLE_CENTERSIZE, vbom); bottom = new Rectangle(0, 0, RETICLE_CENTERSIZE, RETICLE_RADIUS, vbom); left = new Rectangle(0, 0, RETICLE_RADIUS, RETICLE_CENTERSIZE, vbom); } private static void initializeReloadIndicator() { reloadIndicator = new Sprite(0, 0, SpriteManager.mReloadIconTR, BaseActivity.getSharedInstance().getVertexBufferObjectManager()); if (center == null) { init(); } reloadIndicator.detachSelf(); center.attachChild(reloadIndicator); reloadIndicator.setPosition(-(reloadIndicator.getWidth()/2),-(reloadIndicator.getWidth()/2)); reloadIndicator.registerEntityModifier(loopRotation); } public void aim(float x, float y) { if (!GameScene.userControl) { return; } center.setPosition(x, y); } public static void showReloadIndicator() { initializeReloadIndicator(); HUDManager.slowTimeBar.setVisible(false); reloadIndicator.setVisible(true); setVisible(false); } public static void hideReloadIndicator() { setVisible(true); HUDManager.slowTimeBar.setVisible(true); if (reloadIndicator != null) { BaseActivity.getSharedInstance().getEngine().runOnUpdateThread( new Runnable() { @Override public void run() { reloadIndicator.detachSelf(); } } ); } } }