Closed sam-phillips21 closed 1 year ago
moveMtneer = movement
console.log(moveMtneer)
document.addEventListener('keypress', (event) => {
console.log(event)
if (['w', 'a', 's', 'd']) {
if(keypress() == 'w') {direction.up = true}
}
})
can you show me the whole class definition and when we're calling our set direction ?
class newMtneer {
constructor(x, y, color, width, height) {
this.x = x,
this.y = y,
this.color = color,
this.width = width,
this.height = height,
this.alive = true,
this.speed = 15,
this.direction = {
up: false,
down: false,
left: false,
right: false,
},
this.setDirection = function (key) {
console.log('key was pressed', key)
}
}
}
moveMtneer = movement
console.log(moveMtneer)
document.addEventListener('keydown', (event) => {
console.log(event)
if (['w', 'a', 's', 'd']) {
if(onkeydown(event) == 'w') {this.direction.up = true}
}
})
ive been removing the class, and messing the the lay out of the function above. i can. get it to register a keypress but still with errors.
refactored event handler to align with class and implemented new game object 😁
What's the problem you're trying to solve?
having an issues with key movements. set direction is coming back as not a function. eventlistener is working
Post any code you think might be relevant (one fenced block per file)
If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?
it says setdirection is not a function. i have am having trouble finding resources that can fix the issue
What is your best guess as to the source of the problem?
an issue with the way i have the function set up.
What things have you already tried to solve the problem?
ive tried to not have setDirection in a function: which let to setDirection is not a function. Ive put setDirection in a function and it comes back not a function...
Paste a link to your repository here
https://github.com/sam-phillips21/Project-one