Add custom hitbox action and fix polygons draw

This commit is contained in:
Lizard-13
2018-03-14 22:09:25 -03:00
parent 46279e7762
commit ddcf51a2b7
4 changed files with 32 additions and 4 deletions

View File

@@ -175,7 +175,7 @@ gdjs.sk.DebugPixiRenderer.prototype.loadVertices = function(verts, color, fill){
} }
this.renderer.lineStyle(2, color, 0.8); this.renderer.lineStyle(2, color, 0.8);
for(var i=0; i<verts.length; i++){ for(var i=0; i<verts.length; i++){
this.renderer.drawPolygon(verts.reduce(function(a, b){ return a.concat(b); })); this.renderer.drawPolygon(verts.reduce(function(a, b){ return a.concat(b); }).concat(verts[0]));
} }
if(fill){ if(fill){
this.renderer.endFill(); this.renderer.endFill();

View File

@@ -137,6 +137,16 @@ void DeclareSkeletonObjectExtension(gd::PlatformExtension & extension)
obj.AddExpression("Height", _("Height"), _("Object height"), _("Size"), "JsPlatform/Extensions/skeletonicon16.png") obj.AddExpression("Height", _("Height"), _("Object height"), _("Size"), "JsPlatform/Extensions/skeletonicon16.png")
.AddParameter("object", _("Object"), "Skeleton"); .AddParameter("object", _("Object"), "Skeleton");
obj.AddAction("SetDefaultHitbox",
_("Default hitbox"),
_("Change the object default hitbox to be used by other conditions and behaviors."),
_("Set _PARAM0_ default hitbox to _PARAM1_"),
_("Size"),
"JsPlatform/Extensions/skeletonicon24.png",
"JsPlatform/Extensions/skeletonicon16.png")
.AddParameter("object", _("Object"), "Skeleton")
.AddParameter("string", _("Slot path")).SetDefaultValue("\"\"");
// Animation instructions // Animation instructions
obj.AddCondition("AnimationPaused", obj.AddCondition("AnimationPaused",
_("Paused"), _("Paused"),

View File

@@ -23,6 +23,7 @@ gdjs.SkeletonRuntimeObject = function(runtimeScene, objectData){
this.scaleX = 1.0; this.scaleX = 1.0;
this.scaleY = 1.0; this.scaleY = 1.0;
this.renderer = new gdjs.SkeletonRuntimeObjectRenderer(); this.renderer = new gdjs.SkeletonRuntimeObjectRenderer();
this.hitboxSlot = null;
var skeletalData = this.renderer.getData(objectData.skeletalDataFilename); var skeletalData = this.renderer.getData(objectData.skeletalDataFilename);
// Main loaders // Main loaders
@@ -54,6 +55,7 @@ gdjs.SkeletonRuntimeObject.prototype.loadDragonBones = function(runtimeScene, sk
this.rootArmature.loadDragonBones(skeletalData, 0, this.renderer.textures, objectData.debugPolygons); this.rootArmature.loadDragonBones(skeletalData, 0, this.renderer.textures, objectData.debugPolygons);
} }
this.rootArmature.renderer.putInScene(this, runtimeScene); this.rootArmature.renderer.putInScene(this, runtimeScene);
this.customHitboxes = [];
}; };
// RuntimeObject overwrites // RuntimeObject overwrites
@@ -77,6 +79,9 @@ gdjs.SkeletonRuntimeObject.prototype.getRendererObject = function(){
}; };
gdjs.SkeletonRuntimeObject.prototype.getHitBoxes = function(){ gdjs.SkeletonRuntimeObject.prototype.getHitBoxes = function(){
if(this.hitboxSlot){
return this.hitboxSlot.getPolygons();
}
return [this.rootArmature.getAABB()]; return [this.rootArmature.getAABB()];
}; };
@@ -113,7 +118,7 @@ gdjs.SkeletonRuntimeObject.prototype.setScaleY = function(scaleY){
}; };
gdjs.SkeletonRuntimeObject.prototype.getWidth = function(){ gdjs.SkeletonRuntimeObject.prototype.getWidth = function(){
return this.rootArmature.getDefaultWidth() * this.scaleX; return this.rootArmature.getDefaultWidth() * Math.abs(this.scaleX);
}; };
gdjs.SkeletonRuntimeObject.prototype.setWidth = function(width){ gdjs.SkeletonRuntimeObject.prototype.setWidth = function(width){
@@ -122,7 +127,7 @@ gdjs.SkeletonRuntimeObject.prototype.setWidth = function(width){
}; };
gdjs.SkeletonRuntimeObject.prototype.getHeight = function(){ gdjs.SkeletonRuntimeObject.prototype.getHeight = function(){
return this.rootArmature.getDefaultHeight() * this.scaleY; return this.rootArmature.getDefaultHeight() * Math.abs(this.scaleY);
}; };
gdjs.SkeletonRuntimeObject.prototype.setHeight = function(height){ gdjs.SkeletonRuntimeObject.prototype.setHeight = function(height){
@@ -130,6 +135,17 @@ gdjs.SkeletonRuntimeObject.prototype.setHeight = function(height){
this.setScaleY(height / this.rootArmature.getDefaultHeight()); this.setScaleY(height / this.rootArmature.getDefaultHeight());
}; };
gdjs.SkeletonRuntimeObject.prototype.setDefaultHitbox = function(slotPath){
if(slotPath === ""){
this.hitboxSlot = null;
return;
}
var slot = this.getSlot(slotPath);
if(slot){
this.hitboxSlot = slot;
}
};
// Animation instructions // Animation instructions
gdjs.SkeletonRuntimeObject.prototype.isAnimationPaused = function(){ gdjs.SkeletonRuntimeObject.prototype.isAnimationPaused = function(){
return !this.animationPlaying; return !this.animationPlaying;

View File

@@ -30,7 +30,7 @@ public:
GetObjectMetadata("SkeletonObject::Skeleton") GetObjectMetadata("SkeletonObject::Skeleton")
.SetIncludeFile("Extensions/SkeletonObject/Hsk-tools.js") .SetIncludeFile("Extensions/SkeletonObject/Hsk-tools.js")
.SetIncludeFile("Extensions/SkeletonObject/Gskeletonruntimeobject.js") .AddIncludeFile("Extensions/SkeletonObject/Gskeletonruntimeobject.js")
.AddIncludeFile("Extensions/SkeletonObject/Fskanimation.js") .AddIncludeFile("Extensions/SkeletonObject/Fskanimation.js")
.AddIncludeFile("Extensions/SkeletonObject/Eskarmature.js") .AddIncludeFile("Extensions/SkeletonObject/Eskarmature.js")
.AddIncludeFile("Extensions/SkeletonObject/Dskslot.js") .AddIncludeFile("Extensions/SkeletonObject/Dskslot.js")
@@ -60,6 +60,8 @@ public:
actions["SkeletonObject::SetHeight"].SetFunctionName("setHeight").SetGetter("getHeight"); actions["SkeletonObject::SetHeight"].SetFunctionName("setHeight").SetGetter("getHeight");
expressions["Height"].SetFunctionName("getHeight"); expressions["Height"].SetFunctionName("getHeight");
actions["SkeletonObject::SetDefaultHitbox"].SetFunctionName("setDefaultHitbox");
// Animation instructions // Animation instructions
conditions["SkeletonObject::AnimationPaused"].SetFunctionName("isAnimationPaused"); conditions["SkeletonObject::AnimationPaused"].SetFunctionName("isAnimationPaused");
actions["SkeletonObject::PauseAnimation"].SetFunctionName("setAnimationPaused"); actions["SkeletonObject::PauseAnimation"].SetFunctionName("setAnimationPaused");