FAQ |
Kalender |
|
![]() |
#1 | ||
|
|||
Medlem
|
jo det förstår ja väl också men jag vet inte hur jag ska skriva.
|
||
![]() |
![]() |
![]() |
#2 | ||
|
|||
Medlem
|
BUMP!
Ser ut såhär nu: HTML-kod:
handleCollision: function(block) {
// Approaching from left
if(this.x + this.width > block.tile.x) {
this.x = block.tile.x;
}
// Approaching from right
if(this.x < block.tile.x + block.tile.width) {
this.x = block.tile.x + block.tile.width;
}
// Approaching from top
if(this.y + this.height > block.tile.y) {
this.y = block.tile.y;
}
// Approaching from bottom
if(this.y < block.tile.y + block.tile.height) {
this.y = block.tile.y + block.tile.height;
}
}
![]() ![]() En kompis frågade i vilken ordning allting sker så då sa jag: Kolla tangenttryck och sätt KEY_DOWN, KEY_UP osv... till true/false kolla om "gubben" kolliderar(är inuti ett svart block), här körs handleCollision() och sen kör jag update() metoden i "gubbe" klassen. HTML-kod:
update: function() {
if(this.RIGHT) {
this.velX = this.speed;
}
if(this.LEFT) {
this.velX = -this.speed;
}
if(this.UP) {
this.velY = -this.speed;
}
if(this.DOWN) {
this.velY = this.speed;
}
this.x += this.velX;
this.y += this.velY;
if(this.y >= canvas_height - this.height) {
this.y = canvas_height - this.height;
} else if(this.y <= 0) {
this.y = 0;
}
if (this.x >= canvas_width-this.width) {
this.x = canvas_width-this.width;
} else if (this.x <= 0) {
this.x = 0;
}
this.velX = 0;
this.velY = 0;
},
Senast redigerad av secag den 2013-06-01 klockan 15:58 |
||
![]() |
![]() |
Svara |
|
|