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

Accessory 系の clone() 実装 #172

Open
wants to merge 10 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/accessory/accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ phina.namespace(function() {
this.target.detach(this);
this.target = null;
},
clone: function() {
return phina.using(this.className)(this.target);
},

});

phina.app.Element.prototype.$method('attach', function(accessory) {
Expand Down
8 changes: 8 additions & 0 deletions src/accessory/flickable.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,14 @@ phina.namespace(function() {
enable: function() {
this._enable = true;
},

clone: function() {
var flickable = phina.accessory.Flickable(this.target);
flickable.friction = this.friction;
flickable.horizontal = this.horizontal;
flickable.vertical = this.vertical;
return flickable;
},

});

Expand Down
6 changes: 6 additions & 0 deletions src/accessory/physical.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,12 @@ phina.namespace(function() {
this.friction = fr;
return this;
},

clone: function() {
return phina.accessory.Physical(this.target)
.setFriction(this.friction)
.setGravity(this.gravity.x, this.gravity.y);
},
});

phina.app.Element.prototype.getter('physical', function() {
Expand Down
10 changes: 10 additions & 0 deletions src/accessory/tweener.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,16 @@ phina.namespace(function() {
this._init();
return this;
},

clone: function() {
var tweener = Tweener(this.target);
tweener._tasks = this._tasks.clone();
tweener._index = this._index;
tweener.playing = this.playing;
tweener._loop = this._loop;
tweener.updateType = this.updateType;
return tweener;
},

fromJSON: function(json) {
if (json.loop !== undefined) {
Expand Down
52 changes: 42 additions & 10 deletions test/game/src/accessory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ th.describe("accessory.Tweener", function() {
var shape = phina.display.CircleShape().addChildTo(this);
var tweener = phina.accessory.Tweener().attachTo(shape);
tweener
.to({x:320, y:480}, 1000)
.to({x:320, y:480}, 1000);
});

th.it('to', function() {
var shape = phina.display.RectangleShape().addChildTo(this);
var tweener = phina.accessory.Tweener().attachTo(shape);
tweener
.to({x:320, y:480}, 1000)
.to({scaleX:4,scaleY:4, rotation:360}, 1000)
.to({scaleX:4,scaleY:4, rotation:360}, 1000);
});

th.it('by', function() {
Expand All @@ -21,15 +21,15 @@ th.describe("accessory.Tweener", function() {
tweener
.to({x:320, y:480}, 1000)
.by({x:100, y:100}, 1000)
.to({scaleX:4,scaleY:4, rotation:360}, 1000)
.to({scaleX:4,scaleY:4, rotation:360}, 1000);
});

th.it('from', function() {
var shape = phina.display.RectangleShape().addChildTo(this);
shape.position.set(320, 480);
var tweener = phina.accessory.Tweener().attachTo(shape);
tweener
.from({scaleX:4,scaleY:4, rotation:360}, 1000)
.from({scaleX:4,scaleY:4, rotation:360}, 1000);
});

th.it('wait', function() {
Expand All @@ -38,7 +38,7 @@ th.describe("accessory.Tweener", function() {
tweener
.to({x:320, y:480}, 1000)
.wait(1000)
.to({scaleX:4,scaleY:4, rotation:360}, 1000)
.to({scaleX:4,scaleY:4, rotation:360}, 1000);
});

th.it('call', function() {
Expand All @@ -52,7 +52,7 @@ th.describe("accessory.Tweener", function() {
.to({scaleX:4,scaleY:4, rotation:360}, 1000)
.call(function() {
shape.style.color = 'blue';
})
});
});

th.it('set', function() {
Expand All @@ -64,7 +64,7 @@ th.describe("accessory.Tweener", function() {
.set({scaleX:4, scaleY:4})
.call(function() {
shape.fill = 'green';
})
});
});

th.it('play', function() {
Expand All @@ -87,7 +87,7 @@ th.describe("accessory.Tweener", function() {
.to({x:320, y:480}, 1000)
.call(function() {
this.rewind();
})
});
});

th.it('yoyo', function() {
Expand All @@ -98,7 +98,7 @@ th.describe("accessory.Tweener", function() {
.to({x:320+150, y:480}, 1000)
.call(function() {
this.yoyo();
})
});
});

th.it('loop', function() {
Expand All @@ -124,7 +124,21 @@ th.describe("accessory.Tweener", function() {
]
});
});


th.it('clone', function() {
var shape = phina.display.RectangleShape().addChildTo(this);
var tweener = phina.accessory.Tweener().attachTo(shape);
tweener
.to({x:320, y:480}, 1000)
.to({scaleX:4,scaleY:4, rotation:360}, 1000);
var tweener2 = tweener.clone();

var shape = phina.display.RectangleShape({
x: 640,
y: 960,
}).addChildTo(this);
shape.attach(tweener2);
});

});

Expand Down Expand Up @@ -244,6 +258,24 @@ th.describe("accessory.Flickable", function() {
label.text = angle;
};
});

th.it('clone', function() {

var shape = phina.display.CircleShape().addChildTo(this);
shape.setPosition(160, 480);
shape.flickable.enable();

shape.flickable.horizontal = true;
shape.flickable.vertical = false;

var flickable = shape.flickable.clone();

var shape = phina.display.CircleShape().addChildTo(this);
shape.setPosition(480, 480);
flickable.enable();
flickable.attachTo(shape);

});
});


Expand Down