Package arc.scene

Class Element

java.lang.Object
arc.scene.Element
Direct Known Subclasses:
Bar, GridImage, Group, Image, Label, LCanvas.JumpCurve, MapView, ProgressBar, TextField, Touchpad, WarningBar

public class Element extends Object
  • Field Details

    • color

      public final Color color
    • originX

      public float originX
    • originY

      public float originY
    • scaleX

      public float scaleX
    • scaleY

      public float scaleY
    • rotation

      public float rotation
    • name

      public String name
    • fillParent

      public boolean fillParent
    • translation

      public Vec2 translation
    • visible

      public boolean visible
    • userObject

      public Object userObject
    • touchable

      public Touchable touchable
    • parent

      public Group parent
    • visibility

      public Boolp visibility
    • touchablility

      public Prov<Touchable> touchablility
    • cullable

      public boolean cullable
    • x

      public float x
    • y

      public float y
    • width

      protected float width
      DO NOT modify without calling sizeChanged.
    • height

      protected float height
      DO NOT modify without calling sizeChanged.
    • parentAlpha

      protected float parentAlpha
      Alpha value of the parent. Should be multiplied with the actor's alpha, allowing a parent's alpha to affect all children.
  • Constructor Details

    • Element

      public Element()
  • Method Details

    • draw

      public void draw()
      Draws the element. Does nothing by default.
    • act

      public void act(float delta)
      Updates the actor based on time. Typically this is called each frame by Scene.act(float).

      The default implementation calls Action.act(float) on each action and removes actions that are complete.

      Parameters:
      delta - Time in seconds since the last frame.
    • updateVisibility

      public void updateVisibility()
    • hasMouse

      public boolean hasMouse()
    • hasKeyboard

      public boolean hasKeyboard()
    • hasScroll

      public boolean hasScroll()
    • requestKeyboard

      public void requestKeyboard()
    • requestScroll

      public void requestScroll()
    • fire

      public boolean fire(SceneEvent event)
    • notify

      public boolean notify(SceneEvent event, boolean capture)
    • hit

      public Element hit(float x, float y, boolean touchable)
      Returns the deepest actor that contains the specified point and is touchable and visible, or null if no actor was hit. The point is specified in the actor's local coordinate system (0,0 is the bottom left of the actor and width,height is the upper right).

      This method is used to delegate touchDown, mouse, and enter/exit events. If this method returns null, those events will not occur on this Actor.

      The default implementation returns this actor if the point is within this actor's bounds.

      Parameters:
      touchable - If true, the hit detection will respect the touchability.
      See Also:
    • remove

      public boolean remove()
      Removes this actor from its parent, if it has a parent.
      See Also:
    • dragged

      public void dragged(Floatc2 cons)
      Adds a listener which listens for drag (touch down and move) events. Results are returned in positive deltas.
    • scrolled

      public void scrolled(Floatc cons)
    • addListener

      public boolean addListener(EventListener listener)
      Add a listener to receive events that hit this actor. See fire(SceneEvent).
      See Also:
    • removeListener

      public boolean removeListener(EventListener listener)
    • getListeners

      public Seq<EventListener> getListeners()
    • addCaptureListener

      public boolean addCaptureListener(EventListener listener)
      Adds a listener that is only notified during the capture phase.
      See Also:
    • removeCaptureListener

      public boolean removeCaptureListener(EventListener listener)
    • getCaptureListeners

      public Seq<EventListener> getCaptureListeners()
    • addAction

      public void addAction(Action action)
    • actions

      public void actions(Action... actions)
    • removeAction

      public void removeAction(Action action)
    • getActions

      public Seq<Action> getActions()
    • hasActions

      public boolean hasActions()
      Returns true if the actor has one or more actions.
    • clearActions

      public void clearActions()
      Removes all actions on this actor.
    • clearListeners

      public void clearListeners()
      Removes all listeners on this actor.
    • clear

      public void clear()
      Removes all actions and listeners on this actor.
    • getScene

      public Scene getScene()
      Returns the stage that this actor is currently in, or null if not in a stage.
    • setScene

      protected void setScene(Scene stage)
      Called by the framework when this actor or any parent is added to a group that is in the stage.
      Parameters:
      stage - May be null if the actor or any parent is no longer in a stage.
    • isDescendantOf

      public boolean isDescendantOf(Boolf<Element> actor)
    • isDescendantOf

      public boolean isDescendantOf(Element actor)
      Returns true if this actor is the same as or is the descendant of the specified actor.
    • isAscendantOf

      public boolean isAscendantOf(Element actor)
      Returns true if this actor is the same as or is the ascendant of the specified actor.
    • hasParent

      public boolean hasParent()
      Returns true if the actor's parent is not null.
    • isTouchable

      public boolean isTouchable()
      Returns true if input events are processed by this actor.
    • getX

      public float getX(int alignment)
      Returns the X position of the specified alignment.
    • getY

      public float getY(int alignment)
      Returns the Y position of the specified alignment.
    • setPosition

      public void setPosition(float x, float y)
      Sets the position of the actor's bottom left corner.
    • setPosition

      public void setPosition(float x, float y, int alignment)
      Sets the position using the specified alignment. Note this may set the position to non-integer coordinates.
    • moveBy

      public void moveBy(float x, float y)
      Add x and y to current position
    • getWidth

      public float getWidth()
    • setWidth

      public void setWidth(float width)
    • getHeight

      public float getHeight()
    • setHeight

      public void setHeight(float height)
    • getTop

      public float getTop()
      Returns y plus height.
    • getRight

      public float getRight()
      Returns x plus width.
    • sizeChanged

      protected void sizeChanged()
      Called when the actor's size has been changed.
    • rotationChanged

      protected void rotationChanged()
      Called when the actor's rotation has been changed.
    • setSize

      public void setSize(float size)
    • setSize

      public void setSize(float width, float height)
      Sets the width and height.
    • sizeBy

      public void sizeBy(float size)
      Adds the specified size to the current size.
    • sizeBy

      public void sizeBy(float width, float height)
      Adds the specified size to the current size.
    • setBounds

      public void setBounds(float x, float y, float width, float height)
      Set bounds the x, y, width, and height.
    • setOrigin

      public void setOrigin(float originX, float originY)
      Sets the origin position which is relative to the actor's bottom left corner.
    • setOrigin

      public void setOrigin(int alignment)
      Sets the origin position to the specified alignment.
    • setScale

      public void setScale(float scaleXY)
      Sets the scale for both X and Y
    • setScale

      public void setScale(float scaleX, float scaleY)
      Sets the scale X and scale Y.
    • scaleBy

      public void scaleBy(float scale)
      Adds the specified scale to the current scale.
    • scaleBy

      public void scaleBy(float scaleX, float scaleY)
      Adds the specified scale to the current scale.
    • getRotation

      public float getRotation()
    • setRotation

      public void setRotation(float degrees)
    • setRotationOrigin

      public void setRotationOrigin(float degrees, int align)
    • rotateBy

      public void rotateBy(float amountInDegrees)
      Adds the specified rotation to the current rotation.
    • setColor

      public void setColor(float r, float g, float b, float a)
    • setColor

      public void setColor(Color color)
    • toFront

      public void toFront()
      Changes the z-order for this actor so it is in front of all siblings.
    • toBack

      public void toBack()
      Changes the z-order for this actor so it is in back of all siblings.
    • getZIndex

      public int getZIndex()
      Returns the z-index of this actor.
      See Also:
    • setZIndex

      public void setZIndex(int index)
      Sets the z-index of this actor. The z-index is the index into the parent's children, where a lower index is below a higher index. Setting a z-index higher than the number of children will move the child to the front. Setting a z-index less than zero is invalid.
    • clipBegin

      public boolean clipBegin()
      Calls clipBegin(float, float, float, float) to clip this actor's bounds.
    • clipBegin

      public boolean clipBegin(float x, float y, float width, float height)
      Clips the specified screen aligned rectangle, specified relative to the transform matrix of the stage's Batch. The transform matrix and the stage's camera must not have rotational components. Calling this method must be followed by a call to clipEnd() if true is returned.
      Returns:
      false if the clipping area is zero and no drawing should occur.
      See Also:
    • clipEnd

      public void clipEnd()
    • screenToLocalCoordinates

      public Vec2 screenToLocalCoordinates(Vec2 screenCoords)
      Transforms the specified point in screen coordinates to the actor's local coordinate system.
    • stageToLocalCoordinates

      public Vec2 stageToLocalCoordinates(Vec2 stageCoords)
      Transforms the specified point in the stage's coordinates to the actor's local coordinate system.
    • localToStageCoordinates

      public Vec2 localToStageCoordinates(Vec2 localCoords)
      Transforms the specified point in the actor's coordinates to be in the stage's coordinates.
    • localToParentCoordinates

      public Vec2 localToParentCoordinates(Vec2 localCoords)
      Transforms the specified point in the actor's coordinates to be in the parent's coordinates.
    • localToAscendantCoordinates

      public Vec2 localToAscendantCoordinates(Element ascendant, Vec2 localCoords)
      Converts coordinates for this actor to those of a parent actor. The ascendant does not need to be a direct parent.
    • parentToLocalCoordinates

      public Vec2 parentToLocalCoordinates(Vec2 parentCoords)
      Converts the coordinates given in the parent's coordinate system to this actor's coordinate system.
    • getMinWidth

      public float getMinWidth()
    • getMinHeight

      public float getMinHeight()
    • getPrefWidth

      public float getPrefWidth()
    • getPrefHeight

      public float getPrefHeight()
    • getMaxWidth

      public float getMaxWidth()
    • getMaxHeight

      public float getMaxHeight()
    • setLayoutEnabled

      public void setLayoutEnabled(boolean enabled)
    • validate

      public void validate()
      Ensures the actor has been laid out. Calls layout() if invalidate() has been called since the last time validate() was called, or if the actor otherwise needs to be laid out. This method is usually called in draw() by the actor itself before drawing is performed.
    • needsLayout

      public boolean needsLayout()
      Returns true if the widget's layout has been invalidated.
    • invalidate

      public void invalidate()
      Invalidates this actor's layout, causing layout() to happen the next time validate() is called. This method should be called when state changes in the actor that requires a layout but does not change the minimum, preferred, maximum, or actual size of the actor (meaning it does not affect the parent actor's layout).
    • invalidateHierarchy

      public void invalidateHierarchy()
      Invalidates this actor and its ascendants, calling invalidate() on each. This method should be called when state changes in the actor that affects the minimum, preferred, maximum, or actual size of the actor (meaning it potentially affects the parent actor's layout).
    • pack

      public void pack()
      Sizes this actor to its preferred width and height, then calls validate().

      Generally this method should not be called in an actor's constructor because it calls layout(), which means a subclass would have layout() called before the subclass' constructor. Instead, in constructors simply set the actor's size to getPrefWidth() and getPrefHeight(). This allows the actor to have a size at construction time for more convenient use with groups that do not layout their children.

    • setFillParent

      public void setFillParent(boolean fillParent)
      If true, this actor will be sized to the parent in validate(). If the parent is the stage, the actor will be sized to the stage. This method is for convenience only when the widget's parent does not set the size of its children (such as the stage).
    • layout

      public void layout()
      Computes and caches any information needed for drawing and, if this actor has children, positions and sizes each child, calls invalidate() on any each child whose width or height has changed, and calls validate() on each child. This method should almost never be called directly, instead validate() should be used.
    • keepInStage

      public void keepInStage()
    • setTranslation

      public void setTranslation(float x, float y)
    • keyDown

      public void keyDown(KeyCode key, Runnable l)
    • keyDown

      public void keyDown(Cons<KeyCode> cons)
      Adds a keydown input listener.
    • fireClick

      public void fireClick()
      Fakes a click event on all ClickListeners.
    • clicked

      public ClickListener clicked(Runnable r)
      Adds a click listener.
    • clicked

      public ClickListener clicked(KeyCode button, Runnable r)
      Adds a click listener.
    • clicked

      public ClickListener clicked(Cons<ClickListener> tweaker, Runnable r)
      Adds a click listener.
    • clicked

      public ClickListener clicked(Cons<ClickListener> tweaker, Cons<ClickListener> runner)
    • tapped

      public InputListener tapped(Runnable r)
      Adds a touch listener.
    • hovered

      public void hovered(Runnable r)
      Adds a hover/mouse enter listener.
    • exited

      public void exited(Runnable r)
      Adds a hover/mouse exit listener.
    • released

      public void released(Runnable r)
      Adds a mouse up listener.
    • change

      public void change()
      Fires a change event on all listeners.
    • changed

      public void changed(Runnable r)
      Adds a click listener.
    • update

      public Element update(Runnable r)
    • visible

      public Element visible(Boolp vis)
    • touchable

      public void touchable(Prov<Touchable> touch)
    • toString

      public String toString()
      Overrides:
      toString in class Object