Xst load and display images.

XST is simple lib that I wrote in JavaScript to be easier to write some demos and little games in the canvas API HTML5.

This one shows how to load and display an image.


winscreen(640, 480, 0);
setfont(18, 'Algerian');
setcolor(rgb(255, 122, 150));

var player = new Entitie('player', 'player.png', 0, 0);

function main() {
clear();
drawtext("X: "+player.x, 0, 20);
drawtext("Y: "+player.y, 150, 20);
player.x = (getmousex()-(getimagewidth(player.image)/2));//center the mouse in image
player.y = (getmousey()-(getimageheight(player.image)/2));//center the mouse in image
drawtexture(player.image, player.x, player.y);//draw it
}

OR


winscreen(640, 480, 0);
setfont(18, 'Algerian');
setcolor(rgb(255, 122, 150));

var image = loadtexture('player.png');
var x, y;

function main() {
clear();
drawtext("X: "+x, 0, 20);
drawtext("Y: "+y, 150, 20);
x = (getmousex()-(getimagewidth(image)/2));
y = (getmousey()-(getimageheight(image)/2));
drawtexture(image, x, y);
}

Test it here.

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