-
Notifications
You must be signed in to change notification settings - Fork 6
3. Objects
sean_codes edited this page Jan 6, 2017
·
1 revision
Objects are stored in the _objects folder. To create a new object create a new js file in the _objects folder. The files in this folders will be loaded by the load.php at runtime.
<script src="cscript/_objects/obj_something.js?"></script>
Inside the new js file you will need to create the object by using:
cs.obj.create(name, createFunction, stepFunction)
Copy this into your new js file and change the 'obj_name' string to the name of your object.
cs.obj.load('obj_name', function(){
//-------------------------------------------------------------------------------------------//
//-------------------------------------| Create |--------------------------------------------//
//-------------------------------------------------------------------------------------------//
this.width = 16;
this.height = 16;
}, function(){
//-------------------------------------------------------------------------------------------//
//--------------------------------------| Step |---------------------------------------------//
//-------------------------------------------------------------------------------------------//
cs.draw.sprite('spr', 0, this.x, this.y);
});
To create the object add after the init() function to cs.obj.create('obj_name', x, y);
<script type="text/javascript">
cs.init('view');
//Game code under here
cs.obj.create('obj_name', 0, 0);
</script>