Last active
December 20, 2025 20:25
-
-
Save undefined06855/9ef9451287e74114ea0b54c36f1ad206 to your computer and use it in GitHub Desktop.
placing a custom gameobject during gameplay example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void HookedPlayLayer::placeSogBlock(cocos2d::CCPoint pos) { | |
| // using gd::string here for android support | |
| gd::vector<gd::string> values; | |
| gd::vector<void*> exists; | |
| // i think these were broken or won't compile for android so see what happens for you | |
| values.resize(600); | |
| exists.resize(600); | |
| std::unordered_map<int, gd::string> properties = { | |
| { 1, "1" }, // id of the base block you want it to act like | |
| { 2, fmt::to_string(pos.x) }, // x | |
| { 3, fmt::to_string(pos.y) }, // y | |
| { 21, "1011" }, // color 1 (white) | |
| // { 22, "1011" }, // color 2 (white) (optional if your base block doesnt use it) | |
| // these are if you want your block to be above everything | |
| { 24, "11" }, // t layer | |
| { 25, "2147483647" }, // z order (INT_MAX) | |
| // these are good if you want a completely separated block | |
| { 64, "1" }, // dont fade | |
| { 67, "1" }, // dont enter | |
| { 96, "1" }, // no glow | |
| }; | |
| for (auto [key, value] : properties) { | |
| values[key] = value; | |
| exists[key] = this; // just has to be non-zero, though gd makes it the GJBGL pointer | |
| } | |
| auto object = GameObject::objectFromVector(values, exists, this, false); | |
| // do what you want with the object at this point but this is probably a good example | |
| auto texture = CCTextureCache::get()->addImage("sog.png"_spr, false); | |
| object->setTexture(texture); | |
| object->setTextureRect({ 0.f, 0.f, texture->getContentSize().width, texture->getContentSize().height }); | |
| object->m_addToNodeContainer = true; // do this if you're adding your own sprites to it that aren't in GJ_GameSheet | |
| this->addObject(object); // note this wil also work in leveleditorlayer even though this function is on playlayer | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment