Cookie Inquiry for a single game

I scripted several modules that store cookie-like values in localstorage, or even send a player’s in-game data to third-party database. It definitely means that my web game needs to show a cookie policy and ask a permission for collecting a user’s preference and data before utilizing the resources. Is there any project that I can find as references for the cookie permission UX? Or any other suggestions or feedbacks?

Here are some example scripts related to localstorage and data-sending:

// initialize code called once per entity
BooleanButton.prototype.initialize = function() {
    this.boolean = true;
    this.element = this.entity.element;
    this.entity.button.on("click", this.toggle, this);
    this.entity.on("set:default", this.setDefault, this);
    // The property this.value will be equally used in any element in settings
    // that may differ based on the type of a button.
    // In this case, a boolean button will return this.boolean when a user requests its value.
    this.__defineGetter__('value', function() { return this.boolean; });

BooleanButton.prototype.postInitialize = function() {"requestDefault");

BooleanButton.prototype.setDefault = function(value) {
    const parseBoolean = (str) => str === 'true';

    this.boolean = parseBoolean(value);    

BooleanButton.prototype.toggle = function() {
    this.boolean = !this.boolean;

BooleanButton.prototype.setBoolean = function(_boolean) {
    if (this.element.type === "image")
    switch (_boolean) {
        case false: this.element.spriteFrame = 0; break;
        case true: this.element.spriteFrame = 1; break;
    }"set:value", this.value);
const Settings = pc.createScript('settings');

Settings.attributes.add('options', {
    type: 'json',
    array: true,
    schema: [{
        name: 'name',
        title: 'Name',
        type: 'string',
    }, {
        name: 'val',
        title: 'Default Value',
        type: 'string',
    }, {
        name: 'entity',
        title: 'UI Entity',
        type: 'entity',

// initialize code called once per entity
Settings.prototype.initialize = function() {
    this.options.forEach((option) => {
        let storedVal = localStorage.getItem(;
        option.entity.on("set:value", (_value) => localStorage.setItem(, _value), this);
        option.entity.on("requestDefault", () =>"set:default", (storedVal? storedVal: option.val)), this);
        if (!storedVal) localStorage.setItem(, option.val);
// initialize code called once per entity
Network.prototype.initialize = function() { = this;
    const parseBoolean = (str) => str === 'true';
    let enableDataTranmission = parseBoolean(localStorage.getItem("enableDataTranmission"));
    if (enableDataTranmission) {
        this.socket = io(/* Security Issue */);
        this.on("socket:emit", (str, ...args) => {
            args = args.filter(arg => arg);
            if (this.socket && this.socket.connected && typeof str == "string")
                this.socket.emit(str, args);
        }, this);

        this.socket.on("connect", () => {

        this.socket.on("disconnect", (reason) => {

Hey @Heein_Park, you’ll have to do this using HTML+CSS UI. Learn how to implement HTML & CSS UI in PlayCanvas here. Codepen is a great resource for finding inspiration for design templates, a simple google search like “codepen cookie banners” should find you some results you can take inspiration from. Here’s what I got from the same search.

Hope this helps!

Thank you for the answer. I’ve read the HTML+CSS example provided by Playcanvas, and then modified the code to individualize each entity that used the script module to prevent a stylesheet interruption. But also I want to establish some essential checklists before asking cookie-like data from a user. What details should be in the cookie notifications?

Hey @Heein_Park, check out this article -,how%20to%20exercise%20these%20rights. I think it does a fantastic job of touching on all the points you should take care of when you’re collecting data from users.

1 Like