Top Section

Welcome to my computer games design blog ..

Thursday, 22 February 2018

editing the code

Ok so lets look at the code in the HTML file

First we have a peoload funtion that loads all the sprite assets up, we have 4 in this example. The sky the ground a star to collect and of course our animated dude! This function runs code runs once.

function preload() {

    game.load.image('sky', 'assets/sky.png');
    game.load.image('ground', 'assets/platform.png');
    game.load.image('star', 'assets/star.png');
    game.load.spritesheet('dude', 'assets/dude.png', 32, 48);


Next we have some variable to store all the elements we need.

var player;
var platforms;
var cursors;
var stars;

Next we have the create function to put on screen all our assets needed for this game (or a level).
This function runs code runs once.

function create() { all code for putting assets on screen first time goes here }

Then last but not least we have the update function. This function runs until its exited.

function update() { 
all code for :-
Collision detection
animation control

Other functions can be added that are called in the update function. In this example its collectStar function.

All this is based from this example

When you have understood this you are ready to try game states (this link)