Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use spawn action like cocos2d-x #4

Closed
kk167 opened this issue May 2, 2017 · 6 comments
Closed

How to use spawn action like cocos2d-x #4

kk167 opened this issue May 2, 2017 · 6 comments

Comments

@kk167
Copy link
Contributor

kk167 commented May 2, 2017

Hi.

Can you implement action like cc.Spawn in cocos2dx ?

Thank you for this plugin. It's very helpful for me 👍

@hustcc
Copy link
Owner

hustcc commented May 2, 2017

Sequence means running action by the order.

Spawn means running at the same time?

@kk167
Copy link
Contributor Author

kk167 commented May 3, 2017

yes. cc. Spawn run at the same time.
I add class ActionSpawn like below but it's not work.

import Action from './Action';

export class Spawn extends Action {
  constructor(actions) {
    super();
    this.actions = actions;

    this.reset();
  }
  reset() {
    // this._index = 0;
  }
  // if end return true, if not end return false
  update(sprite, delta, deltaMS) {
    if (!this.actions || !this.actions.length) {
      return true; 
    }
    let result = true;
    for(var i = this.actions.length; i >=0;i--){
        let action = this.actions[i];

        let isEnd = action.update(sprite, delta, deltaMS);
        if (isEnd) {
          action.reset();
          this.actions.splice(i,1);
        }else{
          result = false;
        }
    }
    
    return result;
  }
}

in index.js add

import {Spawn} from './ActionSpawn';
....
Spawn: Spawn,

@hustcc
Copy link
Owner

hustcc commented May 3, 2017

What is the error message?

@kk167
Copy link
Contributor Author

kk167 commented May 3, 2017

Uncaught TypeError: Cannot read property 'update' of undefined
    at e.value (pixi-action.js:1)
    at e.value (pixi-action.js:1)
    at e.value (pixi-action.js:1)
    at t.value (pixi-action.js:1)

i rebuild this plugin with comand
npm run build

i define some function like i use in cocos2dx

var cc = cc || {};
 cc.moveTo= function( time, p)
{
    return new PIXI.action.MoveTo(p.x, p.y, time);
};
cc.scaleTo= function( time, p)
{
   
    return new PIXI.action.ScaleTo(p.x, p.y, time);
};

cc.sequence= function( )
{
    return new PIXI.action.Sequence(arguments);//arguments is array
};
cc.spawn= function( )
{
    return new PIXI.action.Spawn(arguments);//arguments is array
};

then i use spawn like this

 var animTime= 1;
    var move = cc.moveTo(animTime, {x: 100, y:100}  );
    var scale = cc.scaleTo(animTime, {x: 1, y:1});
    var beforeMove = new PIXI.action.CallFunc(function() {

    });

    var afterMove = new PIXI.action.CallFunc(function() {

    });
    var action = cc.sequence(beforeMove,  cc.spawn(move, scale),afterMove);
    this.animation = PIXI.actionManager.runAction( this,action);

if i dont' use spawn, it work well.
Sorry for my bad english :(

@kk167 kk167 closed this as completed May 6, 2017
@kk167
Copy link
Contributor Author

kk167 commented May 6, 2017

i fix this in update function
for(var i = this.actions.length -1; i >=0;i--){

@hustcc
Copy link
Owner

hustcc commented May 6, 2017

So you can send a pr.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants