Scrolling Background With Android

  • guigiron
    Likes 0

    Problem Description

    Hey… Whats up? ;) 

    My vacations is bad… i see the video of scrolling background for iphone in youtube but in my code (android) not work… I dont know Why….

    The code here:

           

           this.background.setAnchorPoint(CGPoint.ccp(0, 0));

            this.background2 = new ScreenBackground(Assets.BACKGROUND);
            this.background2.setAnchorPoint(CGPoint.ccp(0, 0));
            this.background2.setPosition(CGPoint.ccp(0, this.win_size.height));

            this.addChild(background);
            this.addChild(background2);
            
            CCRepeatForever sprite_action = CCRepeatForever.action(CCMoveBy.action(2.0f, CGPoint.ccp(0, -this.win_size.height)));
            this.background.runAction(sprite_action);

            CCRepeatForever sprite_action_2 = CCRepeatForever.action(CCMoveBy.action(2.0f, CGPoint.ccp(0, -this.win_size.height)));
            this.background2.runAction(sprite_action_2);
            
            this.scheduleUpdate();

     

    public void update(float dt) {
            
            if (this.background.getPosition().y <= -this.win_size.height + 1){
                this.background.setPosition(0, this.win_size.height);
            }        
            
            if (this.background2.getPosition().y <= -this.win_size.height + 1) {
                this.background2.setPosition(0, this.win_size.height);
            }
        

    If someone can help! Thanks!

  • Sonar Systems admin
    Likes 0

    Does anything appear at all.

  • guigiron
    Likes 0

    sorry.. i dont understand… 

  • Sonar Systems admin
    Likes 0

    Does anything appear on the screen?

  • guigiron
    Likes 0

    Picture rolls 3 Seconds and then the image disappears, and the screen return to black without a imagem… The scrolling background works 2 seconds but after this the screen of android stay black..
  • Sonar Systems admin
    Likes 0

    Try putting logs inside the if statement in update to see if it gets inside it or not.

  • guigiron
    Likes 0

    it is within the 2 ... but if not this simply by setting the position ..
  • Sonar Systems admin
    Likes 0

    ?              

  • guigiron
    Likes 0

    he falls into the condition but does not position the image
  • Sonar Systems admin
    Likes 0

    Try setting the position to a hard coded value to see if that works.

  • guigiron
    Likes 0

    i test this, and its work…. But the problem of scrolling background persist….

    Picture rolls 3 Seconds and then the image disappears, and the screen return to black without a imagem… The scrolling background works 2 seconds but after this the screen of android stay black..
  • Sonar Systems admin
    Likes 0

    Where did you set the hard coded position?

  • guigiron
    Likes 0

    yes, i set in hard position its work.. but scrolling not..

    I'll show a problem of video and post the link here
  • Sonar Systems admin
    Likes 0

    OK, I will wait for the video.

  • guigiron
    Likes 0

  • Sonar Systems admin
    Likes 0

    What framework are you using as you are coding in Java?

  • guigiron
    Likes 0

    cocos2d

  • Sonar Systems admin
    Likes 0

    Cocos2d-java?

  • guigiron
    Likes 0

  • Sonar Systems admin
    Likes 0

    Our tutorial is for Cocos2d-x sorry, use Cocos2d-x it is better plus we have a book covering it https://www.packtpub.com/game-development/cocos2d-x-game-development-essentials plus have hundreds of video tutorials.

  • guigiron
    Likes 0

    but the logic should be the same no ? 
     really want to do this with cocos2d as already fully created the project .. 
    only need this routine working to continue
  • Sonar Systems admin
    Likes 0

    Should be but its hard for us to help as there could be ther factors outside of our code logic affecting the outcome.

  • guigiron
    Likes 0

    its stranger, because 2 seconds its work… but after this.. the background its crash :/

  • Sonar Systems admin
    Likes 0

    Crash, I thought you said it disappeared?

  • guigiron
    Likes 0

    sorry, my english not too good.. Its disappeared…

    I test everyday but not works! :/ 

     

  • Sonar Systems admin
    Likes 0

    OK

     

    We recommend you switch to Cocos2d-x as it has greater performance, more fetaures, faster and better updates plus we can help ont that.

  • guigiron
    Likes 0

    but if I change to cocos2d - x will cause errors the rest of the project ?

    I not know how this its works… 

  • Sonar Systems admin
    Likes 0

    It will, you will need to port your game over.

  • guigiron
    Likes 0

    :/ big problem…    i cant do that… because i not know how works cocosd2-x and my inspiration is a book...

Login to reply