/**
* Provides an interface for tapping a GameObject on the screen. Tapping the
* object will register a "true" value on the provided channel.
*/
public class TappableComponent extends GameComponent
{
private ChannelSystem.Channel mChannel;
private ChannelSystem.ChannelBooleanValue mChannelValue;
public TappableComponent()
{
super();
this.setPhase(ComponentPhases.THINK.ordinal());
this.mChannelValue = new ChannelSystem.ChannelBooleanValue();
}
@Override
public void reset()
{
this.mChannel = null;
this.mChannelValue.value = false;
}
@Override
public void update(float timeDelta, BaseObject parent)
{
InputSystem inputSystem = sSystemRegistry.inputSystem;
final CameraSystem camera = sSystemRegistry.cameraSystem;
ContextParameters context = sSystemRegistry.contextParameters;
float cameraOriginX = 0.0f;
float cameraOriginY = 0.0f;
if (camera != null)
{
camera.getFocusPositionX();
cameraOriginX = camera.getFocusPositionX() - (context.gameWidth / 2.0f);
cameraOriginY = camera.getFocusPositionY() - (context.gameHeight / 2.0f);
}
final InputTouchScreen inputTouchScreen = inputSystem.getTouchScreen();
GameObject parentObject = (GameObject) parent;
float parentCameraXOffset = parentObject.getPosition().x - cameraOriginX;
float parentCameraYOffset = parentObject.getPosition().y - cameraOriginY;
final InputXY inputXY = inputTouchScreen.findPointerInRegion(parentCameraXOffset, parentCameraYOffset, parentObject.width, parentObject.height);
if (inputXY != null)
{
this.mChannelValue.value = true;
}
else
{
this.mChannelValue.value = false;
}
if (this.mChannel != null)
{
this.mChannel.value = mChannelValue;
}
}
public void setChannel(ChannelSystem.Channel channel)
{
this.mChannel = channel;
}
}
--
You received this message because you are subscribed to the Google Groups "ReplicaIsland Coding Community" group.
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To unsubscribe from this group and stop receiving emails from it, send an email to replica-island-coding-community+unsubscribe@googlegroups.com.