jshaObjects ( Objects That Will Spawn Later. ) - Arshiatmi/jsha GitHub Wiki
There Is a jshaObject That You Can Do Some Stuff That Will Happend Soon But Not Now. A Nice Example Of Using jshaObjects Are Pours . With Pours You Can Spawn n Copy Of A jshaObject. You Can Use This Object When You Want To Spawn Something In Specific Situations...
Way To Use :
var final_text = new jshaObject("h1","loseOrWin");
final_text.[function]();
All Methods Are Here :
appendTo( where, mode, index )
You Can Use This Method When You Want To Spawn. You Will Set where To A tag,id,name or class. After That You Have To Select A Mode. modes Are "tag" / "id" / "class" / "name". If You Select id, index Does Not Do Anything But If You Selected Anything Else You Should Select An Index. For Example In name Mode This Code Will Run : (document.getElementsByName(where)[index]) . Default mode Is "tag" And Default index is 0.
setCSSAttribute( key, value )
You Can Set CSS Variables Using This Method. For Example If You Want To Set color Of Object, Just You Need To Run instance.setCSSAttribute("color","red"); And It Will Be Set !
removeCSSAttribute( key )
You Can Remove A CSS Attribute With This Method. For Example instance.removeCSSAttribute("color"); Will Remove Color Of Object.
getLocation( )
Get Location Of Object. ( Answer Is A JSON Like {"x":100,"y":200}. )
x( )
Get x Of Object As number.
y()
Get y Of Object As number.
setCSS(str)
It Will Get An String And Set Object Style To This String. ( String Should Be Like "color:red;font-size:10px;" )
addClass(className);
Add A Class To List Of Classes In This Object.
setAttribute(key, value);
It Will Set An html Value. Like instance.setAttribute("dir","rtl") Or instance.setAttribute("src","image_link") .
getAttribute(key)
Get An HTML Attribute. Like instance.getAttribute("src") . And It Will Return "image_link". ( Example Is From Previous Paragraph )
getCSSAttribute(key)
Get CSS Attribute. Like instance.getCSSAttribute("color") And It Will Return "red" For Example.
remove()
It Will Remove The Object If It Exists In Screen. (Spawned Before)
Events
oncollision(name,func)
You Can Set A Function When Another Kind Of Object Have Collision With This instance Of Object. name Is Name Of The Objects That We Want To Check For Collision And func Is The Function That You Want To Run On Collisions. For Example You Can Use This Part Like This :
enemy.oncollision("bullets",myFunc);
And myFunc Style Must Be Like This :
function myFunc(thisObject,targetObject){ // First Is this Object And Second Is The Object That Has collision To This.
// Your Code Here...
// These Codes Below Are Just An Example.
thisObject.remove();
targetObject.remove();
}
Both Objects That Will Send To myFunc Are Simple HTML Objects. ( All Functions Are like document.getElementById("id") )
An Example Of Using :
var enemy = new jshaObject("img","enemy");
enemy.setAttribute("src","./Enemies/enemy1.png");
enemy.setClass("enemies");
enemy.oncollision("bullet",remover);
enemy.appendTo("body");
It Will Spawn An Enemy Object That Will Remove When A Bullet Collisions To That. ( function remover Is not written )
You Can Access To The Html Object Like That :
var a = new jshaObject("test");
->a.object
You Can Find If Object Is jshaObject Like That :
var a = new jshaObject("test");
->a.type // If Returns "jshaObject" , That's It ! Else Its Not A jshaObject.