Search the Community
Showing results for tags 'framework independant'.
-
Hi all, I was having a look at some code for a platformer and decided I didn't like the way the character locked on to the platform before having finished jumping. So I made my own code, Woo Hoo! In my version I use the createjs class for my bitmap images, other than that, it's just js. I've used 'base' , 'base2', and 'base3' as platforms - same image - just scaled and loaded with different id's - but do it your way - doesn't matter. Whatever image will work. You can determine the width and height of an image apart from it's actual width and height. So say you have a platform image 10px height but half of that image is a drop shadow. Simply call the the image; myImage.height = 5; then your character won't bang it's head on a drop shadow. X and Y values for platforms are recorded just where you put them. In the below code there is no platform that shares the same same y co-ordinate but that would be easy. if (character.y < platform1.y && character.x > platform1.x + 400 && character.y < Platform2.y){ //plus 400 is width of platform 1 platform2 = path} /// DON"T SHOOT ME / HAVEN'T TRIED THIS YET. first make a path... function path(width, height, x, y){ this.width = width; this.height = height; this.x = x; this.y = y;}easy. Then..... if(helpmeghost.y < base.y){ path = base;}elseif(helpmeghost.y > base.y && helpmeghost.y < base2.y){ path = base2;}elseif(helpmeghost.y > base.y && helpmeghost.y > base2.y && helpmeghost.y < base3.y){ path = base3;}Wow! Basic. vy+=gravity; //apply gravity to downward motion if (inAir){ //if not touching platform apply gravity to ghost helpmeghost.y+=vy; } if (vy>15){//limit falling speed vy=15; } if ( helpmeghost.x >= path.x && helpmeghost.x <= path.width && helpmeghost.y >= path.height && helpmeghost.y >= path.y) { helpmeghost.y=path.y; // set pos of ghost to platform/base/path vy=0; // switch gravity off jumping = false; inAir = false; }else{ inAir = true; } if(helpmeghost.x>=550){helpmeghost.x = 550} //keep ghost on stage if(helpmeghost.x<=60){helpmeghost.x =60}You can see all the code (I wouldn't look at it unless I had to) and results here... http://momogames.altervista.org/haunted/