{"id":163,"date":"2015-01-31T15:34:08","date_gmt":"2015-01-31T23:34:08","guid":{"rendered":"http:\/\/c2.studioryu.net\/?p=163"},"modified":"2015-01-31T15:34:08","modified_gmt":"2015-01-31T23:34:08","slug":"working-with-the-sdk-object-properties","status":"publish","type":"post","link":"https:\/\/c2.studioryu.net\/?p=163","title":{"rendered":"Working with the SDK &#8211; Object Properties"},"content":{"rendered":"<p>Working the C2 SDK is not elegant. In fact I would say that the C2 engine was not designed for other developers. There is a lack of documentation and overall a lack of an SDK engine. Instead most of the work with C2 engine is through a small set of callbacks and properties. Often Scirra(Ashley) encourages that Plugins and behaviors have little interaction with others of similar type. \u00a0Such as no Plugin to Plugin interaction and no Behavior to Plugin interaction. Also no Plugin to Behavior interaction, but Behavior to Plugin interaction is encouraged&#8230; whew.<\/p>\n<p>however making anything advanced requires either an SDK or just plain ignoring all this direction. Developers such as RexRainbow and R0j0hound are two in the community that do so regularly. \u00a0With a lack of documentation I have been repeating a simple code that logs the properties of an Object, but this is becoming tedious so I&#8217;m going to post the property names in this post. I&#8217;m also going to post a piece of code snippet that I use to grab another Plugin&#8230; not behavior.<\/p>\n<p>&nbsp;<\/p>\n<p>Here is the snippet of code used to get the properties of an object.<br \/>\nconsole.log(&#8220;this from a\u00a0[location]&#8221;);<br \/>\nfor(name in this){\u00a0console.log(&#8220;property: &#8221; + name ); }<\/p>\n<p>WARNING:<br \/>\nThe properties listed are from this and this.inst, however &#8220;this&#8221; may have a difference reference value.<\/p>\n<h5>C2 Get Plugin and the start of a C2 SDK<\/h5>\n<p>Put this in the top of the runtime.js, but under<br \/>\nassert2(cr, &#8220;cr namespace not created&#8221;);<br \/>\nassert2(cr.plugins_, &#8220;cr.plugins_ not created&#8221;);<\/p>\n<p>if( !cr.hasOwnProperty(&#8220;c2kit&#8221;) ) cr.c2kit = {}; \/\/ prep a c2 sdk kit<\/p>\n<p>if( !cr.c2kit.hasOwnProperty(&#8220;getPluginObject&#8221;) )<br \/>\ncr.c2kit.getPluginObject = function(runtime, plugin)<br \/>\n{<br \/>\nvar plugins = runtime.types;<br \/>\nvar name, inst;<br \/>\nfor (name in plugins)<br \/>\n{<br \/>\ninst = plugins[name].instances[ 0 ];<br \/>\nif (inst instanceof cr.plugins_[ plugin ].prototype.Instance)<br \/>\nreturn inst;<br \/>\n}<br \/>\nreturn null;<br \/>\n};<\/p>\n<p>sample use:<br \/>\n\/\/ get the object first as the object is needed for running functions<br \/>\nvar audioObject =\u00a0cr.c2kit.getPluginObject( this.runtime, &#8220;Audio&#8221;);<\/p>\n<p>\/\/ audio object is the memory run, the plugin is the functions<br \/>\nvar audioPlugin =\u00a0audioPlugin = cr.plugins_.Audio.prototype;<\/p>\n<p>\/\/ when using a function, we need to pass the memory instance<br \/>\n\/\/ in a js call function. so that the function assigns this as the right<br \/>\n\/\/ memory object<br \/>\naudioPlugin.acts.PlayByName.call(audioObject, 0, &#8220;foo&#8221;, 0, 1, &#8220;&#8221;);<\/p>\n<h5>Instance<br \/>\nMemory Runtime\u00a0from<br \/>\nPlugin &#8211; this<br \/>\nBehavior &#8211; this.inst<\/h5>\n<p>This is from a WORLD only object. There are no positional, sizing or other such flags. So it&#8217;s surprising there is so much junk in the this. World seem that this is the level where behaviors would be attached. but there is reference to Tilemaps, even if tilemaps aren&#8217;t used. Sorry Ashley, but this seems poor design architect that everything including the kitchen sink get&#8217;s thrown in even when it&#8217;s not needed.<\/p>\n<p>property: type<br \/>\nproperty: runtime<br \/>\nproperty: recycled<br \/>\nproperty: uid<br \/>\nproperty: puid<br \/>\nproperty: iid<br \/>\nproperty: get_iid<br \/>\nproperty: toString<br \/>\nproperty: extra<br \/>\nproperty: instance_var_names<br \/>\nproperty: instance_vars<br \/>\nproperty: x<br \/>\nproperty: y<br \/>\nproperty: z<br \/>\nproperty: width<br \/>\nproperty: height<br \/>\nproperty: depth \u00a0 &lt; What is depth for?, usually this would be zIndex<br \/>\nproperty: angle<br \/>\nproperty: opacity<br \/>\nproperty: hotspotX<br \/>\nproperty: hotspotY<br \/>\nproperty: blend_mode<br \/>\nproperty: compositeOp<br \/>\nproperty: srcBlend<br \/>\nproperty: destBlend<br \/>\nproperty: effect_params<br \/>\nproperty: active_effect_types<br \/>\nproperty: active_effect_flags<br \/>\nproperty: bbox<br \/>\nproperty: collcells<br \/>\nproperty: rendercells<br \/>\nproperty: bquad<br \/>\nproperty: bbox_changed_callbacks<br \/>\nproperty: set_bbox_changed<br \/>\nproperty: add_bbox_changed_callback<br \/>\nproperty: contains_pt<br \/>\nproperty: update_bbox<br \/>\nproperty: update_render_cell<br \/>\nproperty: update_collision_cell<br \/>\nproperty: get_zindex<br \/>\nproperty: tilemap_exists<br \/>\nproperty: tilemap_width<br \/>\nproperty: tilemap_height<br \/>\nproperty: tilemap_data<br \/>\nproperty: updateActiveEffects<br \/>\nproperty: uses_shaders<br \/>\nproperty: bbox_changed<br \/>\nproperty: cell_changed<br \/>\nproperty: visible<br \/>\nproperty: my_timescale<br \/>\nproperty: layer<br \/>\nproperty: zindex \u00a0 \u00a0 \u00a0&lt; Hey zIndes.. why depth?<br \/>\nproperty: collision_poly<br \/>\nproperty: collisionsEnabled<br \/>\nproperty: behavior_insts \u00a0&lt; could be a behaviour objects?<br \/>\nproperty: properties<br \/>\nproperty: is_contained<br \/>\nproperty: siblings<br \/>\nproperty: onCreate<br \/>\nproperty: onDestroy<br \/>\nproperty: saveToJSON<br \/>\nproperty: loadFromJSON<br \/>\nproperty: draw<br \/>\nproperty: drawGL<br \/>\nproperty: getDebuggerValues<br \/>\nproperty: onDebugValueEdited<\/p>\n<p>&nbsp;<\/p>\n<h5>Object<br \/>\nList of Properties of\u00a0 &#8220;this&#8221; from<br \/>\nBehaviour &#8211;\u00a0behinstProto.onCreate &amp;\u00a0behinstProto.tick<br \/>\nPlugin &#8211;\u00a0pluginProto.Instance<\/h5>\n<p>Examining the properties. This would look like a the prototype and not a run memory values&#8230; however it seems overall there is a lot of mixing. \u00a0 What really throws a strange wrench into this is that &#8220;this&#8221; when access from the initiator on Plugin.Proto.Instance a location where you create variables; this is not the same as the above Plugin memory run time.<\/p>\n<p>C2 Object &#8211; this<br \/>\nproperty: type<br \/>\nproperty: behavior<br \/>\nproperty: inst<br \/>\nproperty: runtime<br \/>\nproperty: recycled<br \/>\nproperty: properties<br \/>\nproperty: onCreate<br \/>\nproperty: onDestroy<br \/>\nproperty: saveToJSON<br \/>\nproperty: loadFromJSON<br \/>\nproperty: tick<br \/>\nproperty: getDebuggerValues<br \/>\nproperty: onDebugValueEdited<br \/>\nIt would seem there are three levels to a Plugin, with behaviours exending the Plugin scope.<\/p>\n<p>1. Root prototype<br \/>\nI didn&#8217;t list this any where in the post. But this would be the global Plugin initiator.<\/p>\n<p>2. Core Object and Engine Functions<br \/>\nThis is where the most basic object information sits. This often include the constructors, destruction and what would be your personal variables for the Plugin<\/p>\n<p>3. Instance Properties and Gaming Function<br \/>\nThis is where all the awesome fun stuff happens and most of the manipulation occurs here.<\/p>\n<p>Alright with this foundation in hand. Go ahead are work on creating some awesome Plugins and Behaviors. I know I will be \ud83d\ude42<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Working the C2 SDK is not elegant. In fact I would say that the C2 engine was not designed for other developers. There is a lack of documentation and overall a lack of an SDK engine. Instead most of the work with C2 engine is through a small set of callbacks and properties. Often Scirra(Ashley) &hellip; <a href=\"https:\/\/c2.studioryu.net\/?p=163\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Working with the SDK &#8211; Object Properties<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11],"tags":[],"class_list":["post-163","post","type-post","status-publish","format-standard","hentry","category-blog"],"_links":{"self":[{"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=\/wp\/v2\/posts\/163","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=163"}],"version-history":[{"count":3,"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions"}],"predecessor-version":[{"id":166,"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=\/wp\/v2\/posts\/163\/revisions\/166"}],"wp:attachment":[{"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=163"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=163"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/c2.studioryu.net\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=163"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}