Problem on Parkour Tutorial

Hi all I got into a problem following this tutorial I’m on the chipmunk section but when I get to this point I get an error:  this.sprite.setBody is not a function  What can I do to fix?

Hey, I don’t know how u r using it… But the code seems to be fine.
Also, are you sure there isn’t any mistake in writing this statement or position where u r writing it. I hope the ‘sprite’ is a correct variable which is receiving actual sprite using new cc.PhysicsSprite("#runner0.png"); .
I guess u might have forget new keyword…
Also one more thing, can u download the entire source code of Parkour and check whether it is working fine on your system.
I faced no problem

Hi thanks for your reply Im using Cocos IDE latest version to date, and this is my code below:

var AnimationLayer = cc.Layer.extend({

spriteSheet:null,
    runningAction:null,
    sprite:null,
    space:null,
    body:null,
    shape:null,
    
    
    ctor:function (space) {
        this._super();
        this.space = space;
        this.init();
    },
    
    init:function () {
        this._super();
        
        cc.spriteFrameCache.addSpriteFrames(res.runner_plist);
        this.spriteSheet = cc.SpriteBatchNode.create(res.runner_png);
        this.addChild(this.spriteSheet);
        
        var animFrames = [];
        for (var i = 0; i < 8; i++) {
            var str = “runner” + i + “.png”;
            var frame = cc.spriteFrameCache.getSpriteFrame(str);
            animFrames.push(frame);
        }
        
        var animation = cc.Animation.create(animFrames, 0.1);
        this.runningAction = cc.RepeatForever.create(cc.Animate.create(animation));
        this.sprite = cc.Sprite.create("#runner0.png");
        
        var contentSize = this.sprite.getContentSize();
        
        this.body = new cp.Body(1, cp.momentForBox(1, contentSize.width, contentSize.height));
        
        this.body.p = cc.p(g_runnerStartx, g_groundHight + contentSize.height / 2);
        
        this.body.applyImpulse(cp.v(150, 0), cp.v(0, 0));
        
        this.space.addBody(this.body);
        
        this.shape = new cp.BoxShape(this.body, contentSize.width - 14, contentSize.height);
        
        this.space.addShape(this.shape);
        
        this.sprite.setBody(this.body);
        
        this.sprite.runAction(this.runningAction);
        
        this.spriteSheet.addChild(this.sprite);
    
    }
    
});

Also this is my project json:

{

“project_type”:“javascript”,
    “debugMode”:1,
    “showFPS”:true,
    “frameRate”:60,
    “id”:“gameCanvas”,
    “renderMode”:0,
    “engineDir”:“frameworks/cocos2d-html5”,
    “modules”:[
        “cocos2d”, “chipmunk”
    ],
    “jsList”:[
        “src/resource.js”,
        “src/app.js”,
        “src/AnimationLayer.js”,
        “src/BackgroundLayer.js”,
        “src/PlayScene.js”,
        “src/StatusLayer.js”,
        “src/globals.js”
    ]
}

@rhasce

Hey… hi… I don’t why I didn’t get any notifications for this post when you commented back.
I hope you’ev used Reply option on my post and not yours!!
Anyways,
I guess, you’ve not seen my last comment properly.
The problem with your code is that you sprite is not physicsSprite but a simple sprite.
And since simple sprite doesnot have any setBody function so that is why it is telling you that the function doesnot exist.

I am not seeing that what is the definition of the sprite… I guess parkour tutorial must have used physicsSprite if it is using setBody with that…

This is the only problem but if you still aren’t able to figure out then we can discuss your code further

Change there Sprite to physicsSprite