-
Notifications
You must be signed in to change notification settings - Fork 0
keyController Objects
Way To Use :
var controller = new keyController();
controller.[function]();
Notice: You Can log All Of This Functions Because They Will Return The Answer ! ( Working Or Not ! )
All Functions That Available Now Are Here :
addKey( key [ The Key That Run Function With That ] , func [ The Function That Should Run After Pressing The Key ] )
add a Key For Control. For Example Character Should Go Left After Pressing "a" . Example Code Is :
// gameObject Is Core Of Jsha .
var player = new gameObject("player");
function goLeft(){
player.moveX(-1);
}
function goRight(){
player.moveX(1);
}
function goUp(){
player.moveY(1);
}
function goDown(){
player.moveY(-1);
}
var controller = new keyController();
controller.addKey("a",goLeft);
controller.addKey("d",goRight);
controller.addKey("w",goUp);
controller.addKey("s",goDown);
// You Have To Set Next Line To Start Controlling
controller.control();
jsonObject Must Be A JSON Like {"a":function(event){left(object,speed),"r":reload," ":shoot,...} All Of Keys Are The Button That Should Be Pressed And Values Are The Function That Should Run When That Button Pressed.
if mode is "X", object X Always Equals To Mouse X. If mode is "Y", object X Always Equals To Mouse Y. if mode is "B", Both Of object X and Y Always Equals To Mouse X And Y. Example :
let controller = new keyController();
let obj1 = new gameObject("myobj");
controller.mouseMove(obj1,"x"); // It Will Set X of Object To X Of Mouse.
// mouseMove Method Does Not Need To Call control Method.
This Function Will init Movement Of A Character With Specific Keys. obj Must Be gameObject,speed Must Be Just speed As String And Key Must Be An Array Like [left_button,right_button,down_button,up_button] Or A JSON Like {"left":left_key,"right":right_key,"up":up_key,"down":down_key}. If You Leave key Empty, Default Is ["a,"d","s","w"]. Anything That You Set As Speed, The Object Will Go With (speed * 10)px. Example :
var player = new gameObject("test");
var keyCtrl = new keyController();
keyCtrl.initMovement(player,1); // It Will Set Common Movement Buttons.
Control Everything That You Registered ! The Final Command After Using keyController Is That !