I am trying to catch object with mouse using mousejoint. As I am a fool I've stolen the code. But it isnt working or me.
I am getting this errors:
Uncaught TypeError: Object #< ba > has no method 'IsActive' Box2dWeb-2.1.a.3.min.js:236
Uncaught TypeError: Object #< ba > has no method 'SetAwake' Box2dWeb-2.1.a.3.min.js:223
here is the code:
var def = new b2MouseJointDef();
def.bodyA = ground;
def.bodyB = body;
def.target = p;
def.collideConnected = true;
def.maxForce = 1000 * body.GetMass();
def.dampingRatio = 0;
mouse_joint = world.CreateJoint(def);
body.SetAwake(true);
And this is the body
function createBox(world, x, y, width, height, options) {
options = $.extend(true, {
'density' : 1.0 ,
'friction' : 1.0 ,
'restitution' : 0.5 ,
'linearDamping' : 0.0 ,
'angularDamping' : 0.0 ,
'type' : b2Body.b2_dynamicBody
}, options);
var body_def = new b2BodyDef();
var fix_def = new b2FixtureDef();
fix_def.density = options.density;
fix_def.friction = options.friction;
fix_def.restitution = options.restitution;
fix_def.shape = new b2PolygonShape();
fix_def.shape.SetAsBox( width , height );
body_def.position.Set(x , y);
body_def.linearDamping = options.linearDamping;
body_def.angularDamping = options.angularDamping;
body_def.type = options.type;
body_def.userData = options.user_data;
var b = world.CreateBody( body_def );
var f = b.CreateFixture(fix_def);
return b;
}
Maybe someone can help?
Falk
I can answer half of the question:
if I set up the ground with
ground = createBox(world, 4, 1, 4 , 0.5, {type : b2Body.b2_staticBody});
instead with this function:
var bodyDef = new b2BodyDef();
var fixDef = new b2FixtureDef();
fixDef.density = 1.0;
fixDef.friction = 1.0;
fixDef.restitution = 0.5;
fixDef.shape = new b2PolygonShape;
//mention half the sizes
fixDef.shape.SetAsBox(4.00 , .5);
//set the position of the center
bodyDef.position.Set(4.10 , 1);
return world.CreateBody(bodyDef).CreateFixture(fixDef);
then it is working. But why?
Related
I am trying to make a multiple date axis graph in AmCharts 4
I have two inputs from two temperature sensors. The dateAxis is cutted at some value and the values are not properly set.
Any ideas please on what's wrong ?
Here is the graph from first temperature sensor
chart from sensor 1
2.The graph from second temperature sensor
chart from sensor 2
3.The resulting image of both sensors:
chart from both sensors
4.Here is the code:
`
chart.data = chartData;
if (chart.data[0]) {
seriesArray = Object.keys(chart.data[0]);
// TODO: only for occurDate
seriesArray.splice(0, 1);
}
// Create axes
var dateAxis = chart.xAxes.push(new am4charts.DateAxis());
dateAxis.renderer.grid.template.location = 0;
dateAxis.renderer.minGridDistance = 50;
dateAxis.baseInterval = {
"timeUnit": "day",
"count": 1
};
dateAxis.skipEmptyPeriods = true;
// Create value axis
var valueAxis = chart.yAxes.push(new am4charts.ValueAxis());
for(let i=0;i<seriesArray.length;i++){
// Create series
var series = chart.series.push(new am4charts.LineSeries());
series.dataFields.valueY = seriesArray[i];
series.dataFields.dateX = "date";
series.strokeWidth = 2;
series.tensionX = 0.90;
series.name = seriesArray[i];
var bullet = series.bullets.push(new am4charts.Bullet());
bullet.tooltipText = seriesArray[i] + ": {valueY}" + unit;
bullet.adapter.add("fill", function(fill, target){
if(target.dataItem.valueY < 21){
return am4core.color("#D66D6D");
}
return fill;
})
var range = valueAxis.createSeriesRange(series);
range.value = goodRange.min;
range.endValue = 0;
range.contents.stroke = am4core.color("#D66D6D");
range.contents.fill = range.contents.stroke;
range.axisFill.fill = am4core.color("#cccccc");
range.axisFill.fillOpacity = 0.2;
range.grid.strokeOpacity = 0;
var range2 = valueAxis.createSeriesRange(series);
range2.value = 1000000;
range2.endValue = goodRange.max;
range2.contents.stroke = am4core.color("#D66D6D");
range2.contents.fill = range.contents.stroke;
range2.axisFill.fill = am4core.color("#cccccc");
range2.axisFill.fillOpacity = 0.2;
range2.grid.strokeOpacity = 0;
}
// Add scrollbar
var scrollbarX = new am4charts.XYChartScrollbar();
scrollbarX.series.push(series);
chart.scrollbarX = scrollbarX;
chart.cursor = new am4charts.XYCursor();
chart.legend = new am4charts.Legend();
chart.legend.position = "bottom";
chart.legend.scrollable = true;
}`
I want embed a excel file to powerpoint file:
I had try this code, but it can't add object:
// Open the source document as read/write.
using (var presentationDocument = PresentationDocument.Open(strFile, true))
{
var presentationPart = presentationDocument.PresentationPart;
var newSlidePart = GetSlidePartsInOrder( presentationPart).Last();
string datafile = #"F:\AUTOM\t1.xlsx";
ShapeTree tree = newSlidePart.Slide.CommonSlideDatShapeTree;
GraphicFrame graphicFrame = new GraphicFrame();
var embedId = "rId" + (newSlidePart.Slide.Elements().Count() + 1915);
var nonVisualPictureProperties = new NonVisualGraphicFrameProperties(
new NonVisualDrawingProperties { Id = (UInt32Value)4U, Name = "Chart 3" },
new NonVisualGraphicFrameDrawingProperties(),
new ApplicationNonVisualDrawingProperties());
var blipFill = new BlipFill();
var blip = new Blip { Embed = embedId };
// Creates an BlipExtensionList instance and adds its children
var blipExtensionList = new BlipExtensionList();
var blipExtension = new BlipExtension { Uri = "{28A0092B-C50C-407E-A947-70E740481C1D}" };
var useLocalDpi = new UseLocalDpi { Val = false };
useLocalDpi.AddNamespaceDeclaration("a14", "http://schemas.microsoft.com/office/drawing/2010/main");
blipExtension.Append(useLocalDpi);
blipExtensionList.Append(blipExtension);
bliAppend(blipExtensionList);
var stretch = new Stretch();
var fillRectangle = new FillRectangle();
stretch.Append(fillRectangle);
blipFill.Append(blip);
blipFill.Append(stretch);
// Create new Embedded Package Part
EmbeddedPackagePart embPackage = newSlidePart.AddNewPart<EmbeddedPackagePart>("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", embedId);
// Feed imported data from an excel file into the embedded package
embPackage.FeedData(new FileStream(datafile, FileMode.Open, FileAccess.ReadWrite));
var aspectRatio = 1;
// Compute the image's offset on the page (in x and y), and its width cx and height cy.
// Note that sizes are expressed in EMU (English Metric Units)
// const int emusPerCm = 360000;
var cy = 5029200L;
var cx = (long)(cy * aspectRatio);
if (cx > 8229600L)
{
cx = 8229600L;
cy = (long)(cx / aspectRatio);
}
// Creates an ShapeProperties instance and adds its children.
var shapeProperties = new ShapeProperties();
var transform2D = new Transform2D();
var offset = new Offset { X = (9144000L - cx) / 2, Y = 1524000L };
var extents = new Extents { Cx = cx, Cy = cy };
transform2D.Append(offset);
transform2D.Append(extents);
var presetGeometry = new PresetGeometry { Preset = ShapeTypeValues.Rectangle };
var adjustValueList = new AdjustValueList();
presetGeometry.Append(adjustValueList);
shapeProperties.Append(transform2D);
shapeProperties.Append(presetGeometry);
graphicFrame.Append(nonVisualPictureProperties);
graphicFrame.Append(blipFill);
graphicFrame.Append(shapeProperties);
tree.AppendChild(graphicFrame);
// Save the modified presentation.
presentationPart.Presentation.Save();
}
How can embed a excel file to PowerPoint file by OpenXML?
Im trying to loop and remove eventlistener in createjs:
Actor = function() {
this.update = true;
this.offset;
this.instance;
this.member = function(a_obj) {
count++;
this._container = a_obj.container;
this._images = a_obj.images;
this._name = a_obj.name;
this._top = a_obj.top;
this._left = a_obj.left;
getCirTest = new createjs.Bitmap(loader.getResult(this._images));
getCirTest.name = this._name;
getCirTest.y = this._top + 10;
getCirTest.x = this._left + 10;
getCirTest.scaleX = 0.8;
getCirTest.scaleY = 0.8;
getCirTest.cursor = "pointer";
this._container.addChild(getCirTest);
holdsAllObj[count]=getCirTest;
console.log(holdsAllObj);
md = getCirTest.on("mousedown", activate);
function activate(evt) {
myCurrentTarget = evt.currentTarget;
xyCor.push(evt.currentTarget.x, evt.currentTarget.y);
this.parent.addChild(this);
this.offset = {
x: this.x - evt.stageX,
y: this.y - evt.stageY
};
}
pm = getCirTest.on("pressmove", move);
function move(evt) {
myintersect(evt.currentTarget, getCenterBitmap);
this.x = evt.stageX + this.offset.x;
this.y = evt.stageY + this.offset.y;
update = true;
}
cc = getCirTest.on("click", release);
function release (evt) {
countClicks++;
holdsAllObj[1].off("mousedown",md);
holdsAllObj[1].off("pressmove",pm);
console.log();
if (soundPlay == true && countClicks == 1) {
console.log("im true");
mySoundInstance = createjs.Sound.play(evt.currentTarget.name);
mySoundInstance.addEventListener("complete", createjs.proxy(handleSoundComplete, mySoundInstance));
} else {
createjs.Sound.stop(evt.currentTarget.name);
countClicks = 0;
}
console.log(countClicks);
update = true;
}
} //**** END: members ****
}
Its my getCirTest, whichs have an event:
md = getCirTest.on("mousedown", activate);
It´s create 10 instance of a bitmap object like this:
for (var circles = 0; circles < 10; circles++) {
var x = Math.round(container.width / 2 + radius * Math.cos(angle) - 150 / 2);
var y = Math.round(container.width / 2 + radius * Math.sin(angle) - 150 / 2);
var MP = new Actor();
MP.member({
container: container,
images: myFTMImages[circles],
name: myFTMNames[circles],
top: y,
left: x
});
angle += step;
}
My problem is that i would like to remove the eventListeners in a event:
cc = getCirTest.on("click", release);
function release (evt) {
}
Thats why i have put the bitmaps in a array:
holdsAllObj[count]=getCirTest;
And then tried the following:
cc = getCirTest.on("click", release);
function release (evt) {
for(var ijk=0;ijk<holdsAllObj.length;ijk++){
holdsAllObj[ijk].off("mousedown",md);
holdsAllObj[ijk].off("pressmove",pm);
}
}
unfortunately .. it´does not work for me ...
This looks like an issue with js scope. JS methods are called in the window context rather than the context they are created. You can use the createjs.proxy method to apply a scope to a method call, like this:
cc = getCirTest.on("click", release, this);
Hope that helps.
Issue already posted here. http://community.createjs.com/discussions/easeljs/22315-domelement-remove-transformsscale
Having problems using DOMElement after I adjust the canvas for devicePixelRatio.
Code looks something like:
stage.canvas.width = width * scalingFactor
stage.canvas.height = height * scalingFactor
stage.canvas.style.width = width
stage.canvas.style.height = height
This gives me nice crisp text on retina screens.
However, positions of DOMElements are now off.
Any ideas? Is this a known error?
Cheers,
Matt.
I ended up with extending the default DOMElement with something like that:
var DOMElement = function(htmlElement) {
this.DOMElement_constructor(htmlElement);
this.globalScale = CanvasUtils.getScale();
this.acceleratedCompositing = Modernizr.csstransforms3d;
};
var p = createjs.extend(DOMElement, createjs.DOMElement);
/**
* #override
*
* Overrides default createjs DOMElement.
*
* overrides _handleDrawEnd
* Sets 3d transform (translateZ)
*/
p._handleDrawEnd = function(evt) {
var o = this.htmlElement;
if (!o) { return; }
var style = o.style;
var props = this.getConcatenatedDisplayProps(this._props), mtx = props.matrix;
// use display instead of visibility
var display = props.visible ? '' : 'none';
if (display != style.display) { style.display = display; }
if (!props.visible) { return; }
var oldProps = this._oldProps, oldMtx = oldProps&&oldProps.matrix;
var n = 10000; // precision
if (!oldMtx || !oldMtx.equals(mtx)) {
var str = '';
if(this.acceleratedCompositing) {
str += 'translateZ(0)';
}
str += "matrix(" + (mtx.a*n|0)/n / this.globalScale +","+ (mtx.b*n|0)/n +","+ (mtx.c*n|0)/n +","+ (mtx.d * n|0)/n / this.globalScale+","+ (mtx.tx + 0.5|0) / this.globalScale;
style.transform = style.WebkitTransform = style.OTransform = style.msTransform = str +","+ (mtx.ty+0.5|0) / this.globalScale +")";
style.MozTransform = str +"px,"+ (mtx.ty+0.5|0) / this.globalScale +"px)";
if (!oldProps) { oldProps = this._oldProps = new createjs.DisplayProps(true, NaN); }
oldProps.matrix.copy(mtx);
}
if (oldProps.alpha != props.alpha) {
style.opacity = ""+(props.alpha*n|0)/n;
oldProps.alpha = props.alpha;
}
};
createjs.DOMElement = createjs.promote(DOMElement, "DOMElement");
I am have difficulty getting drop and drop to work using Starling with feathers ui.
Here is my code:
function begin(){
var quadx = squareSize/4 + squareSize/8;
var quady = 20;
var quadcounter = 0;
for(var f=0;f<totalsquares;f++){
var sprite:Sprite = new Sprite();
var quad:Quad = new Quad(squareSize, squareSize);
sprite.name = "" + f;
spriteunder.name = "" + f * 1000;
quad.setVertexColor(0, 0x3683ed);
quad.setVertexColor(1, 0x3683ed);
quad.setVertexColor(2, 0x3683ed);
quad.setVertexColor(3, 0x3683ed);
sprite.x=quadx;
sprite.y = quady;
var lv3 = new TextField(squareSize, squareSize, f,"Corpid", 14,0xf1f1f1);
sprite.touchable = true;
quad.touchable = true;
lv3.touchable = false;
sprite.addChild(quad);
sprite.addChild(lv3);
addChild(sprite);
sprite.addEventListener(TouchEvent.TOUCH, touchHandler);
quadx = quadx + squareSize + 1;
quadcounter++;
if(quadcounter == boardWidth){
quadx = squareSize/4 + squareSize/8;
quady = quady + squareSize + 1;
quadcounter = 0;
}
}
}
function touchHandler(e : TouchEvent) : void
{
var touch:Touch = e.getTouch(stage);
var position:Point = touch.getLocation(stage);
var target:Quad = e.target as Quad;
if(touch.phase == TouchPhase.MOVED ){
target.x = position.x - target.width/2;
target.y = position.y - target.height/2;
}
}
The problem is that whenever i run this , its the QUAD child that gets dragged around, not the parent sprite.
What do i change in order to get this to drag correctly.
Perhaps you must start with
var touch:Touch = event.getTouch(this, TouchPhase.BEGAN);
if (touch)
{
//get and lock your target, maybe a trace of your actual target, just to be sure!
}
And then in the MOVED phase, actually drag it.