If you just skipped to this chapter directly after seeing it in the navigation bar, you may be wondering why it has taken us 7 chapters to reach aDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/geode-sdk/docs/llms.txt
Use this file to discover all available pages before exploring further.
Hello, World! program. Rest assured, the previous chapters are not just a waste; modding is a complex topic and Geode is an advanced framework. As such, we need to first lay a solid foundation for the basics of modding to build upon before we can get to actual code.
From here on out however, we’re starting to leave the lame theory part and beginning to enter the part where you actually get to make stuff.
And with that, let’s start building our Hello, World! mod!
Constructing the Mod
To begin with, we need to outline what our mod will actually do. The goal is simple: add some text to the main menu in GD that says “Hello, World!”.Modifying the Layer
Our first step is to use what we learned in the previous chapter and modifyMenuLayer:
init function, making sure to call the original:
Adding the label
Now it’s time to actually show the text. As outlined in Chapter 1.4, Cocos2d is node-based; we don’t do our own rendering, we leverage other nodes to do it for us. In this case, since we want to display text, we go for the standardCCLabelBMFont class:
cocos2d namespace, so we must prefix our usage of CCLabelBMFont::create with it. However, as you keep modding, having to stick cocos2d:: everywhere gets annoying really fast. In addition, Geode comes with a bunch of namespaces you probably also don’t want to rewrite every time. For this reason, Geode provides a geode::prelude namespace that automatically brings all Cocos2d and Geode-related namespaces to scope:
If you don’t want to bring Geode namespaces into scope, you can just use
using namespace cocos2d instead.MenuLayer:
Positioning the label
The default position for any node is (0, 0) which is at bottom left of the screen; however, we want to center our label in the middle of the screen. To do this, we need to first figure out what the size of the screen is, and to do this we use thegetWinSize method on CCDirector:
setPosition method on it, placing it halfway across the screen horizontally and vertically:
winSize’s type is CCSize, and that dividing a CCSize by an integer is the same as dividing that size’s width and height by the integer. Since we are dividing both winSize.width and winSize.height by the same number, we can shorten it to just winSize / 2. In addition, all nodes have both a setPosition(float, float) and setPosition(CCPoint) setter by default, and CCSize is implicitly convertible to CCPoint.
All of this means that we can make our setPosition call shorter as just:
Finished Mod
And with that, we have completed our Hello, World! mod. Here’s what the final code looks like:geode new, and then replace the code in src/main.cpp with the above. After building the mod, open up GD and you should see this:
If it works for you, congratulations! You have now officially built your first Geometry Dash mod! Go grab a lil orange juice from the kitchen and give yourself a little treat :)
After drinking your juice however, it’s time to get back into business. So we’ve got a Hello, World! going, that’s great. Now it’s time to start crafting something actually useful.
In Volume 2 of the tutorial, we will start looking at reverse engineering and how making new mods actually works in practice. To start, let’s once again ask the following question: so how exactly does one make a mod?.