Introdution:
In some games, there are settings to set stats to where the player wants.
In some games, there are settings to set stats to where the player wants.
See Astrox series which are not made with Stencyl.
How it works
by clicking a button, the game attibute will adjust.
Limitiations
This case only include the Float which is Number in ActionScript and double in C/C++ . This case excludes initilise saves.
Prequisites
Making buttons out of actors - opitionally optimsation by disabling collison detection.
Using Game Attributes for other purposes and interbehavior relationships.
This game mechanic involves in multiple behaviors. In this case 3, and also some freeform mode which are for public static vars and functions which acts like game attributes but cannot be saved. as well as drawing without using G which is standard in Stencyl in design mode. https://stencyl-nator.blogspot.com/p/drawing-without-using-stencylgraphicsg.html
Scene Behavior - init
Dwaring section which shows save slot. This is optional. Alternatively use the standard When Drawing ecent. This is an optional drawing without using G.
2. Behaviuor for each adjusting buttons. (code mode)
package scripts;
import com.stencyl.Engine;
import com.stencyl.Input;
import com.stencyl.behavior.ActorScript; // all actor behaviors extend ActorScript
import com.stencyl.behavior.Script; // this has many functiuons
import com.stencyl.behavior.TimedTask; // for post-initialsation
import com.stencyl.models.Actor; // this behavior creates Actors
class B_init_setting_behav extends ActorScript
{
public var x:Float; public var y:Float; public var w:Float; public var h:Float;
public var mult_ratio:Float = 1.5;
public var mis:Bool = false;
public var f:F = new F(); public var rh: RH = new RH();
public var default_button:Actor = null;
public var disp_t:String = "coming soon - no data yet"; public var disp_v:Float=0;
public var game_attr: String = ""; // the name of the game attribute
public var init_string: String = "";
public function new (a:Int,b:Actor){super(b);}
override public function init()
{
actor.handlesCollisions = false; // reduces lag. Buttons does not need collision handling
this.f.f_cu = Script.getFont(19); // your desired font font numbet will often differ
this.f.c = 668787987; // font color
this.rh.c = 16631212; // rectangular color
this.x = actor.getX(); this.y = actor.getY(); this.w = actor.cacheWidth; this.h = actor.cacheHeight;
actor.whenDrawingListeners.push(dwg);
actor.mouseOverListeners.push(mos);
Script.runLater(10,create_default_button,actor);
}
public function dwg() // display ntext and hover
{
var t = this.disp_t + ": " + Engine.engine.getGameAttribute(this.game_attr);
this.f.ds(t,this.x + (this.w - this.f.g_textw(t))* 0.5, this.y+3);
if(this.mis) // drawing when mouse hover
{
var a: Float = Input.mouseX - this.x;
if(a < this.w * 0.5){this.rh.draw_hollow_rect(this.x,this.y,this.w * 0.5,this.h);}
else {this.rh.draw_hollow_rect(this.x + this.w * 0.5,this.y,this.w * 0.5,this.h);}
}
}
public function mos(ms:Int)
{
if(ms == -1){this.mis = false;} // unhover
else if(ms == 1){this.mis = true;} // hover
else if(ms == 3) // click left and right halves od the actor
{
var a: Float = Input.mouseX - this.x; // in relation to the button's position
if(a < this.w * 0.5){Engine.engine.setGameAttribute(this.game_attr,Engine.engine.getGameAttribute(this.game_attr)/this.mult_ratio);}
else {Engine.engine.setGameAttribute(this.game_attr,Engine.engine.getGameAttribute(this.game_attr)*this.mult_ratio);}
}
}
public function create_default_button (a:TimedTask)
{
Script.createRecycledActor(Conte.button_ID_to_ActorType("b_default"),this.x + 316, this.y, Script.FRONT);
this.default_button = Script.lastCreatedActor;
this.default_button.setValue("B_default_behav","game_attr",this.game_attr);
}
}
3. The button for reset button. Each correstonds to its own reset parameters.
package scripts;
import com.stencyl.Engine; // Game Attribute adjustments
import com.stencyl.behavior.ActorScript; // all actor behaviuors extend ActorScript
import com.stencyl.models.Actor;
class B_default_behav extends ActorScript
{
public var x:Float; public var y:Float; public var w:Float; public var h:Float;
public var rh:RH = new RH(); public var mos:Bool = false;
public var game_attr:String = ""; public var default_value:Float = 0;
public function new (a:Int, b:Actor){super(b);}
override public function init()
{
actor.handlesCollisions = false; // reduces lag. Buttons does not need collision handling
this.rh.c = 9839312;
this.x = actor.getX(); this.y = actor.getY();
this.w = actor.cacheWidth; this.h = actor.cacheHeight;
actor.mouseOverListeners.push(mis); actor.whenDrawingListeners.push(dwg);
}
public function dwg()
{
if(this.mos){this.rh.draw_hollow_rect(this.x,this.y,this.w,this.h);}
}
public function mis(ms:Int)
{
if(ms == -1){this.mis = false;} // unhover
else if(ms == 1){this.mis = true;} // hover
else if(ms == 3){Engine.engine.setGameAttribute(this.game_attr, Default_values.getv(this.game_attr));} // custom code - publis static function in a freeform mode.
}
}
No comments:
Post a Comment