javascript testbed.js

General discussion about the R.U.B.E editor
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

javascript testbed.js

Post by vkreal »

Hi iforce2d,

something weird in your testbed.js

createWorld function contain
world = new b2World(new b2Vec2(0.0, -10.0));
i believe it should be world = new b2World(new b2Vec2(0.0, 10.0));

and also in draw function with context.scale(1, -1); i believe it should be context.scale(1, 1);

it seems you have to flip to make it work correctly. anyway around this? maybe output json so dont have to scale -1 and reverse gravity? it would be hard to use your tool with other javascript game framework
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: javascript testbed.js

Post by iforce2d »

Where I live gravity makes things move down, but I guess in a game it's a matter of preference :)

You say the testbed is not working correctly... what is the problem exactly?

I think for most people it's easier to create and test scenes in the editor using a gravity that pushes things down. Depending on how you are displaying the output, you may have to flip the scene when rendering, eg. OpenGL requires no changes, but like you say Javascript needs a vertical flip. Most rendering APIs provide an easy way to to this, eg. glScalef in OpenGL or context.scale in Javascript or Android canvas.

I'm not too familiar with any Javascript game frameworks. What things are hard to integrate with them when the physics gravity points downwards?
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Re: javascript testbed.js

Post by vkreal »

Hi iforce2d,

Any way around not vertical flip using context.scale in Javascript? RIght now it seems like to make the terrain work correctly i have to flip terrain bodies. I am very new so forgive my stupidity.

https://dl.dropbox.com/u/16150797/terrain.html


You can look at emanueleferonato code and he has to prevent upside down in his code with 'JSONLoaded' method.

http://www.emanueleferonato.com/2012/12 ... -projects/

This will be a huge problem integrating RUBE.



\Thanks!
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: javascript testbed.js

Post by iforce2d »

I don't really understand the problem. As I said you can use the scale feature of most rendering APIs to flip everything when rendering. And as you said, the terrain works if you flip the terrain bodies. So forgive me for repeating, but what exactly is the problem? If the problem is just that you need to put a minus sign in your code somewhere, I don't think that is so much work.

You could of course alter the loading functions so that all the dimensions are reversed on loading, but this will require a lot of changes to many things like joint anchors, joint limits, body velocities etc. It would be a lot more work than just using flipping the context scale.
vkreal
Posts: 66
Joined: Sun Jan 13, 2013 7:29 pm

Re: javascript testbed.js

Post by vkreal »

iforce thanks for the help! one more question...how can i prevent the back wheel from pushing up when going off a hill? is it just some kind of configurations on bodies I have to play with? any ideas would be greatly appreciated!

https://dl.dropbox.com/u/16150797/endlessTerrain.html
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: javascript testbed.js

Post by iforce2d »

hey, nice demo!

I think the body of the bike gets turned around like that mainly because the back wheel spinning sets up some kind of gyroscope-like reaction. I'm not sure if you can completely fix it, because the best way to fix it is make the wheels very light compared to the main body, but if you make them too light they will have trouble holding up the main body.

It can help to add a 'keel' fixture to the main body, down below it to make the center of mass much lower, and help the bike to land the right way up, most of the time:
Image
Obviously, you would need to set the collision filter so that this keel doesn't collide with anything ;)
Abhishek
Posts: 5
Joined: Thu Feb 21, 2013 6:49 am

Re: javascript testbed.js

Post by Abhishek »

context.scale isnt working for me. Is there a better way???
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: javascript testbed.js

Post by iforce2d »

Abhishek wrote:context.scale isnt working for me. Is there a better way???
Could you explain a little about what is not 'working'? Do the examples work? Maybe you could think about what the difference is between them and your source code.
Abhishek
Posts: 5
Joined: Thu Feb 21, 2013 6:49 am

Re: javascript testbed.js

Post by Abhishek »

i was running one of the sample projects itself (jack in the box), My problem is as follows-
I want to develop only the physics bodies in R.U.B.E, i want to attach all the images and interactions will be handled by my code. But because html n javascript use a different co-ordinate system i am facing problems. So i need your help.


And when i do context.scale, nothing is visible
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Re: javascript testbed.js

Post by iforce2d »

I'm still not clear... let's start from the beginning: does the jack-in-the-box example work?
Post Reply