Jump to content

Javscript help


Oroton
 Share

Recommended Posts

So
I have a sprite variable, and when I draw it i use,

 

	Sprite.prototype.draw = function() {

	    if (!this.flashOn) {

	        ctx.drawImage(

	            this.tileset.image,         

	            this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[0] * this.tileset.tileWidth,

	            this.states[this.currentState].frames[this.states[this.currentState].currentFrame].split(',')[1] * this.tileset.tileHeight,

	                        this.tileset.tileWidth,       

	            this.tileset.tileHeight,      

	            Math.round(this.x),

	            Math.round(this.y),

	            this.width,

	            this.height

	        );

	    }

	}

 

If I create a sprite, like this

 

	var spriteLeftAnim = new Animation(['1,1', '1,0'], 200);

	var spriteRightAnim = new Animation(['0,1', '0,0'], 200);

	var spriteUpAnim = new Animation(['2,1', '2,0'], 200);

	var spriteDownAnim = new Animation(['3,1', '3,0'], 200);


var spriteDefinitions = {
    turtle: new SpriteDefinition(
        tilesets.turtle,
        {                    
                        'left': spriteLeftAnim,
                        'right': spriteRightAnim,
                        'down': spriteDownAnim,
                        'up': spriteUpAnim
                }, //Added by Oroton,
        300, //200?
        5,
        true,
        true
    )

 


It runs perfectly,
I have to create another function for to run solid objects and i use this

 

var chestAnim = new staticObj(['3,0']);

	    chest: new SpriteDefinition(

	        tilesets.maptiles,

	        {

	            down: chestAnim

	        }

	    

 

these are the functions..

 

function Animation(frames, frameDuration) {
            this.frames = frames;
            this.currentFrame = 0;
            this.frameTimer = Date.now();
            this.frameDuration = frameDuration;
        }

function staticObj(frames) {
            this.frames = frames;
            this.currentFrame = 0;
        }

 

 

 

What I want to do is instead of writing

 

	[code]var chestAnim = new staticObj(['3,0']);

	    chest: new SpriteDefinition(

	        tilesets.maptiles,

	        {

	            down: chestAnim  //change this here

	        }

 

 

Write for the solid objects, but what happens is when i draw the item, it under currentState.frames..

 

	[code]var chestAnim = new staticObj(['3,0']);

	    chest: new SpriteDefinition(

	        tilesets.maptiles,

	        {

	            down: '3,0' //to this here

	        }

 
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...