# Class GameSceneView

java.lang.Object
com.codename1.ui.Component
com.codename1.ui.Container
com.codename1.gpu.RenderView
com.codename1.gaming.GameView
com.codename1.gaming.level.GameSceneView

All Implemented Interfaces:
  `Animation, Editable, StyleListener, Iterable<Component>`

public class GameSceneView extends GameView

A turnkey `GameView` that plays a `GameLevel`: it wires the whole lifecycle so a generated game scene can be a thin subclass that only adds behavior.

- 2D levels are realized into the scene immediately.
- board levels are realized on the first sized frame, once an `IsoProjection` can be fitted to the view.
- 3D levels set up the perspective camera and the primary light, and build a `Model` per element in `GameView#onSetup(com.codename1.gpu.GraphicsDevice)` (the only place the GPU device exists); override `#buildModels(GraphicsDevice)` to supply real meshes instead of the default per-element cube.

Game logic goes in `#onUpdate(double)` (a no-op by default) -- the scene's sprite animations are advanced by the renderer, so do not call `Scene#update(double)`.

- ## Field Summary

  ### Fields inherited from class Component

  `BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, CROSSHAIR_CURSOR, DEFAULT_CURSOR, DRAG_REGION_IMMEDIATELY_DRAG_X, DRAG_REGION_IMMEDIATELY_DRAG_XY, DRAG_REGION_IMMEDIATELY_DRAG_Y, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, E_RESIZE_CURSOR, HAND_CURSOR, LEFT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NW_RESIZE_CURSOR, RIGHT, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, TOP, W_RESIZE_CURSOR, WAIT_CURSOR`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `GameSceneView(GameLevel level, AssetCatalog catalog)`

