| キャラ移動による画面切り替え |
| 移動による画面を切り替える例 |
![]() 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
.container{
position: sticky;
}
.layer{
width: 250px;
height: 250px;
position: absolute;
}
.layer1{
top: 0px;
left: 0px;
z-index:1;
}
.layer2{
top: 0px;
left: 0px;
}
.layer3{
top: 250px;
left: 0px;
width: 100px;
height: 30px;
z-index:2;
}
.layer4{
top: 250px;
left: 150px;
width: 100px;
height: 30px;
z-index:2;
}
[javascript]
//マップ座標
const aryX=[200,200,200,200,200,150,100, 50, 0, 200,150,100, 50, 0, 0, 0, 0, 50,100,150,200,200, 0, 50,100,100,100];
const aryY=[0 , 50,100,150,200,200,200,200,200, 200,200,200,200,200,150,100, 50, 50, 50, 50, 50,100, 100,100,100, 50, 0];
let index = 0;
let x=0;
let y=0;
mapA();
//ひよこの位置
chickPosition();
//map A
function mapA()
{
hiddenAllMap();
displayMap(0,8);
displayMap(22,26);
}
//map B
function mapB()
{
hiddenAllMap();
displayMap(9,21);
}
//ひよこの位置
function chickPosition()
{
const chick = document.getElementById("chick");
chick.style.left = aryX[index] +'px';
chick.style.top = aryY[index] +'px';
}
//マップ表示
function displayMap(startIndex,endIndex)
{
for(i=startIndex; i <= endIndex; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "visible";
map.style.left = aryX[i] +'px';
map.style.top = aryY[i] +'px';
}
}
//マップ非表示
function hiddenAllMap()
{
for(i=0; i < aryX.length; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "hidden";
}
}
const b1 = document.getElementById("b1");
b1.addEventListener("click", () =>
{
moveChick(1);
});
const b2 = document.getElementById("b2");
b2.addEventListener("click", () =>
{
moveChick(-1);
});
//ひよこ移動
function moveChick(direction)
{
index += direction;
if(index >= aryX.length)
{
index = aryX.length - 1;
}
if(index<0)
{
index =0;
}
switch(index)
{
case 8:
case 22:
mapA();
break;
case 9:
case 21:
mapB();
break;
}
chickPosition();
}
[画面切り替え処理]
switch(index)
{
case 8:
case 22:
mapA();
break;
case 9:
case 21:
mapB();
break;
}
例えば
function hiddenAllMap()
{
for(i=0; i < aryX.length; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "hidden";
}
}
function displayMap(startIndex,endIndex)
{
for(i=startIndex; i <= endIndex; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "visible";
map.style.left = aryX[i] +'px';
map.style.top = aryY[i] +'px';
}
}
| [URL]イラスト:農民イラスト | |
| URL[https://nawmin.stores.jp][クリックすると開きます]) |
| Screen switching by moving the character |
| Example of switching screens by moving |
![]() 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
.container{
position: sticky;
}
.layer{
width: 250px;
height: 250px;
position: absolute;
}
.layer1{
top: 0px;
left: 0px;
z-index:1;
}
.layer2{
top: 0px;
left: 0px;
}
.layer3{
top: 250px;
left: 0px;
width: 100px;
height: 30px;
z-index:2;
}
.layer4{
top: 250px;
left: 150px;
width: 100px;
height: 30px;
z-index:2;
}
[javascript]
//Map Coordinates
const aryX=[200,200,200,200,200,150,100, 50, 0, 200,150,100, 50, 0, 0, 0, 0, 50,100,150,200,200, 0, 50,100,100,100];
const aryY=[0 , 50,100,150,200,200,200,200,200, 200,200,200,200,200,150,100, 50, 50, 50, 50, 50,100, 100,100,100, 50, 0];
let index = 0;
let x=0;
let y=0;
mapA();
//Chick position
chickPosition();
//map A
function mapA()
{
hiddenAllMap();
displayMap(0,8);
displayMap(22,26);
}
//map B
function mapB()
{
hiddenAllMap();
displayMap(9,21);
}
//Chick position
function chickPosition()
{
const chick = document.getElementById("chick");
chick.style.left = aryX[index] +'px';
chick.style.top = aryY[index] +'px';
}
//Map display
function displayMap(startIndex,endIndex)
{
for(i=startIndex; i <= endIndex; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "visible";
map.style.left = aryX[i] +'px';
map.style.top = aryY[i] +'px';
}
}
//Map hidden
function hiddenAllMap()
{
for(i=0; i < aryX.length; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "hidden";
}
}
const b1 = document.getElementById("b1");
b1.addEventListener("click", () =>
{
moveChick(1);
});
const b2 = document.getElementById("b2");
b2.addEventListener("click", () =>
{
moveChick(-1);
});
//Chick moving
function moveChick(direction)
{
index += direction;
if(index >= aryX.length)
{
index = aryX.length - 1;
}
if(index<0)
{
index =0;
}
switch(index)
{
case 8:
case 22:
mapA();
break;
case 9:
case 21:
mapB();
break;
}
chickPosition();
}
[Screen switching process]
switch(index)
{
case 8:
case 22:
mapA();
break;
case 9:
case 21:
mapB();
break;
}
For example,
function hiddenAllMap()
{
for(i=0; i < aryX.length; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "hidden";
}
}
function displayMap(startIndex,endIndex)
{
for(i=startIndex; i <= endIndex; i++)
{
const map = document.getElementById("map"+i);
map.style.visibility = "visible";
map.style.left = aryX[i] +'px';
map.style.top = aryY[i] +'px';
}
}
| [URL]illustration by nawmin.com | |
| URL[https://nawmin.stores.jp][click to open the homepage]) |
| ホームページおよプリ等に掲載されている情報等については、いかなる保障もいたしません。 ホームページおよびアプリ等を通じて入手したいかなる情報も複製、販売、出版または使用させたり、 または公開したりすることはできません。 当方は、ホームペーよびアプリ利用したいかなる理由によっての障害等が発生しても、 その結果ホームページおよびアプリ等を利用された本人または他の第三者が被った損害について 一切の責任を負わないものとします。 |