Package view
Class EntityView
java.lang.Object
view.EntityView
- All Implemented Interfaces:
Configuration
- Direct Known Subclasses:
SceneryView,SpriteView,TextView
The EntityView represents the un-scaled appearance of the entity on screen.
The view is resized by the scaling factor before it is drawn.
Collision bounds will track the rectangle that bounds the view.
The default collision bounds is the same that of the dimensions of the view.
Collision bounds can be changed to suit the dynamics of the game without affecting the
size of the view.
The view contains the transformational and representational state of the entity.
The draw method when invoked by the ModelEntity, will render
the current representation of the entity on the supplied graphics context at the coordinates specified.
This class, like all of the Java 2D API,
uses a default coordinate system called user space
in which the y-axis values increase downward and x-axis values increase to the right.
- Author:
- Krish Pillai
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface common.Configuration
Configuration.Direction -
Field Summary
Fields inherited from interface common.Configuration
AUDIO_DIR, DEFAULT_FRAME_RATE, DRAWABLE_DIR, GAMELOGGER, setViewCallChain -
Constructor Summary
ConstructorsConstructorDescriptionEntityView contains scale information and provides a mechanism for adding screen location information to the image to be rendered It takes the image form the concrete class and the location information from the model to draw the view on screen. -
Method Summary
Modifier and TypeMethodDescriptionvoiddraw(Graphics2D gc, int x, int y) Renders the concrete view for this entity.voiddrawBounds(Rectangle r, Color c, Graphics2D gc) Renders a hit-box around the text view.booleanReturns the state of the view iteratorReturns the dimensions of of the rendered text.abstract intThe height of the scaled visual representation for this entity.floatGetter for horizontal scalingfloatReturns the scale factor along the y axisabstract intgetWidth()The width of the scaled visual representation for this entity.booleanReturns the state of the wrapped view setting.voidsetAnimation(boolean active) Enables/disables the rolling of frames for the sprite or scenery.voidsetScaleFactor(float scaleX, float scaleY) Sets the x and y scale factorsvoidsetWrappedView(boolean wrap) Sets the entity to wrapped mode when argument is true.
-
Constructor Details
-
EntityView
public EntityView()EntityView contains scale information and provides a mechanism for adding screen location information to the image to be rendered It takes the image form the concrete class and the location information from the model to draw the view on screen.
-
-
Method Details
-
draw
Renders the concrete view for this entity. If an affine transform is defined for this view, it is applied. Rendering is done for the graphics context supplied. View that are unbounded will wrap around the drawing canvas if the entity is set as unbounded.- Parameters:
gc- Graphics context (2D)x- Entity body-center x coordinatey- Entity body-center y coordinate- See Also:
-
getScaleX
public float getScaleX()Getter for horizontal scaling- Returns:
- scale The scale factor along the x axis
-
getScaleY
public float getScaleY()Returns the scale factor along the y axis- Returns:
- scale The vertical scale factor
-
setScaleFactor
public void setScaleFactor(float scaleX, float scaleY) Sets the x and y scale factors- Parameters:
scaleX- Scale factor along x axisscaleY- Scale factor along y axis
-
setAnimation
public void setAnimation(boolean active) Enables/disables the rolling of frames for the sprite or scenery. Iterator does not advance frames if made inactive.- Parameters:
active- True is the iterator returns a new image for each frame
-
getAnimation
public boolean getAnimation()Returns the state of the view iterator- Returns:
- true or false
-
isWrappedView
public boolean isWrappedView()Returns the state of the wrapped view setting. In wrapped mode, the entity will wrap around screen edges. Wrapped entities leaving the North edge will enter through the South and vice versa. Similarly, the East and West boundaries are also conjoined.- Returns:
- state True if entity is in wrapped mode
-
setWrappedView
public void setWrappedView(boolean wrap) Sets the entity to wrapped mode when argument is true.- Parameters:
wrap- True if entity is in wrapped mode
-
getDimension
Returns the dimensions of of the rendered text.- Returns:
- dim Contains the width and height of the current rendering
-
drawBounds
Renders a hit-box around the text view. The rectangle is specified by 'r' using the color 'c'- Parameters:
r- The hit-boxc- The colorgc- The graphics context to use
-
getWidth
public abstract int getWidth()The width of the scaled visual representation for this entity.- Returns:
- width
-
getHeight
public abstract int getHeight()The height of the scaled visual representation for this entity.- Returns:
- height
-