-
Notifications
You must be signed in to change notification settings - Fork 155
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HOW TO REPLACE PACMAN ICON WITH AN IMAGE? #10
Comments
every time I try to replace icon with an image game got stuck, kindly help |
Hello, what are you trying to replace? The pacman player icon, or the page title icon (the icon that shows up on the browser tab)? |
for the pacman player, you'll need to edit pacman.js, and find the function drawPacman(). This function is responsible for drawing the player character (pacman), and it does this by drawing lines and shapes (which is also how the animation works in this case!). To replace the image, do something lie this: pacman.js drawPacman():
` and index.html: this will replace the images, but you will have to change the img src names to match yours. |
@MEMESCOEP I know you posted the solution a while back, but I was just having a bit of issue with the code. I was able to import my own image, but I was having issues making the character larger:
Anytime I increase the X, Y above 25-30 for each instance of this code, it would make the character larger, but when I move the character it would leave streaks across the game board. Also it seems the image is centered to the bottom right of where it should be positioned. I appreciate any help as I'm new to programming. |
Maybe there's a limit to how big the image can be before it stops properly clearing |
@MEMESCOEP Sure. Here it is. |
Taking a look now, it looks like the image is offset, or the grid isn't big enough As for the streaking issue, the |
@zorromustafa I've think I've found the issue. Streaking issueThe Image offsetYou'll need to add Sample codeHere's some example code that gets the job done for both:
|
@MEMESCOEP Thank you! That works great! One last thing: else if (PACMAN_DIRECTION === 3 || PACMAN_DIRECTION === 4) { //left & up I imported 3 different images (with the character facing right, down, and left) In this image, the character is moving upwards but is facing left |
@zorromustafa You can separate the left and up tests, I'll upload some test code in a few minutes |
I did try to create a separate else if (PACMAN_DIRECTION === 4 statement but the character wouldn't populate at all when I tested it. I'll try it again. Also here is my updated code with the added images in case you wanted to look at it. Thanks again for your help. |
@MEMESCOEP Nevermind about the last reply, I got it working! |
No problem! I've also just realized I've been pinging the wrong person, sorry about that |
So I was able to successfully replace each ghost with my own image by modifying the drawHelperGhost function (at the bottom of ghosts.js). I wrote code similar to the drawPacman function, including the image offset modification. I made sure the width / height variables are equal as well yet the streaking is still present. Would you happen to know why? I'm stumped again here but I'm really close. function drawHelperGhost(ctx, x, y, d, b, s, a) {
Here's the full code |
I'll have to take a look at the enemy code @ggalvin1 |
@MEMESCOEP Thanks. Keep me posted if you find out what's causing it |
I haven't found anything yet unfortunately @ggalvin1 |
No description provided.
The text was updated successfully, but these errors were encountered: