Author Topic: Scene Repair  (Read 5245 times)

  • Administrator
  • Sr. Member
  • *****
  • Posts: 407
    • View Profile
Re: Scene Repair
« Reply #60 on: January 11, 2020, 11:14:00 pm »
Finally, how to make a controller using functions
drawRoundedRectangle(target_mc:MovieClip, boxWidth:Number, boxHeight:Number, cornerRadius:Number)
and
createDummyButton(target_mc:MovieClip, name:String, text:String, x:Number, y:Number, width:Number, height:Number, key:String)
created in previous posts.

// first of all, create a Back button:
// create a standalone rounded rectangle named "ctrlback" for that on the bottom of the stage
this.createEmptyMovieClip("ctrlback",this.getNextHighestDepth());
ctrlback._x = 10;
ctrlback._y = 325;
drawRoundedRectangle(ctrlback,63,30,5);
// create a back button inside that
createDummyButton(ctrlback,"buttonback","Back",2,0,57,25,"");
ctrlback.buttonback.onRelease = function()
{
   _root.LVL.prevFrame();
   _root.npc_status = "back";
};

// Lets create main controller object atop of all others.
this.createEmptyMovieClip("controller", this.getNextHighestDepth()); // creates a MovieClip type object in highest free layer named "controller"
// move this object to desired coordinates
controller._x = 10;
controller._y = 40; // location coordinates from left top corner in default resolution pixels
// now draw a backdrop. See function definition on parameters meaning
drawRoundedRectangle(controller, 200, 50, 5);
// Now create a text label "SPEED" in that rectangle using TextField method
//createTextField(instanceName:String, depth:Number, x:Number, y:Number, width:Number, height:Number)
controller.createTextField("label", controller.getNextHighestDepth(), 0, 5, 75, 25);
// set TextField object named "label" actual text
controller.label.text = "SPEED";
// set a text format. Need a special object holding that data for TextField
var textformatdata:TextFormat = new TextFormat();
textformatdata.size = 18;
textformatdata.bold = false;
textformatdata.font = "Arial Black"; // System fonts are used, not fonts packed in SWF file.
textformatdata.color = 0xffffff; // white RGB code
textformatdata.leftMargin = 5;
// apply format on our label using it's setTextFormat() method
controller.label.setTextFormat(textformatdata);

// We have a main animation in object focus.camera.area.char.kendra which have
// multiple parts, each starting in a frame with a label:
// "in" scene start, "a" speed 1, "b" to "e" speeds 2 to 5, "knot" knotting,
// "a_knot", "b_knot" ... "e_knot" knotted version of speeds 1 to 5
// "x1" climax, "x2" knotted climax

// Now create 5 speed buttons in the main "controller" rectangle:
// for speed 1 at coordinates x 90, y 5 (just after "SPEED" text)
createDummyButton(controller,"button1","1",90,5,20,25,"1");
// define button action
controller.button1.onRelease = function()
{
   this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("a");
   this.turnGreen(); // turn this button green, turn other speed buttons white
   this._parent.button2.turnWhite();
   this._parent.button3.turnWhite();
   this._parent.button4.turnWhite();
   this._parent.button5.turnWhite();
};
// but that would not work for knotted part, so create a varibale to hold that
// status and decide button action based on that
controller.knotted = false;
controller.button1.onRelease = function()
{
   if (_parent.knotted)
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("a_knot");
   }
   else
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("a");
   }
   this.turnGreen(); // turn this button green, turn other speed buttons white
   this._parent.button2.turnWhite();
   this._parent.button3.turnWhite();
   this._parent.button4.turnWhite();
   this._parent.button5.turnWhite();
};

// the same with other speed buttons
createDummyButton(controller,"button2","2",110,5,20,25,"2");
controller.button2.onRelease = function()
{
   if (_parent.knotted)
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("b_knot");
   }
   else
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("b");
   }
   this.turnGreen();
   this._parent.button1.turnWhite();
   this._parent.button3.turnWhite();
   this._parent.button4.turnWhite();
   this._parent.button5.turnWhite();
};
createDummyButton(controller,"button3","3",130,5,20,25,"3");
controller.button3.onRelease = function()
{
   if (_parent.knotted)
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("c_knot");
   }
   else
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("c");
   }
   this.turnGreen();
   this._parent.button1.turnWhite();
   this._parent.button2.turnWhite();
   this._parent.button4.turnWhite();
   this._parent.button5.turnWhite();
};
createDummyButton(controller,"button4","4",150,5,20,25,"4");
controller.button4.onRelease = function()
{
   if (_parent.knotted)
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("d_knot");
   }
   else
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("d");
   }
   this.turnGreen();
   this._parent.button1.turnWhite();
   this._parent.button2.turnWhite();
   this._parent.button3.turnWhite();
   this._parent.button5.turnWhite();
};
createDummyButton(controller,"button5","5",170,5,20,25,"5");
controller.button5.onRelease = function()
{
   if (_parent.knotted)
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("e_knot");
   }
   else
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("e");
   }
   this.turnGreen();
   this._parent.button1.turnWhite();
   this._parent.button2.turnWhite();
   this._parent.button3.turnWhite();
   this._parent.button4.turnWhite();
};
// now the climax button
createDummyButton(controller,"buttonclimax","Climax",5,30,75,25,"x");
controller.buttonclimax.onRelease = function()
{
   // Play climax animation:
   if (_parent.knotted)
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("x2");
   }
   else
   {
     this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("x1");
   }
   // Replace Back button with Done button:
   // Delete Back button in ctrlback rectangle first
   this._parent._parent.ctrlback.buttonback.removeMovieClip();
   // Create Done button in place of that
   createDummyButton(this._parent._parent.ctrlback,"buttondone","Done",2,0,57,25,"");
   // define button action
   this._parent._parent.ctrlback.buttondone.onRelease = function()
   {
      _root.LVL.prevFrame();
      _root.npc_status = "done";
   };
   // and finally remove entire main "controller" object with speed buttons
   this._parent.removeMovieClip();
};
// create knot button only if player is canine
if(_root.genus == "canine")
{
   createDummyButton(controller,"buttonknot","Knot",80,30,55,25,"k");
   controller.buttonknot.onRelease = function()
   {
      this._parent._parent.focus.camera.area.char.kendra.gotoAndPlay("knot");
      this.turnGreen();
      this._parent.button1.turnWhite();
      this._parent.button2.turnWhite();
      this._parent.button3.turnWhite();
      this._parent.button4.turnWhite();
      this._parent.button5.turnWhite();
      // set knotted state variable so speed buttons play knotted variation
      _parent.knotted = true;
      // delete button actions so button does nothing when knotted already
      this.onRelease = function()
      {
      };
   };
}

// Now create a zoom control there are 2 approaches to that
// Make it +- zoom:
// Create button without rectangle at bottom right of the stage
createDummyButton(this,"buttonzoomin","+",500,330,20,25,"+");
buttonzoomin.onRelease = function()
{
   // choose some object in maing animation hierarchy. It' heavily nested,
   // easiest is a one without scale and offset matrix so default position is 0, 0, 100% scale
   // now on each click increase scale and move it so desired part (pus*y) is in the center
   this._parent.focus.camera.area._xscale = this._parent.focus.camera.area._xscale + 10;
   this._parent.focus.camera.area._yscale = this._parent.focus.camera.area._yscale + 10;
   this._parent.focus.camera.area._x = this._parent.focus.camera.area._x + 20;
   this._parent.focus.camera.area._y = this._parent.focus.camera.area._y + 10;
};
createDummyButton(this,"buttonzoomout","-",530,330,20,25,"-");
buttonzoomout.onRelease = function()
{
   // the opposite for zoom out. There may be some condition to limit zoom out.
   this._parent.focus.camera.area._xscale = this._parent.focus.camera.area._xscale - 10;
   this._parent.focus.camera.area._yscale = this._parent.focus.camera.area._yscale - 10;
   this._parent.focus.camera.area._x = this._parent.focus.camera.area._x - 20;
   this._parent.focus.camera.area._y = this._parent.focus.camera.area._y - 10;
};
// Alternative approach: camera with fixed view points:
// Create it as a button with toggling function of switching two view points
createDummyButton(controller,"buttonzoom","Zoom",132,30,60,25,"z");
// declare variable holding camera point in that button object
controller.buttonzoom.camera = 1;
controller.buttonzoom.onRelease = function()
{
   // if it's the first camera point, move to the second
   if(this.camera == 1)
   {
      this.turnGreen();
      this._parent._parent.focus.camera.area._xscale = 160;
      this._parent._parent.focus.camera.area._yscale = 160;
      this._parent._parent.focus.camera.area._x = 120;
      this._parent._parent.focus.camera.area._y = 60;
      this.camera = 2;
   }
   // if it's not the first camera point, move back to the first
   else
   {
      this.turnWhite();
      this._parent._parent.focus.camera.area._xscale = 100;
      this._parent._parent.focus.camera.area._yscale = 100;
      this._parent._parent.focus.camera.area._x = 0;
      this._parent._parent.focus.camera.area._y = 0;
      this.camera = 1;
   }
   // of course there may be more than two.
};
// example for Kendra sideways is attached: Normal version for Adobe compiler, FFDec version with removed types and comments because FFDec cannot deal with things that are removed in compilation.
« Last Edit: January 11, 2020, 11:35:20 pm by Tabby »