- ## Method Summary

  Modifier and Type
  Method
  Description
  `int`
  `addScore(int delta)`
  Adds `delta` to the score and returns the new total.
  `protected Sprite`
  `arcadePlayer()`
  The player sprite the arcade behavior drives: an element flagged `player = true` wins, else the first `player`/`hero` asset.
  `protected void`
  `buildModels(GraphicsDevice device)`
  Builds the 3D models for the level.
  `protected void`
  `checkPickups(Sprite player)`
  Default pickups: when the player overlaps a `#isCollectible(String)` sprite, `#onPickup(Sprite)` fires (scores and consumes it); when it overlaps an `#isEnemy(String)` sprite, `#onPlayerHit(Sprite)` fires (costs a life).
  `protected GameElement`
  `elementOf(Sprite sprite)`
  The `GameElement` a sprite was realized from -- its `Sprite#getUserData()` -- or `null` if the sprite did not come from a level element.
  `protected List<Sprite>`
  `findAllByAsset(String assetId)`
  Every sprite stamped from the given asset id, in z-order -- handy for a "collect all the coins" loop.
  `protected Sprite`
  `findByAsset(String assetId)`
  The first sprite stamped from the given asset id (e.g. `"player"`, `"coin"`), or `null`.
  `protected Sprite`
  `findByName(String name)`
  The first sprite in the scene whose source element has the given `name` (the name typed in the Inspector), or `null`.
  `AssetCatalog`
  `getCatalog()`
  `GameLevel`
  `getLevel()`
  `int`
  `getLives()`
  Remaining lives, or `-1` until `#setLives(int)` is called.
  `IsoProjection`
  `getProjection()`
  The isometric projection used to place a board level (valid after the first sized frame).
  `int`
  `getScore()`
  The running score (starts at zero).
  `boolean`
  `isArcadeBehavior()`
  `protected boolean`
  `isCollectible(String assetId)`
  Whether an asset id is a collectible (the default arcade behavior scores and removes it).
  `protected boolean`
  `isEnemy(String assetId)`
  Whether an asset id is an enemy (the default arcade behavior patrols it and costs a life on contact).
  `boolean`
  `isGameOver()`
  True once `#setLives(int)` has been given a count that has since reached zero -- the standard "game over" test (false while lives are uninitialized).
  `protected boolean`
  `isSolidAt(double cx, double cy, double hw, double hh)`
  Whether a box centered at `(cx, cy)` with half-size `(hw, hh)` overlaps any solid tile (a non-empty cell of a visible tile layer).
  `int`
  `loseLife()`
  Decrements the life count (never below zero) and returns what remains.
  `protected boolean`
  `onPickup(Sprite item)`
  Called when the player touches a collectible.
  `protected void`
  `onPlayerHit(Sprite enemy)`
  Called when the player touches an enemy.
  `protected void`
  `onSetup(GraphicsDevice device)`
  Override to allocate GPU resources (meshes, textures, `Model`s) once the GPU device is ready.
  `protected void`
  `onUpdate(double deltaSeconds)`
  Override to advance game logic each frame.
  `protected boolean`
  `overlaps(Sprite a, Sprite b)`
  Whether two sprites' bounding boxes overlap -- a null-safe shorthand for `Sprite#intersects(Sprite)`, the usual "did they touch?" collision test.
  `GameSceneView`
  `setArcadeBehavior(boolean on)`
  Enables (or disables) the built-in 2D arcade behavior -- gravity, run/jump, tile collision, enemy patrol and pickups -- that the editor preview shows.
  `GameSceneView`
  `setFollowCamera(boolean on)`
  Whether the arcade behavior scrolls the scene camera to follow the player (on by default) -- this is what makes a parallax background scroll.
  `void`
  `setLives(int lives)`
  `void`
  `setScore(int score)`
  `protected void`
  `update(double deltaSeconds)`
  Advance the game by the given amount of time.
  `protected void`
  `updateArcade(double deltaSeconds)`
  Runs one arcade frame: player physics, enemy patrol, pickups, and the follow camera.
  `protected void`
  `updateEnemies(double deltaSeconds)`
  Default enemy behavior: every `#isEnemy(String)` sprite patrols horizontally at its `speed` property, turning at walls and level edges.
  `protected void`
  `updatePlayer(Sprite player, double deltaSeconds)`
  Default player physics: run with Left/Right, jump on Up/Fire (edge-triggered), gravity from the level's `gravity` property, jump height from the player's `jumpHeight` property, stopped by solid tiles, respawning if it falls out.

  ### Methods inherited from class GameView

  `addModel, deinitialize, frame, getCamera, getControls, getFixedTimestep, getInput, getInterpolationAlpha, getLight, getScene, handlesInput, initComponent, isPaused, isRunning, keyPressed, keyReleased, pause, pointerDragged, pointerPressed, pointerReleased, removeModel, resume, setClearColor, setFixedTimestep, setup, start, stop`

  ### Methods inherited from class RenderView

  `getPeer, getRenderer, isContinuous, isSupported, requestRender, setContinuous`

  ### Methods inherited from class Container

  `add, add, add, add, add, add, addAll, addComponent, addComponent, addComponent, addComponent, animateHierarchy, animateHierarchyAndWait, animateHierarchyFade, animateHierarchyFadeAndWait, animateLayout, animateLayoutAndWait, animateLayoutFade, animateLayoutFadeAndWait, animateUnlayout, animateUnlayoutAndWait, applyRTL, calcPreferredSize, cancelRepaints, clearClientProperties, constrainHeightWhenScrollable, constrainWidthWhenScrollable, contains, createAnimateHierarchy, createAnimateHierarchyFade, createAnimateLayout, createAnimateLayoutFade, createAnimateLayoutFadeAndWait, createAnimateMotion, createAnimateUnlayout, createReplaceTransition, dragInitiated, drop, encloseIn, encloseIn, findDropTargetAt, findFirstFocusable, fireClicked, flushReplace, forceRevalidate, getBottomGap, getChildrenAsList, getClosestComponentTo, getComponentAt, getComponentAt, getComponentCount, getComponentIndex, getGridPosX, getGridPosY, getLayout, getLayoutHeight, getLayoutWidth, getLeadComponent, getLeadParent, getResponderAt, getSafeAreaRoot, getScrollIncrement, getSideGap, getUIManager, initLaf, invalidate, isEnabled, isSafeArea, isSafeAreaRoot, isScrollableX, isScrollableY, isSelectableInteraction, isSurface, iterator, iterator, layoutContainer, morph, morphAndWait, paint, paintComponentBackground, paintGlass, paramString, pointerPressed, refreshTheme, removeAll, removeComponent, replace, replace, replaceAndWait, replaceAndWait, replaceAndWait, revalidate, revalidateLater, revalidateWithAnimationSafety, scrollComponentToVisible, setCellRenderer, setEnabled, setLayout, setLeadComponent, setSafeArea, setSafeAreaRoot, setScrollable, setScrollableX, setScrollableY, setScrollIncrement, setShouldCalcPreferredSize, setShouldLayout, setUIManager, updateTabIndices`

  ### Methods inherited from class Component

  `accessibilityChanged, accessibilityChanged, addContextMenuListener, addDragFinishedListener, addDragOverListener, addDropListener, addFocusListener, addLongPressListener, addMouseWheelListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, addStateChangeListener, addStylusListener, animate, announceForAccessibility, bindProperty, blocksSideSwipe, calcScrollSize, contains, containsOrOwns, createStyleAnimation, deinitializeCustomStyle, dragEnter, dragExit, dragFinished, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getAccessibilityNode, getAccessibilityText, getAllStyles, getAnimationManager, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getCursor, getDefaultDragTransparency, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getDragTransparency, getEditingDelegate, getHeight, getInlineAllStyles, getInlineDisabledStyles, getInlinePressedStyles, getInlineSelectedStyles, getInlineStylesTheme, getInlineUnselectedStyles, getInnerHeight, getInnerPreferredH, getInnerPreferredW, getInnerWidth, getInnerX, getInnerY, getLabelForComponent, getName, getNativeOverlay, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getOuterHeight, getOuterPreferredH, getOuterPreferredW, getOuterWidth, getOuterX, getOuterY, getOwner, getParent, getPreferredH, getPreferredSize, getPreferredSizeStr, getPreferredTabIndex, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getSemantics, getStyle, getTabIndex, getTensileLength, getTextSelectionSupport, getTooltip, getUIID, getUnselectedStyle, getVisibleBounds, getVisibleBounds, getWidth, getX, getY, growShrink, hasFixedPreferredSize, hasFocus, hideNativeOverlay, initCustomStyle, initDisabledStyle, initPressedStyle, initSelectedStyle, initUnselectedStyle, installDefaultPainter, isAlwaysTensile, isBlockLead, isCellRenderer, isChildOf, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isEditable, isEditing, isFlatten, isFocusable, isGrabsPointerEvents, isHidden, isHidden, isHideInLandscape, isHideInPortrait, isHScrollThumbGrabbed, isHScrollThumbHover, isIgnorePointerEvents, isInClippingRegion, isInitialized, isOpaque, isOwnedBy, isPinchBlocksDragAndDrop, isRippleEffect, isRTL, isScrollable, isScrollVisible, isSetCursorSupported, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isTraversable, isVisible, isVScrollThumbGrabbed, isVScrollThumbHover, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, onSetFocusable, paintBackground, paintBackgrounds, paintBorder, paintBorderBackground, paintComponent, paintComponent, paintIntersectingComponentsAbove, paintLock, paintLockRelease, paintRippleOverlay, paintScrollbars, paintScrollbarX, paintScrollbarY, paintShadows, parsePreferredSize, pinch, pinch, pinchReleased, pointerDragged, pointerHover, pointerHoverPressed, pointerHoverReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, remove, removeContextMenuListener, removeDragFinishedListener, removeDragOverListener, removeDropListener, removeFocusListener, removeLongPressListener, removeMouseWheelListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, removeStateChangeListener, removeStylusListener, repaint, repaint, requestFocus, resetFocusable, respondsToPointerEvents, rotation, scrollRectToVisible, scrollRectToVisible, setAccessibilityText, setAlwaysTensile, setBlockLead, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setCursor, setDefaultDragTransparency, setDirtyRegion, setDisabledStyle, setDraggable, setDragTransparency, setDropTarget, setEditingDelegate, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHidden, setHidden, setHideInLandscape, setHideInPortrait, setHorizontalScrollBounds, setIgnorePointerEvents, setInitialized, setInlineAllStyles, setInlineDisabledStyles, setInlinePressedStyles, setInlineSelectedStyles, setInlineStylesTheme, setInlineUnselectedStyles, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setOpaque, setOwner, setPinchBlocksDragAndDrop, setPreferredH, setPreferredSize, setPreferredSizeStr, setPreferredTabIndex, setPreferredW, setPressedStyle, setPropertyValue, setPullToRefresh, setRippleEffect, setRTL, setSameHeight, setSameSize, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTabIndex, setTactileTouch, setTensileDragEnabled, setTensileLength, setTooltip, setTraversable, setUIID, setUIID, setUIIDFinal, setUnselectedStyle, setVerticalScrollBounds, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, shouldBlockSideSwipeLeft, shouldBlockSideSwipeRight, shouldRenderComponentSelection, showNativeOverlay, startEditingAsync, stopEditing, stripMarginAndPadding, styleChanged, toImage, toString, unbindProperty, updateNativeOverlay, visibleBoundsContains`

  ### Methods inherited from class Object

  `clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait`

  ### Methods inherited from interface Iterable

  `forEach`

