incompl / boxbox Goto Github PK
View Code? Open in Web Editor NEWjavascript physics made easy
Home Page: http://incompl.github.com/boxbox/
License: Other
javascript physics made easy
Home Page: http://incompl.github.com/boxbox/
License: Other
In .createWorld gravity is y only. In .gravity it is an x,y vector.
Right now you can say "color" but all border color
Just wasted a bunch of time trying to get grunt 0.4 working, not realizing the project needs 0.3.
If there's interest, I wouldn't mind migrating the build system to grunt 0.4, although it's more complex.
Right now box2d just allows broken objects to exist
I cant seem to figure out how to render a sprite using a sprite sheet when creating entities
What I have tried
var x = world.createEntity({
name: 'player' + getRandomInt(100, 100000),
x: baseX + pos.x,
y: baseY + pos.y,
height: 18,
width: 10,
friction: .3,
image: "assets/sprites.png",
spriteSheet: true,
spriteWidth: 10,
spriteHeight: 18,
spriteX: 425,
spriteY: 5,
fixedRotation: true,
restitution: 50
});
have also tried, for fun
var x = world.createEntity({
name: 'player' + getRandomInt(100, 100000),
x: baseX + pos.x,
y: baseY + pos.y,
height: 18,
width: 10,
friction: .3,
spriteSheet: sheetImgObj,
spriteWidth: 10,
spriteHeight: 18,
spriteX: 425,
spriteY: 5,
fixedRotation: true,
restitution: 50
});
but all I get is empty sprites. Any help on this would be greatly appreciated
(function() {
if (window.DeviceOrientationEvent) {
console.log("DeviceOrientation is supported");
}
var canvasElem = document.getElementById("myCanvas");
var canvasElem = document.getElementById("myCanvas");
var world = boxbox.createWorld(canvasElem, {
gravity: {x: 0, y: 20},
scale: 60
});
})();
in console Chrome Uncaught TypeError: Cannot read property 'getContext' of null
in console Firefox TypeError: this._canvas is null
API needs to be determined
If I try to add a background image to an entity, the image is displayed on a completely wrong position. The Image has a size of 100x100px and I use imageStretchToFit for scaling.
My code looks like the following:
var canvas = document.getElementById("canvas"),
world = boxbox.createWorld(canvas);
var floor = world.createEntity({
width: 35,
height: 0.5,
color: "#000000"
}, {
x: 0,
y: 16,
type: "static"
});
var torso = world.createEntity({
width: 5,
height: 5,
// screenshot 1:
/*color: "#FF0000",
borderColor: "#FF0000",
borderWidth: 1,*/
// screenshot 2
image: "background.png",
imageStretchToFit: true
}, {
x: 3,
y: 7,
type: "dynamic"
});
What am I doing wrong?
Here's some draw code for an entity:
draw: function(ctx, x, y) {
ctx.strokeStyle = "black";
ctx.lineWidth = 10;
ctx.fillStyle = "rgba(128,0,128,0.5)";
ctx.beginPath();
ctx.arc(this.canvasPosition().x,this.canvasPosition().y,40,0,Math.PI*2,true);
ctx.closePath();
ctx.stroke();
ctx.fill();
}
I shouldn't have to type "this.canvasPosition().x" in the draw function, it should pass "cpx, xpy" or something. Regular x and y are not very useful here in a draw context.
PLEAAAAAAZE HALP
Updating an entity's position during a collision callback (onImpact or onStartContact) doesn't seem to have any effect.
No significant updates in 3 years. I get the feeling that you got tired of it. For a project of this size, I can understand that. But if so, that's too bad. boxbox was simple, well documented and therefore a pleasure to work with.
if the world is locked, boxbox should defer entity creation for you
Vector x y passed to _toVector do not get multiplied by power.
I was looking for the json object to load in canvas which is generated by physics body editor. But I was not able to find any example in your document if it's possible.
Expose it if necessary
Hi,
I'm new to Box2D and I find your project really useful. There is one issue, though. The latest submit to github is producing artifacts on rendering.
I'm not sure where the issue resides but it must be easy for you to find. To get an idea what I'm talking about, compare the version you are using in your demos and the one in source. I tried on latest versions of Firefox and Chrome.
Here are the links:
http://incompl.github.io/boxbox/boxbox/demos/chain/chain.html
https://rawgithub.com/incompl/boxbox/master/demos/chain/chain.html
jQuery is on to something here
The IIFE that defines window.boxbox does return this
, which means that boxbox's entire API is extended onto the window
object. This doesn't strike me as the intent here, it should only return the boxbox API itself.
These are ways to filter collisions in box2d. boxbox should provide a more friendly API that doesn't involve doing bit math etc.
The problem is with:
gravity: function(value) {
if (value !== undefined) {
this._world.SetGravity(new b2Vec2(value.x, value.y));
}
var v = this._world.GetGravity();
return {x: v.x, y: v.y};
},
I had to change
this._world.SetGravity(new b2Vec2(0, value));
to
this._world.SetGravity(new b2Vec2(value.x, value.y));
It asks for {x,y} but if you send in {x: 0, y: 20} for example, it thinks y is now an object until the above fix is applied.
It doesn't scale when the world scales
Creating a polygon and setting it's origin location as x:1, y:1 actually positions the element at x:2, y:2
Is this something I am missing in the creation of a polygon, or a bug in how they are created?
may be a box2d limitation, should report error at least though
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.