craftyjs

cloned entity not draggable although original entity is ,crafyjs

人走茶凉 提交于 2020-01-25 10:25:07
问题 I am building this simple HTML5 drag and drop game using Craftyjs. I created an entity let's call it E1 with some components, one of the components is " Draggable ". I created a new entity E2 and made it as a clone of E1 (now E2 should have a copy of all E1's properties and components) on run, E2 is cloned with the same properties and attribute but it is not draggable! var E1 = Crafty.e("2D, Canvas, apple, Draggable, Gravity, Collision"); var E2 = E1.clone(); E2.attr({x:100, y:100}); E2

jQuery functions not working after JS innerHTML property

帅比萌擦擦* 提交于 2019-12-24 16:48:01
问题 I am using this code in my application: document.getElementById("inventory_box").innerHTML = "<img src='./img/rock.gif' id='test' />"; The #inventory_box element is present already, so it just spews out the IMG into #inventory_box . What I want is to be able to click this appeared IMG with id name test , but won't work like: $("#test").click(function() { // Run this }); 回答1: Try this, $(document).on('click',"#test",function() { alert('test'); }); Read on() 回答2: Since the image is added

Workaround for not being able to save booleans with HTML5 Web Storage

只愿长相守 提交于 2019-12-13 02:40:36
问题 I'm currently making a Mario-esque game with Javascript, or more precisely, CraftyJS. I've looked here as reference, and understand how to save values inputed by the user. But what I want to accomplish is to save certain booleans(is that what they are called?) automatically, or when the player presses a save button or something. For example, I have a dungeon called dungeon1, and I create a variable to represent whether or not the dungeon has been completed. It's var dungeon1 = false; by