Package totalcross.game
Class Animation
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.game.Animation
-
- Direct Known Subclasses:
AnimatedButton
public class Animation extends Control
The Animation control class.
This control displays an animation that can be loaded from indexed BMP files (one frame per image) or by a multi-frames BMP. This kind of BMP file contains a list of images having all the same size and that lay side by side.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description protected ImagebackgroundBackground image.protected intcurFrameThe current frame.intdrawOpDumb field to keep compilation compatibility with TC 1.static inteventFinishNotifies animation endings.static inteventFrameNotifies animation frames.static inteventLoopNotifies animation loops.static inteventNoneNo notify at all.protected inteventsMaskEvent notification mask, whose value iseventFinish, which means that an event is posted only when the animation finishes.intframePeriodDelay between two frames.ImageframesBufferFrames buffer.booleanisPausedReflects the animation pause state.booleanisPlayingReflects the animation play state.static intLOOPS_UNLIMITEDstart()methodloopsargument special value to loop endlessly.booleanpauseIfNotVisibleSets to true to stop the animation if its parent window is not the top most.-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, nextTabControl, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidenableEvents(int mask)Enable the posting of events.intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.voidonEvent(Event e)Process events for theAnimationclass.voidonPaint(Graphics gfx)Called by the system to draw the animation.voidpause()Pauses a running animation.voidresume()Resumes a paused animation.voidsetImage(Image frames, int frameCount, int framePeriod)Sets the image of anAnimationobject.intsize()Number of frames in the animation.voidstart(int loops)Starts the animation.voidstart(int sFrame, int eFrame, int step, int loops)Starts the animation with a frame range.voidstop()Stops the animation.-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addTimer, addTimer, addTimerListener, addWindowListener, bringToFront, changeHighlighted, clear, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onBoundsChanged, onColorsChanged, onFontChanged, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
pauseIfNotVisible
public boolean pauseIfNotVisible
Sets to true to stop the animation if its parent window is not the top most.
-
framePeriod
public int framePeriod
Delay between two frames.
-
isPlaying
public boolean isPlaying
Reflects the animation play state.
-
isPaused
public boolean isPaused
Reflects the animation pause state.
-
framesBuffer
public Image framesBuffer
Frames buffer.
-
eventsMask
protected int eventsMask
Event notification mask, whose value iseventFinish, which means that an event is posted only when the animation finishes.
-
eventNone
public static final int eventNone
No notify at all.- See Also:
- Constant Field Values
-
eventFinish
public static final int eventFinish
Notifies animation endings.- See Also:
- Constant Field Values
-
eventLoop
public static final int eventLoop
Notifies animation loops.- See Also:
- Constant Field Values
-
eventFrame
public static final int eventFrame
Notifies animation frames.- See Also:
- Constant Field Values
-
LOOPS_UNLIMITED
public static final int LOOPS_UNLIMITED
start()methodloopsargument special value to loop endlessly.- See Also:
- Constant Field Values
-
curFrame
protected int curFrame
The current frame.
-
drawOp
public int drawOp
Dumb field to keep compilation compatibility with TC 1.
-
background
protected Image background
Background image.
-
-
Constructor Detail
-
Animation
protected Animation()
Animation constructor. This constructor may be used by deriving classes.
-
Animation
public Animation(Image frames, int framePeriod) throws ImageException
Animation constructor.- Parameters:
frames- Single image containing all frames. The number of frames and the transparent colors are fetched from the image.framePeriod- Delay in milliseconds between two frames.- Throws:
ImageException- If an internal method throws it.
-
Animation
public Animation(Image frames, int frameCount, int framePeriod) throws ImageException
Animation constructor.- Parameters:
frames- single image containing all frames.frameCount- width in pixels of one frame.framePeriod- delay in milliseconds between two frames.- Throws:
ImageException- If an internal method throws it.
-
-
Method Detail
-
setImage
public void setImage(Image frames, int frameCount, int framePeriod) throws ImageException
Sets the image of anAnimationobject.- Parameters:
frames- single image containing all frames.frameCount- width in pixels of one frame.framePeriod- delay in milliseconds between two frames.- Throws:
ImageException- If an internal method throws it.
-
onEvent
public void onEvent(Event e)
Process events for theAnimationclass.
-
size
public int size()
Number of frames in the animation.- Returns:
- Frames amount
-
getPreferredWidth
public int getPreferredWidth()
Returns the preferred width of this control.- Overrides:
getPreferredWidthin classControl- Returns:
- The preferred width of this control.
-
getPreferredHeight
public int getPreferredHeight()
Returns the preferred height of this control.- Overrides:
getPreferredHeightin classControl- Returns:
- The preferred height of this control.
-
onPaint
public void onPaint(Graphics gfx)
Called by the system to draw the animation.
-
enableEvents
public void enableEvents(int mask)
Enable the posting of events. By default the posting of events are disabled.
-
pause
public void pause()
Pauses a running animation. If the animation is not playing, this call has no effect.
-
resume
public void resume()
Resumes a paused animation. If the animation is not playing, this call has no effect.
-
stop
public void stop()
Stops the animation. If the animation is not playing, this call has no effect.
-
start
public void start(int sFrame, int eFrame, int step, int loops)Starts the animation with a frame range. This method starts an animation by specifying the frame range and a loop flag. If the application is already playing, this call has no effect.- Parameters:
sFrame- The start frame.eFrame- The end frame.step- The frame increment.loops- The number of animation iterations.
-
start
public void start(int loops)
Starts the animation. This method starts the animation and loops the specified amount of time. If the application is already playing, this call has no effect.- Parameters:
loops- Integer value specifying the number of loops orLOOPS_UNLIMITEDfor an infinite loop.- See Also:
LOOPS_UNLIMITED
-
-