How to add a text on image in kineticjs

Folks,

I have been searching for a longtime to write text on image in kineticjs..but its none of use..in some articles they mentioned we can use z-index like below..zI should be given with integer..

bet.setZIndex(zI);

But i sort it out without using that by placing kinetic text in kinetic image like shown below..

                                var imageObj = new Image();
 
                                imageObj.onload = function () {
                                    bet = new Kinetic.Image({
                                        x: xaxis,
                                        y: yaxis,
                                        image: imageObj
                                    });
                                    group.add(bet);
                                    layer.add(group);
                                    yaxis = yaxis - 7;
                                    var text = new Kinetic.Text({
                                        x: bet.getX(),//get x coordinate of image
                                        y: bet.getY() + 30, // get y coordinate of image
                                        text: '',
                                        fill: 'red',
                                        fontFamily: 'Cambria',
                                        fontSize: 19,
                                        fontStyle: 'bold',
                                        width: 118,
                                        height: 100,
                                        align: "center",
                                        verticalAlign: "middle"
                                    });
                                    text.setText(arg1); //set text on your image
                                    group.add(text);
                                    layer.draw(); 
 
 
                                };
                                imageObj.src = 'bet_chips/' + i + '.png';//image source
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s