Package snap.games
Class GameView
java.lang.Object
snap.props.PropObject
snap.view.View
snap.view.ParentView
snap.view.ChildView
snap.games.GameView
- All Implemented Interfaces:
PropChange.DoChange
,XMLArchiver.Archivable
,ViewHost
- Direct Known Subclasses:
BoardGameView
This class is the main view for games and manages Actors.
-
Nested Class Summary
Nested classes/interfaces inherited from class snap.view.View
View.Overflow
-
Field Summary
FieldsFields inherited from class snap.view.ParentView
_children, Children_Prop, NeedsLayout_Prop
Fields inherited from class snap.view.View
_align, _border, _borderRadius, _effect, _fill, _font, _margin, _padding, _repaintRect, _showing, _spacing, _vertical, Action, Align_Prop, Border_Prop, BorderRadius_Prop, Cursor_Prop, Disabled_Prop, DragEvents, Effect_Prop, Fill_Prop, Focusable_Prop, Focused_Prop, FocusWhenPressed_Prop, Font_Prop, GrowHeight_Prop, GrowWidth_Prop, Height_Prop, KeyEvents, KeyPress, KeyRelease, KeyType, LeanX_Prop, LeanY_Prop, Managed_Prop, Margin_Prop, MaxHeight_Prop, MaxWidth_Prop, MinHeight_Prop, MinWidth_Prop, MouseDrag, MouseEnter, MouseEvents, MouseExit, MouseMove, MousePress, MouseRelease, Name_Prop, Opacity_Prop, Overflow_Prop, Padding_Prop, Paintable_Prop, Parent_Prop, Pickable_Prop, PrefHeight_Prop, PrefWidth_Prop, Rotate_Prop, RuntimeClassName_Prop, ScaleX_Prop, ScaleY_Prop, Scroll, Showing_Prop, Spacing_Prop, Text_Prop, TextColor_Prop, ToolTip_Prop, TransX_Prop, TransY_Prop, Vertical_Prop, Visible_Prop, Width_Prop, X_Prop, Y_Prop
Fields inherited from class snap.props.PropObject
_pcs, EMPTY_OBJECT
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addActorAtXY
(Actor anActor, double anX, double aY) Adds a new actor to game view at given XY point.void
Override to clear actors list.<T extends Actor>
TgetActorAtXY
(double aX, double aY, Class<T> aClass) Returns the first actor hit by given point in local coords.getActorForName
(String aName) Returns the actor with given name.Returns the actors.getActorsAtXY
(double aX, double aY, Class<T> aClass) Returns the actors hit by given point in local coords.Returns the actors reversed.Returns the game controller.getImage()
Returns the background image.int
Returns the mouse click count.double
Returns the mouse X.double
Returns the mouse Y.boolean
Returns whether to draw coordinate grid.protected boolean
isActorAtXY
(Actor anActor, double aX, double aY, Class<?> aClass) Returns whether given actor is at given XY and of matching class.boolean
isKeyClicked
(String aKey) Returns whether a given key was pressed in the current frame.boolean
Returns whether a given key is pressed.boolean
Returns whether the mouse was clicked on this frame.boolean
Returns whether the mouse button is down.boolean
Returns whether game is playing.protected void
paintFront
(Painter aPntr) Paints the game view.void
play()
Starts the game timer.protected void
processEvent
(ViewEvent anEvent) Process event.removeActor
(int anIndex) Removes an actor.int
removeActor
(Actor anActor) Removes an actor.removeChild
(int anIndex) Override to clear actors list.void
setFillColor
(String aString) Sets the game view fill color for given color string.void
Sets the background image.void
setImageForName
(String imageName) Sets the image for given name.void
setPlaying
(boolean aValue) Sets whether game is playing.void
setShowCoords
(boolean aValue) Sets whether to draw coordinate grid.protected void
Steps the game forward a frame.void
stop()
Stops the game timer.Methods inherited from class snap.view.ChildView
addChild, addGuest, getGuest, getGuestCount, removeChild, removeChildren, removeGuest, setChildren
Methods inherited from class snap.view.ParentView
addDeepChangeListener, childDidDeepChange, childDidPropChange, fromXML, fromXMLChildren, fromXMLView, getChild, getChildAtXY, getChildCount, getChildCountManaged, getChildForClass, getChildForName, getChildren, getChildrenArray, getChildrenForClass, getChildrenInPaintOrder, getChildrenManaged, getFocusNext, getFocusPrev, getLastChild, getPropValue, getViewProxy, indexOfChild, initProps, intersectsShape, isInLayout, isNeedsLayout, isNeedsLayoutDeep, isNeedsRepaintDeep, layout, layoutDeep, layoutDeepImpl, layoutFloatingViews, layoutImpl, paintAll, paintChildren, parentFontChanged, processPropChange, relayout, removeDeepChangeListener, setFont, setNeedsLayout, setNeedsLayoutDeep, setNeedsRepaintDeep, setOwner, setOwnerChildren, setPropValue, setShowing, themeChanged, toXML, toXMLChildren, toXMLView
Methods inherited from class snap.view.View
addEventFilter, addEventHandler, clone, contains, contains, containsShape, createActionEvent, disableEvents, enableEvents, fireActionEvent, getAlign, getAlignX, getAlignY, getAnim, getAnimCleared, getAnimTimeDeep, getBestHeight, getBestSize, getBestWidth, getBorder, getBorderRadius, getBounds, getBoundsLocal, getBoundsParent, getBoundsShape, getBoundsShapeParent, getClip, getClipAll, getClipBounds, getClipBoundsAll, getCursor, getDefaultFont, getEffect, getEnv, getEventAdapter, getFill, getFillColor, getFocusNext, getFocusPrev, getFont, getHeight, getHost, getInsetsAll, getLean, getLeanX, getLeanY, getLocalToParent, getLocalToParent, getMargin, getMaxHeight, getMaxSize, getMaxWidth, getMaxX, getMaxY, getMidX, getMidXY, getMidY, getMinHeight, getMinHeightImpl, getMinSize, getMinWidth, getMinWidthImpl, getName, getOpacity, getOpacityAll, getOverflow, getOwner, getOwner, getPadding, getParent, getParent, getParentCount, getParentToLocal, getParentToLocal, getPhysics, getPhysics, getPrefHeight, getPrefHeight, getPrefHeightImpl, getPrefSize, getPrefWidth, getPrefWidth, getPrefWidthImpl, getProp, getPropDefault, getProps, getRepaintRect, getRepaintRectExpanded, getRootView, getRotate, getRuntimeClassName, getScale, getScaleX, getScaleY, getSize, getSpacing, getText, getTextColor, getToolTip, getToolTip, getTransX, getTransY, getUpdater, getValuePropName, getVisibleBounds, getWidth, getWindow, getX, getXY, getY, indexInHost, indexInParent, initStyleProps, isActionable, isAncestor, isAnimActive, isClipToBounds, isDisabled, isEnabled, isFocusable, isFocused, isFocusKeysEnabled, isFocusPainted, isFocusWhenPressed, isFontSet, isGrowHeight, isGrowWidth, isGuest, isHorizontal, isLocalToParentSimple, isManaged, isManagedVisible, isMaxHeightSet, isMaxWidthSet, isMinHeightSet, isMinWidthSet, isMouseOver, isNeedsRepaint, isPaintable, isPickable, isPickableVisible, isPrefHeightSet, isPrefWidthSet, isPropDefault, isShowing, isToolTipEnabled, isVertical, isVisible, localToParent, localToParent, localToParent, localToParent, localToScreen, paintAbove, paintBack, parentToLocal, parentToLocal, parentToLocal, parentToLocal, playAnimDeep, processEventAll, processEventFilters, processEventHandlers, relayoutParent, removeEventFilter, removeEventHandler, repaint, repaint, repaint, repaintInParent, requestFocus, runDelayed, runIntervals, runLater, scrollToVisible, setActionable, setAlign, setAlignX, setAlignY, setAnimString, setAnimTimeDeep, setBorder, setBorder, setBorderRadius, setBounds, setBounds, setBoundsLocal, setClipToBounds, setCursor, setDisabled, setEffect, setEnabled, setFill, setFocusable, setFocused, setFocusKeysEnabled, setFocusPainted, setFocusWhenPressed, setGrowHeight, setGrowWidth, setHeight, setLean, setLeanX, setLeanY, setManaged, setMargin, setMargin, setMaxHeight, setMaxSize, setMaxSize, setMaxWidth, setMidXY, setMinHeight, setMinSize, setMinSize, setMinWidth, setName, setOpacity, setOverflow, setPadding, setPadding, setPaintable, setParent, setPickable, setPrefHeight, setPrefSize, setPrefSize, setPrefWidth, setProp, setRotate, setRuntimeClassName, setScale, setScaleX, setScaleY, setSize, setSize, setSizeLocal, setSizeToBestSize, setSizeToPrefSize, setSpacing, setText, setTextColor, setToolTip, setToolTipEnabled, setTransX, setTransY, setVertical, setVisible, setWidth, setX, setXY, setXYLocal, setY, stopAnimDeep, stopIntervals, toStringProps
Methods inherited from class snap.props.PropObject
addPropChangeListener, addPropChangeListener, batchPropChange, batchPropChange, batchPropChanges, fireBatchPropChanges, firePropChange, firePropChange, firePropChange, getPropForName, getPropParent, getPropSet, getPropsForArchival, getPropsForArchivalExtra, getPropsString, processArchivedNode, processUnarchivedNode, removePropChangeListener, removePropChangeListener, setPropsString, setPropValues, toString
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface snap.view.ViewHost
addGuest, getGuests, removeGuest, setGuests
-
Field Details
-
_controller
-
-
Constructor Details
-
GameView
public GameView()Constructor. -
GameView
public GameView(double width, double height) Constructor.
-
-
Method Details
-
getController
Returns the game controller. -
getImage
Returns the background image. -
setImage
Sets the background image. -
setImageForName
Sets the image for given name. -
getShowCoords
public boolean getShowCoords()Returns whether to draw coordinate grid. -
setShowCoords
public void setShowCoords(boolean aValue) Sets whether to draw coordinate grid. -
getActors
Returns the actors. -
getActorsReversed
Returns the actors reversed. -
addActorAtXY
Adds a new actor to game view at given XY point. -
getActorForName
Returns the actor with given name. -
getActorAtXY
Returns the first actor hit by given point in local coords. -
getActorsAtXY
Returns the actors hit by given point in local coords. -
isActorAtXY
Returns whether given actor is at given XY and of matching class. -
removeActor
Removes an actor. -
removeActor
Removes an actor. -
setFillColor
Sets the game view fill color for given color string. -
isMouseDown
public boolean isMouseDown()Returns whether the mouse button is down.- Overrides:
isMouseDown
in classView
-
getMouseX
public double getMouseX()Returns the mouse X. -
getMouseY
public double getMouseY()Returns the mouse Y. -
isMouseClicked
public boolean isMouseClicked()Returns whether the mouse was clicked on this frame. -
getMouseClickCount
public int getMouseClickCount()Returns the mouse click count. -
isKeyDown
Returns whether a given key is pressed. -
isKeyClicked
Returns whether a given key was pressed in the current frame. -
isPlaying
public boolean isPlaying()Returns whether game is playing. -
setPlaying
public void setPlaying(boolean aValue) Sets whether game is playing. -
play
public void play()Starts the game timer. -
stop
public void stop()Stops the game timer. -
stepGameFrame
protected void stepGameFrame()Steps the game forward a frame. -
paintFront
Paints the game view.- Overrides:
paintFront
in classView
-
processEvent
Process event.- Overrides:
processEvent
in classView
-
addChild
Override to clear actors list. -
removeChild
Override to clear actors list.- Overrides:
removeChild
in classChildView
-