Skip to main content

Project JPacman #5: Graphics and Controls

spanish Puedes leer este artículo en español en

After JPacman had given the first signs of life using Cocos2d-x, it was time to make it finally playable again. What was missing for this? Two things: to see the graphics on screen and to use the keyboard to control menus and main character.

Graphics on Screen

In order to display the graphics on the screen and keep the logic that I had already implemented in the original version of JPacman, I had to first check how it did it work and which were the contents of the image files that the project already contained.

I discovered that JPacman loaded only one large image per scene. At the top of each image there was the background of the scene at full screen size, which meant a resolution of 640 by 480 pixels. There were four different scenes in the game and so there were four image files: intro, main menu, best scores screen and the game scene.

JPacman background images
The backgrounds of the four JPacman scenes: the scene to play has the maze painted in the background; the intro has a black background; the menus have a (horrible) green bricks background, and the main menu has the game logo over it.

Each of the four files had repeated in the bottom a series of images with all the drawings of the animations of the game characters and dynamic objects. It surprised me that almost twenty years ago I actually used what is known in the industry as a textures atlas, because it is one of the most efficient ways to handle image files in a videogame of this type.

JPacman texture atlas
The images and animations of the characters and dynamic objects of JPacman, using the technique known as texture atlas.

I had to convert image files to PNG, because the original version of JPacman used image files in BMP format, and Cocos2d-x does not support that format. Also, I separated the texture atlas sectipn from the backgrounds in the image files because I thought it would be better for managing the loading and unloading of the images.

Already focused on the code, making the graphics work was not difficult at all. I had to work on the the Gfx.cpp file, especially on the DrawSprite function to be able to register in the Cocos2d-x scene system the images that needed to be displayed. I also had to be careful with coordinate systems because I discovered, the hard way, that the Y coordinate was inverted between Direct X and Cocos2d-x.

Finally, I fixed an awful bug I had in the code regarding the GFXFile variable, with which I was doing what is known as a “memory corruption”. That surely explains unexpected crashes that I experienced in the original version and that I never understood why they happened. For more details, you can see the code in Bitbucket and the change I made.

Controls and Keyboards

The next step was to be able to control the menus and the character with the keyboard. Inspecting the code, I discovered that I had also programmed (or copied from somewhere) the functionality to be able to use gamepads with the game, but apparently it was incomplete. Challenge for a later stage, I told myself.

For the keyboard to work, I first had to modify several files because the constants I used to identify the keys conflicted with Cocos2d-x constants. To all the constants of the game I had to add the JPACMAN_ prefix, and that fixed the issue.

Then I added the code to register a Cocos2d-x event listener and added the handling of the OnKeyPressed and OnKeyReleased events, which was a lot easier than I expected.

JPacman was playable again!

JPacman screenshot
Having connected the graphics and keyboard of the original code with Cocos2d-x, JPacman was playable again!
spanish Puedes leer este artículo en español en
Share Button

Juan Pablo Lastra

Juan Pablo makes videogames since he was 8 and he is a father since 2004. Today, he has three children and he has worked in more than 20 videogames. He got interested on how paternity and the videogame industry are related and he decided to write about it, founding "Papa Game Dev"

