pictcode / app / webroot / js / pictcode / sprite_action.js @ 0b1b8047
履歴 | 表示 | アノテート | ダウンロード (1.422 KB)
1 |
define(['sprite_manager', 'sprite_drawer'], function(spriteManager, spriteDrawer){ |
---|---|
2 |
|
3 |
var previousPosition;
|
4 |
var targetSprite;
|
5 |
var isMoving = false; |
6 |
var ceRatio;
|
7 |
var editorSize;
|
8 |
|
9 |
function setSwipeTarget(x, y, canvas, edtrSize, tSprite){ |
10 |
previousPosition= {x:x, y:y}; |
11 |
targetSprite = tSprite; |
12 |
isMoving = true;
|
13 |
editorSize = edtrSize; |
14 |
ceRatio = canvas.width/editorSize.width; |
15 |
} |
16 |
|
17 |
function changeSpritesPositionBySwipe(x, y, drawSprites){ |
18 |
if (!isMoving) {return}; |
19 |
|
20 |
var dx = x-previousPosition.x;
|
21 |
var dy = y-previousPosition.y;
|
22 |
dx /= ceRatio; |
23 |
dy /= ceRatio; |
24 |
dy *= -1;
|
25 |
targetSprite.position.x += dx; |
26 |
targetSprite.position.y += dy; |
27 |
previousPosition.x = x; |
28 |
previousPosition.y = y; |
29 |
|
30 |
if (targetSprite.x < -editorSize.width/2){ |
31 |
targetSprite.x = -editorSize.width/2;
|
32 |
isMoving = false;
|
33 |
}; |
34 |
if(targetSprite.x > editorSize.width/2){ |
35 |
targetSprite.x = editorSize.width/2;
|
36 |
isMoving = false;
|
37 |
}; |
38 |
if(targetSprite.y < -editorSize.height/2){ |
39 |
targetSprite.y = -editorSize.height/2;
|
40 |
isMoving = false;
|
41 |
}; |
42 |
if(targetSprite.y > editorSize.height/2) { |
43 |
targetSprite.y = editorSize.height/2
|
44 |
isMoving = false;
|
45 |
}; |
46 |
|
47 |
drawSprites(); |
48 |
} |
49 |
|
50 |
function finishSwipe(){ |
51 |
isMoving = false;
|
52 |
} |
53 |
|
54 |
return {
|
55 |
setSwipeTarget:setSwipeTarget,
|
56 |
changeSpritesPositionBySwipe:changeSpritesPositionBySwipe,
|
57 |
finishSwipe:finishSwipe,
|
58 |
}; |
59 |
}); |