Skip to content

razerofficial/GameMakerChromaExtension

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

56 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Latest

GameMaker Chroma Extension - GameMaker Extension to control lighting for Razer Chroma

Table of Contents

See Also

Docs:

Plugins:

  • CChromaEditor - C++ native MFC library for playing and editing Chroma animations

Frameworks supported

Getting Started

  • Install Synapse

  • Make sure the Chroma Connect module is installed.

image_8

  • If you don't have Chroma hardware, you can see Chroma effects with the Chroma Emulator

1 Import the GameMakerChromaExtension.gmez extension

2 Double-click the ChromaSDK extension

image_1

3 On the Import Resources tab, expand Included Files, select CChromaEditorLibrary.dll and click Import All

image_2

4 CChromaEditorLibrary.dll should appear in your project's Included Files folder

image_3

5 Double-click a Chroma animation to associate the .chroma extension with the CChromaEditor

image_4

6 Once associated, double-click a Chroma animation to bring up the animation editor

image_5

7 In order to see the lighting animations play, use the File->Create Application menu item to create a Windows application. After the installer completes, the application will play Chroma animations.

image_7

Assets

This extension supports the Chroma animation exports from UE4, Unity, and GameMaker.

Add Chroma animation files to the project's Included Files to make the animations accessible from GMS script.

image_4

API

The extension methods are only available on the Windows platform. Use GMS to detect the Windows os.

if (os_type == os_windows)
{
   // do Chroma
}

When the first room loads, run GMS script to set the default global variables. These globals are what connects the Chroma DLL methods.

See ScriptGlobals.gml.

The API has various methods with the D suffix where double return-type/parameters were used. This is to support engines like GameMaker which have a limited number of data-types.

ScriptChromaCloseAnimationName

The helper script closes an animation to reload from disk. The method takes a string parameter of the animation name.

animation = 'Random_Keyboard.chroma';
ScriptChromaCloseAnimationName(animation);

ScriptChromaCopyKeyColorName

The helper script copies the key color from a source animation to the target animation for the key of the animation frame. The source and target animation are strings. The frame index is a number from 0 to the frame count. The key is a integer of the key number.

See ScriptGlobals.gml for the list of key values.

sourceAnimation = 'Fire_Keyboard.chroma';
targetAnimation = 'Random_Keyboard.chroma';
frameIndex = 0;
key = gloval.RZKEY_W;
ScriptChromaCopyKeyColorName(sourceAnimation, targetAnimation, frameIndex, key);

ScriptChromaGetFrameCountName

The helper script returns the number of animation frames. The animation parameter is a string.

animation = 'Random_Keyboard.chroma';
frameCount = ScriptChromaGetFrameCountName(animation);

ScriptChromaInit

The helper script initializes the ChromaSDK and has no parameters.

ScriptChromaInit();

ScriptChromaOpenEditorDialog

The helper script opens an edit dialog for the animation. The animation parameter is a string. The edit dialog is modal so only one animation can be edited at a time.

animation = 'Random_Keyboard.chroma';
ScriptChromaOpenEditorDialog(animation);

ScriptChromaPauseAnimationName

The helper script pauses an animation. The animation parameter is a string.

animation = 'Random_Keyboard.chroma';
ScriptChromaPauseAnimationName(animation);

ScriptChromaPlayAnimationName

The helper script plays an animation. The animation parameter is a string. The animation can play with loop ON or OFF.

animation = 'Random_Keyboard.chroma';
loopOn = 1.0;
loopOff = 0.0;
loop = loopOn;
ScriptChromaPlayAnimationName(animation, loop);

ScriptChromaPlayAnimationFrameName

The helper script plays an animation. The animation parameter is a string. The animation can play with loop ON or OFF starting at the frameId.

animation = 'Random_Keyboard.chroma';
loopOn = 1.0;
loopOff = 0.0;
loop = loopOn;
frameId = 12;
ScriptChromaPlayAnimationFrameName(animation, frameId, loop);

ScriptChromaPlayComposite

The helper script plays a set of animations. The composite is a string. The animation can play with loop ON or OFF. This method will play the set of animations which includes ChromaLink, Headset, Keyboard, Keypad, Mouse, and Mousepad.

composite = "Random";
loopOn = 1.0;
loopOff = 0.0;
loop = loopOn;
ScriptChromaPlayComposite(composite, loop);

