Jump to content

How to add controls to image/sprite?


Recommended Posts

So to get right to the point. I am having issues with my ship image/sprite and my drawn objects on screen disappearing as soon as I try and addEventListener to code. why does my code essentially break when i add the EventListener? is it not possible to add controls to image or sprite within Html canvas?


Ship game code = https://codepen.io/BlaineP16/pen/VpQBZV

Link to comment
Share on other sites

  • 2 weeks later...

Looks like you're doing something based on this tutorial: https://developer.mozilla.org/en-US/docs/Games/Tutorials/2D_Breakout_game_pure_JavaScript/Paddle_and_keyboard_controls? I guess you forgot to change "paddleWidth" to "ship.width" ;)

And your code probably breaks because of typos in your handlers names. They are currently named keyDownHander and keyUpHander. Note the missing l.
Also there are probably some issues related to "collision checks". I could be more helpful if you described what kind of behaviour you're trying to achieve.

And yeah, would be nice to look at full project.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...