fpv/source/libraries/noble/.docs/classes/NobleSprite.html
2024-06-01 16:52:11 +03:00

11 KiB

<html> <head> </head>

NobleSprite

An extension of Playdate's sprite object, incorporating Noble.Animation and other Noble Engine features.

Use this in place of playdate.graphics.sprite in most cases.

NobleSprite is a child class of playdate.graphics.sprite, so see the Playdate SDK documentation for additional methods and properties.


Fields

self.animation
The animation for this NobleSprite.

See

Methods

noblesprite:init([__view[, __viewIsSpritesheet=false[, __singleState=false[, __singleStateLoop=true]]]])
Do not call an "init" method directly. Use NobleSprite() (see usage examples).

Parameters

  • __view string (optional)
    This can be: the path to an image or spritesheet image file, an image object (Graphics.image) or an animation object (Noble.Animation)
  • __viewIsSpritesheet boolean = false (default)
    Set this to true to indicate that __view is a spritesheet. Will only be considered if __view is a string path to an image.
  • __singleState boolean = false (default)
    If this sprite has just one animation, set this to true. It saves you from having to use Noble.Animation.addState()
  • __singleStateLoop boolean = true (default)
    If using a single state animation, should it loop?

See

Usage

-- Provide a spritesheet image file to create a new Noble.Animation for a NobleSprite's view.
myNobleSprite = NobleSprite("path/to/spritesheet", true)
-- Provide an image file to create a new Graphics.image for a NobleSprite's view.
myNobleSprite = NobleSprite("path/to/image")
-- Use an existing Noble.Animation for a NobleSprite's view.
	local myAnimation = Noble.Animation.new("path/to/spritesheet")
 myAnimation:addState("default", 1, animation.imageTable:getLength(), nil, true)
myNobleSprite = NobleSprite(myAnimation)
-- Use an existing Graphics.image object for a NobleSprite's view.
 local myImage = Graphics.image.new("path/to/image")
myNobleSprite = NobleSprite(myImage)
-- Extending NobleSprite.

-- MyCustomSprite.lua
MyCustomSprite = {}
class("MyCustomSprite").extends(NobleSprite)

function MyCustomSprite:init(__x, __y, __anotherFunArgument)
	MyCustomSprite.super.init(self, "path/to/spritesheet", true)
	-- Etc. etc.
end

-- MyNobleScene.lua
myNobleSprite = MyCustomSprite(100, 100, "Fun!")
noblesprite:play()
This will enable the update loop for this NobleSprite, which also causes its Noble.Animation to play.
noblesprite:pause()
This will disable the update loop for this NobleSprite, which also causes its Noble.Animation to pause.
noblesprite:stop()
This will disable the update loop for this NobleSprite, and also reset its Noble.Animation (if it exists) to the first frame of its current state.
noblesprite:add(__x, __y)
Use this to add this NobleSprite to your scene. This replaces playdate.graphics.sprite:add() to allow NobleSprites to be tracked by the current NobleScene.

To add a playdate.graphics.sprite to a scene, use NobleScene:addSprite(__sprite).

Parameters

  • __x
  • __y

See

noblesprite:remove()
Use this to remove this NobleSprite from your scene. This replaces playdate.graphics.sprite:remove() to allow NobleSprites to be tracked by the current NobleScene.

To remove a playdate.graphics.sprite from a scene, use NobleScene:removeSprite(__sprite).

See

Noble Engine by Mark LaCroix, Noble Robot Documentation created using LDoc 1.5.0.
</html>