ScriptChromaResumeAnimationName

The helper script will resume playing a paused animation. The animation is a string. The animation can resume with loop ON or OFF.

animation = 'Random_Keyboard.chroma';
loopOn = 1.0;
loopOff = 0.0;
loop = loopOn;
ScriptChromaResumeAnimationName(animation, loop);

ScriptChromaSetKeyColorName

The helper script assigns the key color to the animation frame. The animation is a string. The frame index is a number from 0 to the frame count. The key the integer of the key number. The color is a COLORREF integer.

See ScriptGlobals.gml for the list of key values.

animation = 'Random_Keyboard.chroma';
frameIndex = 0;
key = global.RZKEY_W;
red = ScriptToBGRInt(255, 0, 0);
green = ScriptToBGRInt(0, 255, 0);
blue = ScriptToBGRInt(0, 0, 255);
color = red; 
ScriptChromaSetKeyColorName(animation, frameIndex, key, color);

ScriptChromaGetKeyColorName

The helper script gets the key color of the animation frame. The animation is a string. The frame index is a number from 0 to the frame count. The key the integer of the key number. The color is a COLORREF integer.

See ScriptGlobals.gml for the list of key values.

animation = 'Random_Keyboard.chroma';
frameIndex = 0;
key = global.RZKEY_W;
color = ScriptChromaGetKeyColorName(animation, frameIndex, key);

ScriptChromaStopComposite

The helper script stops a set of animations. The composite is a string. This method will stop the set of animations which includes ChromaLink, Headset, Keyboard, Keypad, Mouse, and Mousepad.

composite = "Random";
ScriptChromaStopComposite(composite);

ScriptChromaUninit

The helper script uninitializes the ChromaSDK and has no parameters.

ScriptChromaInit();

ScriptChromaCloseComposite

The helper script closes a set of animations so they can be reloaded from disk. The set of animations will be stopped if playing.

composite = "Random";
ScriptChromaCloseComposite(composite);

ScriptChromaGet1DColorName

The helper script gets the animation color for a frame given the 1D led. The led should be greater than or equal to 0 and less than the MaxLeds.

animation1D = 'Random_ChromaLink.chroma';
frameCount = ScriptChromaGetFrameCountName(animation1D);
device = ScriptChromaGetDeviceName(animation1D);
maxLeds = ScriptChromaGetMaxLeds(device);
for (frameIndex = 0; frameIndex < frameCount; ++frameIndex)
{
    for (led = 0; led < maxLeds; ++led)
    {
        color = ScriptChromaGet1DColorName(animation1D, frameIndex, led);
    }
}

ScriptChromaGet2DColorName

The helper script gets the animation color for a frame given the 2D row and column. The row should be greater than or equal to 0 and less than the MaxRow. The column should be greater than or equal to 0 and less than the MaxColumn

animation2D = 'Random_Keyboard.chroma'
frameCount = ScriptChromaGetFrameCountName(animation2D);
device = ScriptChromaGetDeviceName(animation2D);
maxRow = ScriptChromaGetMaxRow(device);
maxColumn = ScriptChromaGetMaxColumn(device);
for (frameIndex = 0; frameIndex < frameCount; ++frameIndex)
{
    for (i = 0; i < maxRow; ++i)
    {
        for (j = 0; j < maxColumn; ++j)
        {
            rowColumnIndex = i * maxColumn + j; // only 4 params allowed for DLL methods when string is involved
            color = ScriptChromaGet2DColorName(animation2D, frameIndex, rowColumnIndex);
        }
    }
}

ScriptChromaGetCurrentFrameName

The helper script gets the current frame of an animation.

animation2D = 'Random_Keyboard.chroma'
currentFrame = ScriptChromaGetCurrentFrameName(animation2D);

ScriptChromaSetCurrentFrameName

The helper script sets the current frame of an animation.

animation2D = 'Random_Keyboard.chroma'
frameId = 12;
ScriptChromaSetCurrentFrameName(animation2D, frameId);

ScriptChromaGetDeviceName

The helper script returns a number from the EChromaSDKDevice1DEnum or EChromaSDKDevice2DEnum of a Chroma animation respective to the deviceType, as an integer upon success. Returns -1 upon failure.

