Hi guys!
My knowledge of English language doesn't allow me to understand completely that is written in documentation.
Also I can not understand with new b2ContactListenerClass
How to make a jump in 2.1a version like in this tutorial for 2.0
this is my example of code.
its Working but then my hero start to contact with new tile there is something strange. "var canjump" did not set in "true".

My knowledge of English language doesn't allow me to understand completely that is written in documentation.
Also I can not understand with new b2ContactListenerClass
How to make a jump in 2.1a version like in this tutorial for 2.0
Code:
Box2D.Dynamics{
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2ContactListener {
var canjump:Boolean=false;
/// Called when a contact point is added. This includes the geometry
/// and the forces.
public function can_jump() {
return (canjump);
}
public virtual function Add(point:b2ContactPoint):void {}
/// Called when a contact point persists. This includes the geometry
/// and the forces.
public virtual function Persist(point:b2ContactPoint):void {
if (point.shape1.GetUserData()=="groundsensor"||point.shape2.GetUserData()=="groundsensor") {
canjump=true;
}
}
/// Called when a contact point is removed. This includes the last
/// computed geometry and forces.
public virtual function Remove(point:b2ContactPoint):void {
if (point.shape1.GetUserData()=="groundsensor"||point.shape2.GetUserData()=="groundsensor") {
canjump=false;
}
}
/// Called after a contact point is solved.
public virtual function Result(point:b2ContactResult):void {
}
}
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2ContactListener {
var canjump:Boolean=false;
/// Called when a contact point is added. This includes the geometry
/// and the forces.
public function can_jump() {
return (canjump);
}
public virtual function Add(point:b2ContactPoint):void {}
/// Called when a contact point persists. This includes the geometry
/// and the forces.
public virtual function Persist(point:b2ContactPoint):void {
if (point.shape1.GetUserData()=="groundsensor"||point.shape2.GetUserData()=="groundsensor") {
canjump=true;
}
}
/// Called when a contact point is removed. This includes the last
/// computed geometry and forces.
public virtual function Remove(point:b2ContactPoint):void {
if (point.shape1.GetUserData()=="groundsensor"||point.shape2.GetUserData()=="groundsensor") {
canjump=false;
}
}
/// Called after a contact point is solved.
public virtual function Result(point:b2ContactResult):void {
}
}
this is my example of code.
Code:
package
{
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
import Box2D.Common.Math.*;
/**
* ...
* @author JiMKE
*/
public class custom_contact_listener extends b2ContactListener
{
public var canjump:Boolean = false;
public function can_jump():Boolean {
return (canjump);
}
override public function BeginContact(contact:b2Contact):void
{
// getting the fixtures that collided
var fixtureA:b2Fixture = contact.GetFixtureA();
var fixtureB:b2Fixture = contact.GetFixtureB();
if (fixtureA.IsSensor() || fixtureB.IsSensor()){
if (fixtureB.GetUserData() == "groundsensor" || fixtureA.GetUserData() == "groundsensor") {
canjump = true;
}
}
}
override public function EndContact(contact:b2Contact):void
{
// getting the fixtures that collided
var fixtureA:b2Fixture = contact.GetFixtureA();
var fixtureB:b2Fixture = contact.GetFixtureB();
if (fixtureA.IsSensor() || fixtureB.IsSensor()){
if (fixtureB.GetUserData() == "groundsensor" || fixtureA.GetUserData() == "groundsensor") {
canjump = false;
}
}
}
}
}
{
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
import Box2D.Common.Math.*;
/**
* ...
* @author JiMKE
*/
public class custom_contact_listener extends b2ContactListener
{
public var canjump:Boolean = false;
public function can_jump():Boolean {
return (canjump);
}
override public function BeginContact(contact:b2Contact):void
{
// getting the fixtures that collided
var fixtureA:b2Fixture = contact.GetFixtureA();
var fixtureB:b2Fixture = contact.GetFixtureB();
if (fixtureA.IsSensor() || fixtureB.IsSensor()){
if (fixtureB.GetUserData() == "groundsensor" || fixtureA.GetUserData() == "groundsensor") {
canjump = true;
}
}
}
override public function EndContact(contact:b2Contact):void
{
// getting the fixtures that collided
var fixtureA:b2Fixture = contact.GetFixtureA();
var fixtureB:b2Fixture = contact.GetFixtureB();
if (fixtureA.IsSensor() || fixtureB.IsSensor()){
if (fixtureB.GetUserData() == "groundsensor" || fixtureA.GetUserData() == "groundsensor") {
canjump = false;
}
}
}
}
}
its Working but then my hero start to contact with new tile there is something strange. "var canjump" did not set in "true".
