Search code examples
javascriptlimejs

Put two images in one LimeJS layer


I want to put two images within one LimeJS layer. The images should be aligned horizontally next to each other.

Adding one image into a layer is straight forward:

var myLayer = new lime.Layer().setPosition(0, 0)

var myImage = new lime.Sprite().setSize(800,400).setFill('myimage.png');

myLayer.appendChild(myImage);   

scene.appendChild(myLayer);

But to add two images into one layer doesn't seem possible. I have read LimeJS Docs however my class document reading experience is sketchy.

I have tried using the setOffset method on the Sprite class:

var myLayer = new lime.Layer().setPosition(0, 0);

var myImage = new lime.Sprite().setSize(800,400).setFill('myimage.png');
var myImage2 = new lime.Sprite().setSize(800,400).setFill('myimage.png')
             .setOffset(800, 0, true); // Uncaught TypeError: undefined is not a function

myLayer.appendChild(myImage);    
myLayer.appendChild(myImage2);    

scene.appendChild(myLayer);

But the above returns Uncaught TypeError: undefined is not a function

Maybe putting two images into one layer is not possible but any help is appreciated.


Solution

  • The typeError is occurring because the Sprite object does not include a setOffset method. That can be found on the lime.fill.Image object.

    Consider using the setPosition method, which Sprite inherits from lime.Node

    Here are the lime docs that relate to it:

    Class Lime Sprite

    Good luck!