200 thoughts on “Project JPacman #5: Graphics and Controls

  1. Pingback: Late holiday deals
  2. Pingback: must watch
  3. Pingback: read more
  4. Pingback: Aws alkhazrajii
  5. This message is posted here using XRumer + XEvil 4.0

    XEvil 4.0 is a revolutionary application that can solve any anti-botnet protection.
    Captcha Bypass Google (ReCaptcha-1, ReCaptcha-2), Facebook, BING, Hotmail, Yahoo,
    Yandex, VKontakte, Captcha Com – and over 8.4 million other types!

    You read this – it means it works! 😉
    Details on the official website of XEvil.Net, there is a free demo version.

    Check YouTube video “XEvil ReCaptcha2”

  6. Pingback: real estate leads
  7. Pingback: seo salt lake city
  8. И вообще мне нужно идти

    Вы допускаете ошибку. Могу отстоять свою позицию. Пишите мне в PM, обсудим. скачать взломанную fifa 15, fifa 15 скачать торрент механики rus или сайт fifa fifa 15 moddingway скачать торрент pc

  9. Pingback: 검증사이트
  10. Pingback: Online cialis
  11. Pingback: Discount cialis
  12. Pingback: quantaflo semler
  13. Pingback: Online cialis
  14. Pingback: Generic for cialis
  15. Pingback: Buy viagra
  16. Pingback: continue
  17. Pretty portion of content. I just stumbled upon your web site and in accession capital to assert that I acquire actually enjoyed account your blog posts. Any way I will be subscribing in your augment or even I fulfillment you access constantly quickly. egkbegeddcbkfgef

  18. I am really enjoying the themedesign of your blog. Do you ever run into any browser compatibility problems? A handful of my blog readers have complained about my website not operating correctly in Explorer but looks great in Chrome. Do you have any advice to help fix this issue? kbcefefefdedffcb

  19. Pingback: check this out
  20. Pingback: Cialis daily
  21. Pingback: Bangalore Escorts
  22. Pingback: Kolkata Escorts
  23. Pingback: Goa Escorts
  24. Pingback: this web page
  25. Pingback: Cialis coupon
  26. Pingback: this web page
  27. Pingback: visit the page
  28. Pingback: read completely
  29. Pingback: page
  30. Pingback: follow the link
  31. Pingback: click to continue
  32. Pingback: Cialis 20mg
  33. Pingback: essayforme
  34. Pingback: Cialis 20mg
  35. Pingback: Buy cialis
  36. Pingback: Cialis coupon
  37. Pingback:
  38. Pingback: click here
  39. Pingback: on this page
  40. Pingback: read more
  41. Pingback: more on this page
  42. Pingback:
  43. Pingback:
  44. Pingback:
  45. Pingback:
  46. Pingback: taken from here
  47. Pingback:
  48. Pingback: provided link
  49. Pingback: visit the source
  50. Pingback: go to the source
  51. Pingback:
  52. Pingback:
  53. Pingback: provided link
  54. Pingback: this web page
  55. Pingback: on this page
  56. Pingback:
  57. Pingback: read completely
  58. Pingback: read
  59. You are so awesome! I do not believe I’ve truly read through a single thing like that before.
    So great to find somebody with original thoughts on this subject matter.
    Really.. thank you for starting this up. This site is one thing that is needed on the web, someone with some originality!

    my web site buy weed

  60. Wonderful beat ! I wish to apprentice at the same
    time as you amend your site, how could i subscribe for a blog web site?
    The account helped me a acceptable deal. I had been a little bit acquainted of
    this your broadcast offered bright clear concept

    Also visit my web-site … best kratom

  61. Today, I went to the beach front with my kids.
    I found a sea shell and gave it to my 4 year old daughter and said “You can hear the ocean if you put this to your ear.” She placed the shell to her ear and screamed.
    There was a hermit crab inside and it pinched her ear.
    She never wants to go back! LoL I know this is entirely off
    topic but I had to tell someone!

    Also visit my website :: cbd capsules for pain (

  62. Hello I am so delighted I found your webpage,
    I really found you by mistake, while I was researching on Askjeeve for something else, Anyways I am here now and would just like
    to say cheers for a incredible post and a all round interesting blog (I also love the
    theme/design), I don’t have time to read through it all at the minute but I have bookmarked it and also added your RSS
    feeds, so when I have time I will be back to read a
    great deal more, Please do keep up the awesome job.

    My page; how to take red vein remahan maeng da leaf

  63. Новые семейные расстановки.
    Системно-феноменологическая психотерапия Духовные расстановки.
    Структурные расстановки. Системно-феноменологический подход.
    Организационные расстановки.
    Системно-феноменологический подход.

Leave a Reply

Your email address will not be published. Required fields are marked *