Issue
I am dev game when I coding collision. In the collision I use width but when I do console log the width is shown as the number '1920' but I write player.style.width = 100 +'px'
I not what to do
.cube1 {
background-color: rgb(255, 0, 0);
left: 50%;
right: 50%;
width: 100px;
}
As you can see I set the width to one hundred, but as soon as I do a console log to the width, it is so 1920
function collision() {
playerwidth = parseInt(player.width)
var playerleftside = parseInt(player.style.left);
var blockrightside = parseInt(block.style.left) + parseInt(block.style.width);
var playerrightside = parseInt(player.style.left) + parseInt(player.width);
var blockleftside = parseInt(block.style.left);
console.log(playerwidth);
switch(switchcollision){
case 68:
if (!(playerrightside >= blockleftside)) {
player.style.left = playerleftside + 100 + "px";
} else{
console.log( player.style.left = block.style.left - parseInt(block.style.width) + "px");
player.style.left = block.style.left - parseInt(block.style.width) + "px";
}
break;
case 65:
if (!(blockleftside <= playerrightside)) {
player.style.left = playerleftside - 100 +"px";
} else {פ
console.log("yes_2");
player.style.left = block.style.left + parseInt(block.style.width) + "px";
}
// }
}
}
I will appreciate if you can help me because I have been trying to find an answer for two months
I search internet for answer but isn't work to me
Solution
Solution
function collision
playerWidth = parseInt(player.clientWidth)
var playerleftside = parseInt(player.style.left)
var blockrightside = parseInt(block.style.left) + parseInt(block.style.width)
var playerrightside = parseInt(player.style.left) + parseInt(player.clientWidth)
// The Rest Of The Code Is Same...`
Answered By - Saayxee
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.