code mode - Empty actor behavior shortened

 Introduction
This is for code mode and advanced Stencyl users or who just want to learn Haxe after using Stencyl. This page is for advanced Stencyl users to optimse the game.  

Empty preview of a design mode (ActorScript)  - initial   
package scripts;

import com.stencyl.graphics.G;
import com.stencyl.graphics.BitmapWrapper;
import com.stencyl.graphics.ScaleMode;

import com.stencyl.behavior.Script;
import com.stencyl.behavior.Script.*;
import com.stencyl.behavior.ActorScript;
import com.stencyl.behavior.SceneScript;
import com.stencyl.behavior.TimedTask;

import com.stencyl.models.Actor;
import com.stencyl.models.GameModel;
import com.stencyl.models.actor.Animation;
import com.stencyl.models.actor.ActorType;
import com.stencyl.models.actor.Collision;
import com.stencyl.models.actor.Group;
import com.stencyl.models.Scene;
import com.stencyl.models.Sound;
import com.stencyl.models.Region;
import com.stencyl.models.Font;
import com.stencyl.models.Joystick;

import com.stencyl.Config;
import com.stencyl.Engine;
import com.stencyl.Input;
import com.stencyl.Key;
import com.stencyl.utils.motion.*;
import com.stencyl.utils.Utils;

import openfl.ui.Mouse;
import openfl.display.Graphics;
import openfl.display.BlendMode;
import openfl.display.BitmapData;
import openfl.display.Bitmap;
import openfl.events.Event;
import openfl.events.KeyboardEvent;
import openfl.events.TouchEvent;
import openfl.net.URLLoader;

import box2D.common.math.B2Vec2;
import box2D.dynamics.B2Body;
import box2D.dynamics.B2Fixture;
import box2D.dynamics.joints.B2Joint;

import com.stencyl.graphics.shaders.BasicShader;
import com.stencyl.graphics.shaders.GrayscaleShader;
import com.stencyl.graphics.shaders.SepiaShader;
import com.stencyl.graphics.shaders.InvertShader;
import com.stencyl.graphics.shaders.GrainShader;
import com.stencyl.graphics.shaders.ExternalShader;
import com.stencyl.graphics.shaders.InlineShader;
import com.stencyl.graphics.shaders.BlurShader;
import com.stencyl.graphics.shaders.SharpenShader;
import com.stencyl.graphics.shaders.ScanlineShader;
import com.stencyl.graphics.shaders.CSBShader;
import com.stencyl.graphics.shaders.HueShader;
import com.stencyl.graphics.shaders.TintShader;
import com.stencyl.graphics.shaders.BloomShader;



class Design_21_21_test extends ActorScript
{
public var _uf0:Font;
public var _unused0:Float;
public function new(dummy:Int, actor:Actor, dummy2:Engine)
{
super(actor);
nameMap.set("Actor", "actor");
nameMap.set("uf0", "_uf0");
nameMap.set("unused0", "_unused0");
_unused0 = 0.0;
}
override public function init()
{
}
override public function forwardMessage(msg:String)
{
}
}


Empty preview of a code mode extends (ActorScript)  
package scripts;

import com.stencyl.graphics.G;

import com.stencyl.behavior.Script;
import com.stencyl.behavior.Script.*;
import com.stencyl.behavior.ActorScript;
import com.stencyl.behavior.SceneScript;
import com.stencyl.behavior.TimedTask;

import com.stencyl.models.Actor;
import com.stencyl.models.GameModel;
import com.stencyl.models.actor.Animation;
import com.stencyl.models.actor.ActorType;
import com.stencyl.models.actor.Collision;
import com.stencyl.models.actor.Group;
import com.stencyl.models.Scene;
import com.stencyl.models.Sound;
import com.stencyl.models.Region;
import com.stencyl.models.Font;
import com.stencyl.models.Joystick;

import com.stencyl.Engine;
import com.stencyl.Input;
import com.stencyl.utils.motion.*;
import com.stencyl.utils.Utils;

import nme.ui.Mouse;
import nme.display.Graphics;


class Unused_actor_behav extends ActorScript
{
//Expose your attributes like this:
//@:attribute("id='1' name='Display Name' desc='An Attribute'")
//public var attributeName:String;

//Need further help? See: http://www.stencyl.com/help/view/code-mode/
override public function init()
{
}
public inline function update(elapsedTime:Float)
{
}
public inline function draw(g:G)
{
}
//==========================================================
// Don't edit below unless you know what you're doing
//==========================================================
public function new(dummy:Int, actor:Actor, dummy2:Engine)
{
super(actor);
addWhenUpdatedListener(null, onUpdate);
addWhenDrawingListener(null, onDraw);
}
public function onUpdate(elapsedTime:Float, list:Array<Dynamic>)
{
if(wrapper.enabled)
{
update(elapsedTime);
}
}
public function onDraw(g:G, x:Float, y:Float, list:Array<Dynamic>)
{
if(wrapper.enabled)
{
draw(g);
}
}
}


Shortened empty code mode (ActorScript)  
package scripts;
import com.stencyl.Engine; // needed for public function new () and cemera positions. 
import com.stencyl.behavior.ActorScript; // All actor behaviors extends ActorScript which extends Script. 
import com.stencyl.models.Actor; //needed for initialisation. 

class Object_behav extends ActorScript
{
public function new(a:Int,b:Actor,c:Engine){super(b);}
override public function init(){
add_dra(diagnosis); 
add_upd(upd); addMouseOverActorListener(actor,mos);} 
// when created event. init is in script as a public function. 
public function add_dra(a:Dynamic){actor.whenDrawingListeners.push(a);} 
// adds drawing events. 
public function add_upd(a:Dynamic){actor.whenUpdatedListeners.push(a);} // adds DoEnterFrame or Always in desing mode. 
public function diagnosis(){}
public function mos(ms:Int, unused_0:Array<Dynamic>{}
public function upd(){}
}

By studying this page, the code can be altered to imporve efficiency. 

=============================================================
Futher shorterned with dummy2 being removed 


the R is a freeform code adapted from https://stencyl-nator.blogspot.com/p/rectangle-drawing-arbitrary-code-for.html. that is to draw or fill rectangles. 
the F is a freeform code adapted from https://stencyl-nator.blogspot.com/p/text-drawing-arbitrary-code-for-stencyl.html

The code above shows that the public function new can be simplified from original, minimising the unued parameters gooint into the behavior. 
old: public function new(dummy:Int, actor:Actor, dummy2:Engine){super(actor);}
new: public function new(a:Dynamic, b:Actor) {super(b);} but that a can be any type include the class you created, actor behaviors and scene behaviors. because only actor will be used for super. 




No comments:

Post a Comment