どんな入力でも大歓迎です!
簡単に言うと、HTML5/CSS3 ボタンを使用してキャンバス上のスプライト アニメーションを制御する方法を理解する必要があります。ボタンは、スプライトの方向と速度を個別に制御します。
2 つのタイプのスプライト コントロールを表す 2 つの配列があり、それぞれがさまざまな程度にインデックス付けされています (1 w/3 インデックスと 1 w/8 インデックス)。ボタンをスプライトのそれぞれの「変換」にリンクするには、どのような方法が必要ですか? 私のスプライトはタイル化され、8 インデックス配列でインデックス付けされているため、従来のように画像を変換する必要はありません。各ボタンをクリックして、特定の配列を特定のインデックスに変更し、それを drawImage() および clearRect () 式に挿入してアニメーションを作成する必要があります。クリックするたびに、1 つの配列とインデックス番号のみが変更され、他のすべては同じままになります。. . 速度と方向の値を配列に配置するのは正しいですか? 何か案は?
HTML
Div controlPanel は、キャンバスの上に z インデックスが付けられ、すべてのコントロール ボタンが含まれています。
<div id="controlPanel">
<div id="rightButtons">
<div id="fast">
<button type="button" class="speed" name="fast" value="2"></button>
</div>
<div id="medium">
<button type="button" class="speed" name="medium" value="1"></button>
</div>
<div id="slow">
<button type="button" class="speed" name="slow" value="0"></button>
</div>
</div>
<div id="bottomButtons">
<div id="H0">
<button type="button" class="heading" name="H0" value="0"></button>
</div>
<div id="H1">
<button type="button" class="heading" name="H1" value="1"></button>
</div>
<div id="H2">
<button type="button" class="heading" name="H2" value="2"></button>
</div>
<div id="H3">
<button type="button" class="heading" name="H3" value="3"></button>
</div>
<div id="H4">
<button type="button" class="heading" name="H4" value="4"></button>
</div>
<div id="H5">
<button type="button" class="heading" name="H5" value="5"></button>
</div>
<div id="H6">
<button type="button" class="heading" name="H6" value="6"></button>
</div>
<div id="H7">
<button type="button" class="heading" name="H7" value="7"></button>
</div>
</div>
EXT. ジャバスクリプト
var heading = [180,210,0,30,60,90,120,150] //x-coordinates of the sprite tile
var speed = [5,10,20];
document.getElementById("plane").onload=function(){
var canvasTwo = document.getElementById("canvasTwo");
var cxt = canvasTwo.getContext("2d");
var plane = document.getElementById("plane");
animatePlane();
}
function animatePlane(){
setInterval(drawPlane,200);
}
var plane = document.getElementById("plane");
var dy = speed;
var dx = s;
var x = 400;
var y = 475;
function drawPlane(){
y = y+dy;
x = x + dx;
cxt.save();
cxt.clearRect(x-dx,y-dy,30,30);
cxt.drawImage(plane,heading,0,30,30,x,y,30,30);
cxt.restore();
}
//This is where dx and dy get alittle funky. The value of dx and dy depend on the heading. Quite frankly I don't know where to place this block of code.
//to determine the value of dx
if (heading[]= 0){
dx= speed[];
dy= 0;
}
if (heading[]= 30){
dx= speed[];
dy= speed[]*-1;
}
if (heading[]= 60){
dx= 0;
dy= speed[]*-1;
}
if (heading[]= 90){
dx= speed[]*-1;
dy= speed[]*-1;
}
if (heading[]= 150){
dx= speed[]*-1;
dy= speed[];
}
if (heading[]= 180){
dx= 0;
dy= speed[];
}
if (heading[]= 210){
dx= speed[];
dy= speed[];
}