// 1D device
animation1D = 'Random_ChromaLink.chroma';
device = ScriptChromaGetDeviceName(animation2D);

// 2D device
animation2D = 'Random_Keyboard.chroma'
device = ScriptChromaGetDeviceName(animation2D);

ScriptChromaGetDeviceTypeName

The helper script returns a number from the EChromaSDKDeviceTypeEnum of a Chroma animation as an integer upon success. Returns -1 upon failure.

// 1D device type
animation1D = 'Random_ChromaLink.chroma';
deviceType = ScriptChromaGetDeviceTypeName(animation2D);

// 2D device type
animation2D = 'Random_Keyboard.chroma'
deviceType = ScriptChromaGetDeviceTypeName(animation2D);

ScriptChromaGetMaxColumn

The helper script returns the MAX COLUMN given the EChromaSDKDevice2DEnum device as an integer upon success. Returns -1 upon failure.

animation2D = 'Random_Keyboard.chroma'
device = ScriptChromaGetDeviceName(animation2D);
maxColumn = ScriptChromaGetMaxColumn(device);

ScriptChromaGetMaxLeds

The helper script returns the MAX LEDS given the EChromaSDKDevice1DEnum device as an integer upon success. Returns -1 upon failure.

animation1D = 'Random_ChromaLink.chroma';
device = ScriptChromaGetDeviceName(animation1D);
maxLeds = ScriptChromaGetMaxLeds(device);

ScriptChromaGetMaxRow

The helper script returns the MAX ROW given the EChromaSDKDevice2DEnum device as an integer upon success. Returns -1 upon failure.

animation2D = 'Random_Keyboard.chroma'
device = ScriptChromaGetDeviceName(animation2D);
maxRow = ScriptChromaGetMaxRow(device);

ScriptChromaSet1DColorName

The helper script sets the animation color for a frame given the 1D led. The led should be greater than or equal to 0 and less than the MaxLeds.

green = ScriptToBGRInt(0, 255, 0);
color = green;
animation1D = 'Random_ChromaLink.chroma';
ScriptChromaCloseAnimationName(animation1D);
frameCount = ScriptChromaGetFrameCountName(animation1D);
device = ScriptChromaGetDeviceName(animation1D);
maxLeds = ScriptChromaGetMaxLeds(device);
for (frameIndex = 0; frameIndex < frameCount; ++frameIndex)
{
    for (led = 0; led < maxLeds; ++led)
    {
        ScriptChromaSet1DColorName(animation1D, frameIndex, led, color);
    }
}
ScriptChromaPlayAnimationName(animation1D, 1.0);

ScriptChromaSet2DColorName

The helper script sets the animation color for a frame given the 2D row and column. The row should be greater than or equal to 0 and less than the MaxRow. The column should be greater than or equal to 0 and less than the MaxColumn.

animation2D = 'Random_Keyboard.chroma'
ScriptChromaCloseAnimationName(animation2D);
frameCount = ScriptChromaGetFrameCountName(animation2D);
device = ScriptChromaGetDeviceName(animation2D);
maxRow = ScriptChromaGetMaxRow(device);
maxColumn = ScriptChromaGetMaxColumn(device);
for (frameIndex = 0; frameIndex < frameCount; ++frameIndex)
{
    for (i = 0; i < maxRow; ++i)
    {
        for (j = 0; j < maxColumn; ++j)
        {
            rowColumnIndex = i * maxColumn + j; // only 4 params allowed for DLL methods when string is involved
            ScriptChromaSet2DColorName(animation2D, frameIndex, rowColumnIndex, color);
        }
    }
}
ScriptChromaPlayAnimationName(animation2D, 1.0);

Examples

ScriptAnimateOnKeyRelease.gml - detects key released events to invoke methods. This script is called from the room object released keyboard event.

ScriptDrawUI.gml - displays the keyboard shortcuts for the example. This script is called from the room object draw event.

ScriptGlobals.gml - initializes the globals and sets the DLL extension methods. This script is called from the room object create event. This is also where the keyboard enums are listed.

ScriptToBGRInt.gml - Converts red (0 to 255), green (0 to 255), blue (0 to 255) arguments into a BGR integer COLORREF.

image_6

Helper scripts wrap the Chroma DLL methods to make sure only defined methods are invoked.