Add: highlightOn/OffFinger

This commit is contained in:
2018-06-20 09:49:14 +09:00
parent ba3b88793b
commit bc8179302b
3 changed files with 44 additions and 46 deletions
Binary file not shown.
+43 -45
View File
@@ -3,9 +3,11 @@ class Hand {
constructor(keyMapper) { constructor(keyMapper) {
this.keyMapper = keyMapper; this.keyMapper = keyMapper;
this.pressingFinger = KeyButton.NONE_FINGER; this.pressingFinger = KeyButton.NONE_FINGER;
this.prevFingerSprite = null;
this.hand = game.add.image(0, Hand.DEFAULT_Y_PX, "hand_palm"); this.hand = game.add.image(0, Hand.DEFAULT_Y_PX, "hand_palm");
this.hand.anchor.set(0.5); this.hand.anchor.set(0.5);
this.hand.scale.set(2);
this.thumb = game.add.image(0, 0, "hand_thumb"); this.thumb = game.add.image(0, 0, "hand_thumb");
this.hand.addChild(this.thumb); this.hand.addChild(this.thumb);
@@ -18,9 +20,6 @@ class Hand {
this.little_finger = game.add.image(0, 0, "hand_ring_finger"); this.little_finger = game.add.image(0, 0, "hand_ring_finger");
this.hand.addChild(this.little_finger); this.hand.addChild(this.little_finger);
this.hand.scale.set(2);
// this.hand.anchor.set(0.5);
let mask = game.add.graphics(); let mask = game.add.graphics();
mask.beginFill(0xffffff); mask.beginFill(0xffffff);
mask.drawRect(100, 300, 1028, 400); mask.drawRect(100, 300, 1028, 400);
@@ -35,6 +34,11 @@ class Hand {
moveTo(key) { moveTo(key) {
} }
moveToDefaultPosition() {
this.moveRow(3, null);
this.unhighlightOffFinger(KeyButton.NONE_FINGER);
}
moveRow(rowNo, key) { moveRow(rowNo, key) {
let rowIndex = rowNo - 1; let rowIndex = rowNo - 1;
@@ -47,53 +51,51 @@ class Hand {
} }
pressFinger(finger) { getFingerSprite(fingerNo) {
if(this.pressingFinger !== finger) { let fingerSprite = null;
unpressFinger(this.pressingFinger); switch(fingerNo) {
}
switch(finger) {
case KeyButton.THUMB: case KeyButton.THUMB:
prevFinger = this.thumb; fingerSprite = this.thumb;
break; break;
case KeyButton.INDEX_FINGER: case KeyButton.INDEX_FINGER:
prevFinger = this.thumb; case KeyButton.INDEX_FINGER_BASELINE:
fingerSprite = this.index_finger;
break; break;
case KeyButton.MIDDLE_FINGER: case KeyButton.MIDDLE_FINGER:
prevFinger = this.thumb; fingerSprite = this.middle_finger;
break; break;
case KeyButton.RING_FINGER: case KeyButton.RING_FINGER:
prevFinger = this.thumb; fingerSprite = this.ring_filger;
break; break;
case KeyButton.LITTLE_FINGER: case KeyButton.LITTLE_FINGER:
prevFinger = this.thumb; fingerSprite = this.little_finger;
break; break;
} }
if(prevFinger !== null) return fingerSprite;
prevFinger.tint = 0x0000ff;
} }
unpressFinger(finger) { highlightOnFinger(fingerNo) {
let prevFinger = null; console.log(fingerNo);
switch(finger) { console.log(this);
case KeyButton.THUMB: let pressingFingerSprite = this.getFingerSprite(fingerNo);
prevFinger = this.thumb; if(pressingFingerSprite === this.prevFingerSprite)
break; return;
case KeyButton.INDEX_FINGER:
prevFinger = this.thumb; if(this.prevFingerSprite !== null)
break; this.unhighlightOffFinger();
case KeyButton.MIDDLE_FINGER:
prevFinger = this.thumb; if(pressingFingerSprite !== null)
break; pressingFingerSprite.tint = 0xffff00;
case KeyButton.RING_FINGER:
prevFinger = this.thumb; this.prevFingerSprite = pressingFingerSprite;
break; }
case KeyButton.LITTLE_FINGER:
prevFinger = this.thumb; unhighlightOffFinger() {
break; if(this.prevFingerSprite === null)
} return;
if(prevFinger !== null) this.prevFingerSprite.tint = 0xffffff;
prevFinger.tint = 0xffffff;
this.prevFingerSprite = null;
} }
} }
@@ -114,10 +116,6 @@ class LeftHand extends Hand {
this.moveToDefaultPosition(); this.moveToDefaultPosition();
} }
moveToDefaultPosition() {
this.moveRow(3, null);
}
moveTo(key) { moveTo(key) {
if(key === undefined) if(key === undefined)
return; return;
@@ -138,6 +136,8 @@ class LeftHand extends Hand {
this.moveColumn(5, key); this.moveColumn(5, key);
break; break;
} }
this.highlightOnFinger(key.fingerType);
} }
moveColumn(rowNo, key) { moveColumn(rowNo, key) {
@@ -183,10 +183,6 @@ class RightHand extends Hand {
this.moveToDefaultPosition(); this.moveToDefaultPosition();
} }
moveToDefaultPosition() {
this.moveRow(3, null);
}
moveTo(key) { moveTo(key) {
if(key === undefined) if(key === undefined)
return; return;
@@ -207,6 +203,8 @@ class RightHand extends Hand {
this.moveColumn(5, key); this.moveColumn(5, key);
break; break;
} }
this.highlightOnFinger(key.fingerType);
} }
moveColumn(rowNo, key) { moveColumn(rowNo, key) {
+1 -1
View File
@@ -239,4 +239,4 @@ KeyButton.INDEX_FINGER = 2;
KeyButton.INDEX_FINGER_BASELINE = 3; KeyButton.INDEX_FINGER_BASELINE = 3;
KeyButton.MIDDLE_FINGER = 4; KeyButton.MIDDLE_FINGER = 4;
KeyButton.RING_FINGER = 5; KeyButton.RING_FINGER = 5;
KeyButton.LITTLE_FINGER = 5; KeyButton.LITTLE_FINGER = 6;