Browse Source

- Now when touching the composite sprite in the CompositeSpriteToy it deletes the sprites under the touch point.

MelvMay-GG 12 years ago
parent
commit
bf09573
1 changed files with 44 additions and 1 deletions
  1. 44 1
      modules/CompositeSpriteToy/1/main.cs

+ 44 - 1
modules/CompositeSpriteToy/1/main.cs

@@ -22,6 +22,9 @@
 
 function CompositeSpriteToy::create( %this )
 {
+    // Activate the package.
+    activatePackage( CompositeSpriteToyPackage );
+    
     // Load scripts.
     exec( "./scripts/noLayout.cs" );
     exec( "./scripts/rectLayout.cs" );
@@ -55,6 +58,8 @@ function CompositeSpriteToy::create( %this )
 
 function CompositeSpriteToy::destroy( %this )
 {
+    // Deactivate the package.
+    deactivatePackage( CompositeSpriteToyPackage );    
 }
 
 //-----------------------------------------------------------------------------
@@ -134,4 +139,42 @@ function CompositeSpriteToy::createBackground(%this)
     
     // Add to the scene.
     SandboxScene.add( %obj );   
-}
+}
+
+
+package CompositeSpriteToyPackage
+{
+
+function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
+{
+    // Call parent.
+    Parent::onTouchDown(%this, %touchID, %worldPosition );
+    
+    // Fetch the composite sprite.
+    %compositeSprite = CompositeSpriteToy.CompositeSprite;
+    
+    // Pick sprites.
+    %sprites = %compositeSprite.pickPoint( %worldPosition );    
+
+    // Fetch sprite count.    
+    %spriteCount = %sprites.count;
+    
+    // Finish if no sprites picked.
+    if ( %spriteCount == 0 )
+        return;    
+        
+    // Iterate sprites.
+    for( %i = 0; %i < %spriteCount; %i++ )
+    {
+        // Fetch sprite Id.
+        %spriteId = getWord( %sprites, %i );
+        
+        // Select the sprite Id.
+        %compositeSprite.selectSpriteId( %spriteId );
+        
+        // Remove the se
+        %compositeSprite.removeSprite();
+    }
+}
+  
+};