Jump Script Error

Jump Script Error

Hi everyone,

I wrote a code for jumping. But it gives this error.

I upload all my classes to github

Please post code inline instead of screenshots. We can easy cut and paste to test if we don’t see an obvious errors.

What is the scope of origin?

Coding advice, it is better to implement boolean values into the conditional brackets in such a manner:

Unideal: isFalling == false
Ideal: !isFalling
if true:
Unideal: isFalling == true
Ideal: isFalling

Can you explain where you see this as being ideal and un-ideal? I see it both ways through out various projects I work with. I do usually fo if (isFalling) or if( !isFalling).

It has nothing to do with parsing or code generation or anything like that.

It is because of the way C (and C++) handles expressions, and the slippery-slope for bad code that such constructs encourage.

In this case specifically, C has traditionally not had a boolean data type. Writing if (x == FALSE) has never been a problem – it is when you then write things like if (x ==TRUE) when things go wrong.

Consequently, the conventional (and correct) wisdom is to let the compiler do its job properly performing implicit boolean conversions as a last step without your help.

That, and the truthiness of the statement is considered both obvious and cleaner to read without the extra verbiage.

if (x) ... if (!x) ...

Both are short, sweet, and to the point without ambiguity, just like C (and C++) programmers like it.

Hope this helps.

I solved the first problem. Game works fine but still it doesn’t jump. I upload all the classes on GitHub https://github.com/Refetizm/forriza . I think the problem is in Character.cpp file. Here are the codes:

#include "Character.h"
#include "Definitions.h"
#include "SimpleAudioEngine.h"


Character::Character(cocos2d::Layer* layer)
	SpriteBatchNode* charBatchNode = SpriteBatchNode::create("Character.png");
	SpriteFrameCache* frameCache = SpriteFrameCache::getInstance();
	mainChar = Sprite::createWithSpriteFrameName("wlk1.png");
	mainChar->setAnchorPoint(Vec2(0.5f, 0.0));
	charBatchNode->setAnchorPoint(Vec2(0.0, 0.0));
	charBatchNode->setPosition(Point(960, 100));
	auto charBody = PhysicsBody::createBox(mainChar->getContentSize(), PhysicsMaterial(0, 1, 0));
	layer->addChild(charBatchNode, 5);

	for (int i = 1; i <= 6; i++)
		std::string frameName = cocos2d::StringUtils::format("wlk%d.png", i);
		SpriteFrame* frame = frameCache->getSpriteFrameByName(frameName.c_str());

	Animation* animation = Animation::createWithSpriteFrames(frames, 0.1f);
	auto animate = Animate::create(animation);
	isFalling = false;


void Character::Fall()
	if (true == isFalling)
		mainChar->setPositionX(visibleSize.width / 2 + origin.x);
		mainChar->setPositionY(mainChar->getPositionY() - (CHAR_FALLING_SPEED * visibleSize.height));
		mainChar->setPositionX(visibleSize.width / 2 + origin.x);
		mainChar->setPositionY(mainChar->getPositionY() + (CHAR_FALLING_SPEED * visibleSize.height));
1 Like

Where do you think you are having the character jump in your code?

Character.cpp -> Line 42 between 54 and Line 38
Character.h -> Line 10 between 12 and Line 18
GameScene.h -> Line 27 between 30
GameScene.cpp -> Line 130 between 135 and Line 160 between 178.
All these code lines are about character jump and fall. I took these codes from a tutorial. The only difference between education and my writing is that I use spritesheet animation.

I’m not looking at your repo I don’t have time to look through all of your code. Look at cpp-tests for examples.

Thank. A see a lot of projects doing this.