123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- //-----------------------------------------------------------------------------
- // Copyright (c) 2013 GarageGames, LLC
- //
- // Permission is hereby granted, free of charge, to any person obtaining a copy
- // of this software and associated documentation files (the "Software"), to
- // deal in the Software without restriction, including without limitation the
- // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
- // sell copies of the Software, and to permit persons to whom the Software is
- // furnished to do so, subject to the following conditions:
- //
- // The above copyright notice and this permission notice shall be included in
- // all copies or substantial portions of the Software.
- //
- // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
- // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
- // IN THE SOFTWARE.
- //-----------------------------------------------------------------------------
- function MoveToToy::create( %this )
- {
- // Activate the package.
- activatePackage( MoveToToyPackage );
- // Initialize the toys settings.
- MoveToToy.moveSpeed = 50;
- MoveToToy.trackMouse = true;
- // Add the custom controls.
- addNumericOption("Move Speed", 1, 150, 1, "setMoveSpeed", MoveToToy.moveSpeed, true, "Sets the linear speed to use when moving to the target position.");
- addFlagOption("Track Mouse", "setTrackMouse", MoveToToy.trackMouse, false, "Whether to track the position of the mouse or not." );
- // Reset the toy initially.
- MoveToToy.reset();
- }
- //-----------------------------------------------------------------------------
- function MoveToToy::destroy( %this )
- {
- // Deactivate the package.
- deactivatePackage( MoveToToyPackage );
- }
- //-----------------------------------------------------------------------------
- function MoveToToy::reset( %this )
- {
- // Clear the scene.
- SandboxScene.clear();
-
- // Create background.
- %this.createBackground();
- // Create target.
- %this.createTarget();
-
- // Create sight.
- %this.createSight();
- }
- //-----------------------------------------------------------------------------
- function MoveToToy::createBackground( %this )
- {
- // Create the sprite.
- %object = new Sprite();
-
- // Set the sprite as "static" so it is not affected by gravity.
- %object.setBodyType( static );
-
- // Always try to configure a scene-object prior to adding it to a scene for best performance.
- // Set the position.
- %object.Position = "0 0";
- // Set the size.
- %object.Size = "100 75";
-
- // Set to the furthest background layer.
- %object.SceneLayer = 31;
-
- // Set an image.
- %object.Image = "ToyAssets:highlightBackground";
-
- // Set the blend color.
- %object.BlendColor = SlateGray;
-
- // Add the sprite to the scene.
- SandboxScene.add( %object );
- }
- //-----------------------------------------------------------------------------
- function MoveToToy::createSight( %this )
- {
- // Create the sprite.
- %object = new Sprite();
-
- // Set the sight object.
- MoveToToy.SightObject = %object;
-
- // Set the static image.
- %object.Image = "ToyAssets:Crosshair2";
- // Set the blend color.
- %object.BlendColor = Lime;
-
- // Set the transparency.
- %object.setBlendAlpha( 0.5 );
-
- // Set a useful size.
- %object.Size = 40;
-
- // Set the sprite rotating to make it more interesting.
- %object.AngularVelocity = -90;
-
- // Add to the scene.
- SandboxScene.add( %object );
- }
- //-----------------------------------------------------------------------------
- function MoveToToy::createTarget( %this )
- {
- // Create the sprite.
- %object = new Sprite();
- // Set the target object.
- MoveToToy.TargetObject = %object;
-
- // Set the static image.
- %object.Image = "ToyAssets:Crosshair3";
-
- // Set the blend color.
- %object.BlendColor = DarkOrange;
-
- // Set a useful size.
- %object.Size = 20;
-
- // Set the sprite rotating to make it more interesting.
- %object.AngularVelocity = 60;
-
- // Add to the scene.
- SandboxScene.add( %object );
- }
- //-----------------------------------------------------------------------------
- function MoveToToy::setMoveSpeed( %this, %value )
- {
- %this.moveSpeed = %value;
- }
- //-----------------------------------------------------------------------------
- function MoveToToy::setTrackMouse( %this, %value )
- {
- %this.trackMouse = %value;
- }
- //-----------------------------------------------------------------------------
- package MoveToToyPackage
- {
- function SandboxWindow::onTouchDown(%this, %touchID, %worldPosition)
- {
- // Call parent.
- Parent::onTouchDown(%this, %touchID, %worldPosition );
-
- // Set the target to the touched position.
- MoveToToy.TargetObject.Position = %worldPosition;
-
- // Move the sight to the touched position.
- MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveSpeed );
- }
- //-----------------------------------------------------------------------------
- function SandboxWindow::onTouchMoved(%this, %touchID, %worldPosition)
- {
- // Call parent.
- Parent::onTouchMoved(%this, %touchID, %worldPosition );
-
- // Finish if not tracking the mouse.
- if ( !MoveToToy.trackMouse )
- return;
-
- // Set the target to the touched position.
- MoveToToy.TargetObject.Position = %worldPosition;
-
- // Move the sight to the touched position.
- MoveToToy.SightObject.MoveTo( %worldPosition, MoveToToy.moveSpeed );
- }
-
- };
|