Browse Source

Add getSpriteId method for CompositeSprite

Mike Lilligreen 11 years ago
parent
commit
2c62b9cd9c

+ 12 - 0
engine/source/2d/core/SpriteBatch.cc

@@ -457,6 +457,18 @@ bool SpriteBatch::selectSpriteName( const char* pName )
 
 //------------------------------------------------------------------------------
 
+U32 SpriteBatch::getSpriteId( void ) const
+{
+    // Finish if a sprite is not selected.
+    if ( !checkSpriteSelected() )
+        return 0;
+
+    // Get sprite id.
+    return mSelectedSprite->getBatchId();
+}
+
+//------------------------------------------------------------------------------
+
 void SpriteBatch::setSpriteImage( const char* pAssetId, const U32 imageFrame )
 {
     // Debug Profiling.

+ 1 - 0
engine/source/2d/core/SpriteBatch.h

@@ -120,6 +120,7 @@ public:
     bool selectSpriteName( const char* pName );
     inline void deselectSprite( void ) { mSelectedSprite = NULL; }
     bool isSpriteSelected( void ) const { return mSelectedSprite != NULL; }
+    U32 getSpriteId( void ) const;
 
     void setSpriteImage( const char* pAssetId, const U32 imageFrame );
     void setSpriteImage( const char* pAssetId, const char* namedFrame );

+ 10 - 0
engine/source/2d/sceneobject/CompositeSprite_ScriptBinding.h

@@ -1040,6 +1040,16 @@ ConsoleMethodWithDocs(CompositeSprite, getSpriteName, ConsoleString, 2, 2, ())
 
 //-----------------------------------------------------------------------------
 
+/*! Gets the SpriteBatchId of the currently selected sprite.
+    @returns The SpriteBatchId
+*/
+ConsoleMethodWithDocs(CompositeSprite, getSpriteId, ConsoleInt, 2, 2, ())
+{
+    return object->getSpriteId();
+}
+
+//-----------------------------------------------------------------------------
+
 /*! Picks sprites intersecting the specified point with optional group/layer masks.
     @param x/y The coordinate of the point as either (\x y\ or (x,y)
     @return Returns list of sprite Ids.