public class Sprite
- Object
- Sprite
ImplementsPhysicsLinkable
Known subtypesAnimatedSprite
A drawable image with position, rotation, scale, tint and a normalized anchor.
A sprite is a lightweight data holder: it describes what and where, while a
SpriteRenderer turns it into a GPU textured quad each frame (using the
com.codename1.gpu package – an orthographic camera in pixel space, a
com.codename1.gpu.Material.Type#SPRITE material and alpha blending). Because a
sprite never touches the GPU directly you can create one with just an
com.codename1.ui.Image – the renderer uploads and caches the matching
com.codename1.gpu.Texture on demand.
#getX()/#getY() is the location of the anchor point (the image center by
default); rotation and scale pivot around that anchor. Sprite implements
com.codename1.gaming.physics.PhysicsLinkable so a physics body can drive it –
see com.codename1.gaming.physics.PhysicsWorld.
Constructors
public Sprite() | Creates an empty sprite with no image. |
public Sprite(Image image) | Creates a sprite drawing the given image, anchored at its center. |
Methods
Inherited methods
Constructor details
Sprite
public Sprite()Sprite
public Sprite(Image image)Method details
onUpdate
protected void onUpdate(double deltaSeconds)AnimatedSprite override it to advance over time. Scene#update(double)
invokes this for every sprite it contains.getRenderWidth
public float getRenderWidth()getRenderHeight
public float getRenderHeight()getBounds
public Rectangle getBounds()intersects
public boolean intersects(Sprite other)setPhysicsPosition
public void setPhysicsPosition(float xPx, float yPx)setPhysicsRotation
public void setPhysicsRotation(float radians)getImage
public Image getImage()setImage
public void setImage(Image image)getX
public double getX()getY
public double getY()setX
public void setX(double x)setY
public void setY(double y)setPosition
public void setPosition(double x, double y)getZ
public double getZ()GameView’s GameCamera is in
perspective mode (GameCamera#MODE_PERSPECTIVE). Ignored in 2D.setZ
public void setZ(double z)setPosition
public void setPosition(double x, double y, double z)getRotation
public float getRotation()setRotation
public void setRotation(float degrees)getScaleX
public float getScaleX()getScaleY
public float getScaleY()setScale
public void setScale(float scale)setScale
public void setScale(float scaleX, float scaleY)setSize
public void setSize(float widthPx, float heightPx)getColor
public int getColor()setColor
public void setColor(int argb)getAlpha
public int getAlpha()#getColor().setAlpha
public void setAlpha(int alpha)getAnchorX
public double getAnchorX()getAnchorY
public double getAnchorY()setAnchor
public void setAnchor(double anchorX, double anchorY)isVisible
public boolean isVisible()setVisible
public void setVisible(boolean visible)getZOrder
public int getZOrder()setZOrder
public void setZOrder(int zOrder)Scene to sort sprites; higher values draw on top.getUserData
public Object getUserData()setUserData
public void setUserData(Object userData)getParallaxX
public float getParallaxX()1): the fraction of the scene camera’s
x-offset this sprite scrolls by. 1 scrolls with the world; a value below 1
scrolls slower so the sprite reads as more distant (clouds, far mountains); 0
pins it to the screen (a HUD-like backdrop).getParallaxY
public float getParallaxY()1); see #getParallaxX().setParallax
public void setParallax(float x, float y)0.2-0.5) so it drifts behind the foreground as the camera scrolls.