LHSprite Reference

LHSprite.lua

Overview

LHSprite class is used to load textured rectangles that are found in a level file.

Conforms to:

LHNodeProtocol

LHAnimationsProtocol

LHPhysicsProtocol

Instance Methods

createWithSpriteFrameName

  createWithSpriteFrameName(spriteFrameName, imageFilePath, parent)
Parameters
spriteFrameName

The sprite frame name as defined in the Sprite Packer and Physics Editor.

imageFilePath

The path to the image file.

parent

The parent node of the newly created sprite object. Usually the game world node.

Return Value

A new LHSprite object.

local LHSprite =  require("LevelHelper2-API.Nodes.LHSprite");

local newSpriteObj = LHSprite:createWithSpriteFrameName("carTyre", "PublishFolder/carParts.png", lhScene:getGameWorldNode());
    
newSpriteObj.x = 100;
newSpriteObj.y = 200;
--where lhScene is the object returned by LHScene:initWithContentOfFile("...");

Discussion

Create a new sprite given a sprite frame name and an image name.

If the sprite frame name also has physics, it will also create a body on the new sprite object.

Note that the x and y position values needs to be given in the parent coordinate system.

Declared In
LHSprite.lua

getImageFilePath

local  getImageFilePath()
Return Value

A string value

Discussion

Get the image file path used by the texture of this sprite.

Declared In
LHSprite.lua

getSpriteFrameName

local  getSpriteFrameName()
Return Value

A string value or nil if sprite is not using a frame name but an image file.

Discussion

Get the name of the sprite texture rectangle.

Declared In
LHSprite.lua

getSpriteSheetPath

local  getSpriteSheetPath()
Return Value

A string value or nil if sprite is using an image file.

Discussion

Get the sprite sheet path

Declared In
LHSprite.lua

setSpriteFrameWithName

local  setSpriteFrameWithName(spriteName)
Parameters
spriteName

A name from the sprite sheet this sprite belongs to. A string value.

Discussion

Changes the sprite texture rectangle based on the new sprite name.

Declared In
LHSprite.lua
Last updated: 2015-3-15

Back to top

Copyright © VLADU BOGDAN DANIEL PFA.