Kobaltic Posted February 14, 2014 Share Posted February 14, 2014 Is there an equivalent of appendChild in Phaser. I tired game.world.add but that keeps telling me that the property is undefined. Thanks. Link to comment Share on other sites More sharing options...
rich Posted February 14, 2014 Share Posted February 14, 2014 To do what exactly? Link to comment Share on other sites More sharing options...
jcs Posted February 14, 2014 Share Posted February 14, 2014 game.add.existing( obj ) adds an existing object to the world if you have a specific Group that you want to add an object to, just call add() on that group. e.g. 'myGroup.add( some_object );' Link to comment Share on other sites More sharing options...
Kobaltic Posted February 14, 2014 Author Share Posted February 14, 2014 Alright, so I am working on a raycast engine. I ported one over into Phaser. I got everything working correctly except the rendering. It currently renders to a div and doesn't use Phaser. I am trying to fix that. Here is the section of the code that I am working on. The first line vars the "screen" div. The last line appends the child of "strip" . I am thinking that I need to change screen.appendChild(strip); to something like game.appendChild(strip). That is were my issue is. If more code would help let me know and I will put some more up.function initScreen() { var screen = $("screen"); for (var i = 0; i < screenWidth; i += stripWidth) { var strip = dc("div"); strip.style.position = "absolute"; strip.style.left = i + "px"; strip.style.width = stripWidth + "px"; strip.style.height = "0px"; strip.style.overflow = "hidden"; strip.style.backgroundColor = "magenta"; var img = new Image(); img.src = ("assets/wall.jpg"); img.style.position = "absolute"; img.style.left = "0px"; strip.appendChild(img); strip.img = img; // assign the image to a property on the strip // element so we have easy access to the image later screenStrips.push(strip); screen.appendChild(strip); // game.add.existing(strip); }} Link to comment Share on other sites More sharing options...
Kobaltic Posted February 15, 2014 Author Share Posted February 15, 2014 I tried adding it as a group and got this error. Same error I got with game.add.existing(strip). Link to comment Share on other sites More sharing options...
rich Posted February 15, 2014 Share Posted February 15, 2014 You can't add DOM elements into a Phaser Group or World. Link to comment Share on other sites More sharing options...
jcs Posted February 15, 2014 Share Posted February 15, 2014 yes, my bad. I misunderstood your initial post. I'm not really sure what you're after, but Phaser is drawn into a single canvas element. AFAIK, you can't add DOM elements to Phaser. if you could modify the raycast engine to render to a Canvas then perhaps you could use that as a texture and have Phaser render it Link to comment Share on other sites More sharing options...
Kobaltic Posted February 15, 2014 Author Share Posted February 15, 2014 Face 2 palm. Well I tried a direct port. Perhaps I will just have to code it all from scratch and make it canvas. Thanks for saving me more of a head ache. Link to comment Share on other sites More sharing options...
Recommended Posts