Trouble with obstacles (cocos2d-x / C++)

Started by
2 comments, last by Breve 8 years, 1 month ago

Hey there!

Works pretty well in top and button (like the image), just i want the same but to left and right...

e636b01075a1c3a9.jpg


#include "Pipe.h"
#include "Definitions.h"

USING_NS_CC;

Pipe::Pipe( )
{
    visibleSize = Director::getInstance( )->getVisibleSize( );
    origin = Director::getInstance( )->getVisibleOrigin( );
}

void Pipe::SpawnPipe( cocos2d::Layer *layer )
{
    CCLOG( "SPAWN PIPE" );
    
    auto topPipe = Sprite::create( "Pipe.png" );
    auto bottomPipe = Sprite::create( "Pipe.png" );
    
    auto topPipeBody = PhysicsBody::createBox( topPipe->getContentSize( ) );
    auto bottomPipeBody = PhysicsBody::createBox( bottomPipe->getContentSize( ) );
    
    auto random = CCRANDOM_0_1( );
    
    if ( random < LOWER_SCREEN_PIPE_THRESHOLD )
    {
        random = LOWER_SCREEN_PIPE_THRESHOLD;
    }
    else if ( random > UPPER_SCREEN_PIPE_THRESHOLD )
    {
        random = UPPER_SCREEN_PIPE_THRESHOLD;
    }
    
    auto topPipePosition = ( random * visibleSize.height ) + ( topPipe->getContentSize( ).height / 2 );
    
    topPipeBody->setDynamic( false );
    bottomPipeBody->setDynamic( false );
    
    topPipe->setPhysicsBody( topPipeBody );
    bottomPipe->setPhysicsBody( bottomPipeBody );
    
    topPipe->setPosition( Point( visibleSize.width / 2 + topPipe->getContentSize().width + origin.x + CCRANDOM_MINUS1_1() * 250, topPipePosition ) );
    bottomPipe->setPosition( Point( topPipe->getPositionX(), topPipePosition - ( Sprite::create( "Ball.png" )->getContentSize( ).height * PIPE_GAP ) - topPipe->getContentSize().height ) );
    
    layer->addChild( topPipe );
    layer->addChild( bottomPipe );
}

I do not know if the problem it is here, but i think yes, IF YOU NEED A OTHER PART OF THE CODE, JUST TELL ME.

I REALLY APPRECIATE ALL THE HELP

Advertisement
It not clear what you are asking. Do you want to create horizontal pipes as well?
My current game project Platform RPG

No, I just want replace the vertical pipes for horizontal pipes, and these works the same form like the vertical but in horizontal.

It not clear what you are asking. Do you want to create horizontal pipes as well?

No, I just want replace the vertical pipes for horizontal pipes, and these works the same form like the vertical but in horizontal.

This topic is closed to new replies.

Advertisement