- ## Constructor Details

  - ### GameSceneView

    public GameSceneView(GameLevel level, AssetCatalog catalog)

- ## Method Details

  - ### getLevel

    public GameLevel getLevel()

  - ### getCatalog

    public AssetCatalog getCatalog()

  - ### update

    protected void update(double deltaSeconds)
    Advance the game by the given amount of time. Called once per frame (or repeatedly at a fixed interval when `#setFixedTimestep(double)` is used). Realizes a board level lazily once the view has a size, then defers to `#onUpdate(double)`.
    Specified by:
      `update` in class `GameView`

  - ### onUpdate

    protected void onUpdate(double deltaSeconds)
    Override to advance game logic each frame. The default does nothing.

  - ### getProjection

    public IsoProjection getProjection()
    The isometric projection used to place a board level (valid after the first sized frame).

  - ### elementOf

    protected GameElement elementOf(Sprite sprite)
    The `GameElement` a sprite was realized from -- its `Sprite#getUserData()` -- or `null` if the sprite did not come from a level element. This is the bridge back to the typed `lives`/`value`/`speed` numbers you set in the editor.

  - ### findByName

    protected Sprite findByName(String name)
    The first sprite in the scene whose source element has the given `name` (the name typed in the Inspector), or `null`. The generated scene initializes a field per named element with this.

  - ### findByAsset

    protected Sprite findByAsset(String assetId)
    The first sprite stamped from the given asset id (e.g. `"player"`, `"coin"`), or `null`.

  - ### findAllByAsset

    protected List<Sprite> findAllByAsset(String assetId)
    Every sprite stamped from the given asset id, in z-order -- handy for a "collect all the coins" loop. Never `null` (empty when none match).

  - ### overlaps

    protected boolean overlaps(Sprite a, Sprite b)
    Whether two sprites' bounding boxes overlap -- a null-safe shorthand for `Sprite#intersects(Sprite)`, the usual "did they touch?" collision test.

  - ### getScore

    public int getScore()
    The running score (starts at zero). Add to it with `#addScore(int)`.

  - ### setScore

    public void setScore(int score)

  - ### addScore

    public int addScore(int delta)
    Adds `delta` to the score and returns the new total.

  - ### getLives

    public int getLives()
    Remaining lives, or `-1` until `#setLives(int)` is called. The generated scene seeds this from the player's `lives` property.

  - ### setLives

    public void setLives(int lives)

  - ### loseLife

    public int loseLife()
    Decrements the life count (never below zero) and returns what remains.

  - ### isGameOver

    public boolean isGameOver()
    True once `#setLives(int)` has been given a count that has since reached zero -- the standard "game over" test (false while lives are uninitialized).

  - ### setArcadeBehavior

    public GameSceneView setArcadeBehavior(boolean on)
    Enables (or disables) the built-in 2D arcade behavior -- gravity, run/jump, tile collision, enemy patrol and pickups -- that the editor preview shows. Off by default. Has no effect on board or 3D levels.

  - ### isArcadeBehavior

    public boolean isArcadeBehavior()

  - ### setFollowCamera

    public GameSceneView setFollowCamera(boolean on)
    Whether the arcade behavior scrolls the scene camera to follow the player (on by default) -- this is what makes a parallax background scroll.

  - ### updateArcade

    protected void updateArcade(double deltaSeconds)
    Runs one arcade frame: player physics, enemy patrol, pickups, and the follow camera. Called automatically before `#onUpdate(double)` when `#setArcadeBehavior(boolean)` is on and the level is 2D.

  - ### arcadePlayer

    protected Sprite arcadePlayer()
    The player sprite the arcade behavior drives: an element flagged `player = true` wins, else the first `player`/`hero` asset. Cached; also seeds `#setLives(int)` from the player's `lives` property on first resolve.

  - ### updatePlayer

    protected void updatePlayer(Sprite player, double deltaSeconds)
    Default player physics: run with Left/Right, jump on Up/Fire (edge-triggered), gravity from the level's `gravity` property, jump height from the player's `jumpHeight` property, stopped by solid tiles, respawning if it falls out. Override to change movement, or `#setArcadeBehavior(boolean)` off to opt out.

  - ### updateEnemies

    protected void updateEnemies(double deltaSeconds)
    Default enemy behavior: every `#isEnemy(String)` sprite patrols horizontally at its `speed` property, turning at walls and level edges.

  - ### checkPickups

    protected void checkPickups(Sprite player)
    Default pickups: when the player overlaps a `#isCollectible(String)` sprite, `#onPickup(Sprite)` fires (scores and consumes it); when it overlaps an `#isEnemy(String)` sprite, `#onPlayerHit(Sprite)` fires (costs a life).

  - ### onPickup

    protected boolean onPickup(Sprite item)
    Called when the player touches a collectible. The default adds the item's `value` property to the score and returns `true` to consume it. Override for power-ups: read the asset id / properties, change state, and return whether to remove the item.

  - ### onPlayerHit

    protected void onPlayerHit(Sprite enemy)
    Called when the player touches an enemy. The default costs a life and respawns the player at its start. Override for HP, knockback, invulnerability frames, checkpoints or a death screen.

  - ### isCollectible

    protected boolean isCollectible(String assetId)
    Whether an asset id is a collectible (the default arcade behavior scores and removes it). Defaults to `coin`/`gem`/`star`/`token`; override to add yours.

  - ### isEnemy

    protected boolean isEnemy(String assetId)
    Whether an asset id is an enemy (the default arcade behavior patrols it and costs a life on contact). Defaults to `slime`/`enemy*`/`npc*`; override yours.

  - ### isSolidAt

    protected boolean isSolidAt(double cx, double cy, double hw, double hh)
    Whether a box centered at `(cx, cy)` with half-size `(hw, hh)` overlaps any solid tile (a non-empty cell of a visible tile layer). The collision query the default player/enemy physics uses; override for one-way platforms etc.

  - ### onSetup

    protected void onSetup(GraphicsDevice device)

    Override to allocate GPU resources (meshes, textures, `Model`s) once the GPU device is ready. Invoked once on the render thread before the first frame -- the only place you can call `com.codename1.gpu.Primitives` / `com.codename1.gpu.GltfLoader`, which need the device. The default does nothing.

    ###### Parameters

    - `device`: the GPU device for creating meshes, textures and buffers
    For a 3D level, configures the camera + light and builds the models.
    Overrides:
      `onSetup` in class `GameView`

  - ### buildModels

    protected void buildModels(GraphicsDevice device)
    Builds the 3D models for the level. The default gives every element a unit cube (`com.codename1.gpu.Primitives#cube`) shaded with its asset's base color and placed/scaled from the element transform. Override to load real meshes (e.g. with `com.codename1.gpu.GltfLoader`) keyed off the element's asset id.