Question

I have an html5 game I am working on. It uses Crafty game engine and using the boiler plate for the game engine which uses backbone, jquery, and require js. I have coded a new backbone interface I coded for the game but it does not respond to any event handlers. Is there something I am doing wrong. Here is my code:

Info = BaseEntity.extend({
defaults: {
        'text_begin' : "<span id='info_begin' style='text-shadow:2px 2px #000;cursor:pointer; '>bEGIN gAME</span>",
    },
    initialize: function(){
     var model = this;


     var entity = Crafty.e("2D, HTML, DOM, Text, Mouse")

     entity
            .attr({x: 20, y: 50, z: 1, w: 200})
            .text(model.get('text_begin'))
            .textColor('#FF0000')
            .textFont({'size' : '30px', 'family': 'Arial', 'weight': 'bold'})
            .setName('Begin Info')
.bind("Click", function(){console.log('hi tere')})




     model.set({'entity' : entity });
    }
});
Was it helpful?

Solution

Yes, you are misunderstanding how backbone is set up for the boiler plate for this game engine. Interfaces are basically 'read-only'. Read the wiki on the craft boiler plate. If you want to create new interactive crafty entities you need to create new entities , not interfaces.

So, for example, you would go to your scene file and declare a new entity:

sc['info'] = new Info();

You also want to make sure the AMD is calling your new entity file. Then basically that file you have ther could be moved to the entity folder and you should get your interactivity.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top