Click on sprite JS

  • webkuk
    Likes 0

    Problem Description

    Im doing class


    var Cell = cc.Node.extend({
        ctor: function(x,y){
            this._super();
      
            this.setPosition(x, y);
            
            card = ccs.load(res.cardNode).node;
            cardCover = card.getChildByName('card');
            
            cc.eventManager.addListener(cc.EventListener.create({
                event: cc.EventListener.MOUSE,
                
                onMouseUp: function (event) {         
                    var target = event.getCurrentTarget();
                    target.setVisible(false);
                }
            
            }), cardCover);
            
            this.addChild(card);
        }
    });

    After this add some cells on my scene and when im clicked ALL sprites hided. What im doing wrong?

  • Sonar Systems admin
    Likes 0

    What is target?

  • webkuk
    Likes 0

    target is sprite. one from 2 in node

  • Sonar Systems admin
    Likes 0

    How have you created both of the sprites?

  • webkuk
    Likes 0

    In Cocos Studio

  • Sonar Systems admin
    Likes 0

    Could you show us a screenshot of Cocos Studio?

  • webkuk
    Likes 0

    http://i66.fastpic.ru/big/2015/0304/3a/aa75192f5397cab1583f87f6a709ed3a.jpg


  • Sonar Systems admin
    Likes 0

    How are you retrieving the target Sprite in code?

  • webkuk
    Likes 0

    in my first post
            card = ccs.load(res.cardNode).node;
            cardCover = card.getChildByName('card');

  • webkuk
    Likes 0

    u can tell me how add click callback function on sprite ?

  • Sonar Systems admin
    Likes 0

    You generally want to add a callback function on a button not a sprite

     

    like so

     

    http://cocos.sonarlearning.co.uk/v1.0/docs/widgets-button

  • webkuk
    Likes 0

    If Button, how use callback feature from Cocos Studio?

  • Sonar Systems admin
    Likes 0

    Check that link out that I sent you.

  • webkuk
    Likes 0

    yes,thx, im read this, but it example for touches, but im need for mouse click

  • webkuk
    Likes 1

    sry, my bad,  it works fine. Big THX

  • Sonar Systems admin
    Likes 0

    Your very welcome and don’t forget to post any other questions you may have.

     

    Kind regards

    Sonar Team

  • webkuk
    Likes 0

    hi )) how easy play animation from cocos studio in my code?

  • Sonar Systems admin
    Likes 0

    You can use armature from custom objects which will be covered in our Cocos Studio tutorial series. You can see the status/timeline of our Cocos Studio tutorial series using the link below:

     

    http://www.sonarlearning.co.uk/questions.php?question-topic=40

  • webkuk
    Likes 0

    https://drive.google.com/open?id=0B4S6wwcC-ZSUY1M0eVQ2Um5PX3M&authuser=0

    Look my example, how play this animation in code?

  • Sonar Systems admin
    Likes 0

    It wouldn’t open for me. What are you trying to achieve?

  • webkuk
    Likes 0

    u cant download file or open it? im trying load node with animation(without armature) and play it in my project

  • Sonar Systems admin
    Likes 0

    It won’t open, what sort of animation are you trying to play?

  • webkuk
    Likes 0

    https://drive.google.com/open?id=0B4S6wwcC-ZSUZFFCcjQzVlpLVm8&authuser=0

    this json file for my node, basic scale animation in timeline

  • Sonar Systems admin
    Likes 0

    Using an action will be easier for this http://cocos.sonarlearning.co.uk/v1.0/docs/actions


  • webkuk
    Likes 0

    yes i know it, but i need cocos studio for faster creating animation for many sprites. It is possible? How do action sequence with 2 parallel actions + 2 parallel actions?

  • Sonar Systems admin
    Likes 0

    For simple animations just use actions.

  • webkuk
    Likes 0

    what about sequence?

  • Sonar Systems admin
    Likes 0

    Do you want to run them at the same time or one after another once the previous action has completed?

  • webkuk
    Likes 0

    i need ScaleTo + RotateTo in paralell for one sprite, after finish this again ScaleTo + RotateTo

  • Sonar Systems admin
    Likes 0

    Just run 2 actions on 2 separate lines and they will run at the same time.

  • webkuk
    Likes 0

    I'm confused (( this method for cocos studio? I meant how to do this with actions.

  • Sonar Systems admin
    Likes 0

    Something like this do with code.

  • webkuk
    Likes 0

    thx, i did it

  • Sonar Systems admin
    Likes 0

    Great to hear :D

     

    Feel free to post any new questions you have as new questions.

  • webkuk
    Likes 0

    Yep, i like teach this biutiful game engine and I dont hesitate to ask any questions laugh

Login to reply