CopperCube is an editor for creating 3D games and 3D websites, as windows or Mac OS apps, as Flash or WebGL websites, or Android apps.

Post tutorial Report RSS [CopperCube] Scripting - Load Textures Externally

This lesson will show you how to make games made with CopperCube can load textures externally rather than pack it inside the game executable.

Posted by on - Basic Other

Hi DevMates! :)
Today i will show you how to make games made with CopperCube can load textures externally.

As we know, games made with CopperCube will pack the models, maps, sounds, textures & other game components inside the executable ("gamename.exe"). It's has advantages and disadvantages.

The advantages is our gamefiles are secured. Why? Because it's inside the game. Not only that, CopperCube also encrypts every single file inside the game. So we can't edit the game, we can't even change the icon of the Compiled Game. Cool! :D

Then what's the advantages..? Of course, the size.
Since the files are packed inside the game, the size of the executable would be extremely high (Indeed). Especially if we use high-poly models, high quality sounds, 2K Textures (Current CopperCube version only support 2k textures max.), it's possible that you will get your .exe sized 1GB even more.

Ok! now, it's time for the tutorial to begin! :)

Make a variable that will get your target scene node:

var s = ccbGetSceneNodeFromName("NodeName");


Replace "NodeName" with your scene node name, and replace "s" with anything you want.

Now make a variable that will load the texture:

var texture = ccbLoadTexture("./directory/filename");


Replace "directory" with your textures directory, replace "filename" your texture name (i.e. texture.png), and "texture" with anything you want

Note:
"./" is the root folder of the game. So if your texture destination is "./gamedata/textures/filename.png", and the game location is in "D:\Game\MyGame", it will load texture from "D:\Game\MyGame\gamedata\textures\filename.png

Now, it's time to execute the scripts!
To execute the scripts above, you have to use this script:

ccbSetSceneNodeMaterialProperty(s, materialindex, "Texture1", texture);

"materialindex" is the number of texture in your prefab. first texture in your prefab is "0", 2nd texture is "1", and so on.

Now, combine those scripts. And the result is:

var s = ccbGetSceneNodeFromName("NodeName");

var texture = ccbLoadTexture("./directory/filename");
ccbSetSceneNodeMaterialProperty(s, materialindex, "Texture1", texture);

Are we done here? Not yet.. ;)

Now we need trigger that will execute the scripts above. I'd recommend you to put this to the root scene node.
How to? See it below! :)

scenegraphbehaviours

action

javascript

Now, test your game and... if it works, Voila! Your game can now load textures externally! :)
But if it doesn't work, try to re-check your script. And test your game again :)

If you get struggled, don't hesitate to ask me for further help. I'd be happy to help you! :D
If you found this tutorial helpful for you, please consider to donate me. I'd appreciate it a lot!

PayPal Donate Button PNG Pic


Bitcoin:

1CGJgbwzNPynPi5EGr2ry2DoS7PCe5DDow


Also, don't forget to check out my current game project! :)


NoNameYet game - Indie DB


See you next time! :)


Post a comment

Your comment will be anonymous unless you join the community. Or sign in with your social account: