flash actionscript:
I want to make a game like the classic mario games where you jump over the blocks. when attempting to make this i keep having to put in the seperate axis in so if i had a block at 93 on the x-axis i have to put ON(Keypress("<Right>"){ this._x += 5 if(this._x >= 93) this._x = 93} and then do the same again and again for the following block so can someone help me by either telling me a basic code which will stop my character moving through the blocks from all angles or any other way in which i can do it. Thanks...
thanks, but im only a kid learning the basic and when i tried to do the hit test it worked but still didn't stop my character from every angle, so could you tell me in more detail because im pretty clue-less. thanks...
if your blocks are movieclips with instance names block1, block2, ..., block99, you can use: ON(Keypress("<Right>"){ this._x += 5 for(var i=1;i<99;i++){ if(this.hitTest(_root["block"+i])){ this._x-=5; // adjust this line to undo your keypress result for you left, up and down keys. break; } } }
try: ON(Keypress("<Right>"){ this._x += 5 for(var i=1;i<99;i++){ mc=_root["block"+i]; if(this.hitTest(mc)&&this._y<mc._y+mc._height){ this._x-=5; // adjust this line to undo your keypress result for you left, up and down keys. break; } } }
i'm not accectly sure how to use that code but it dosn't seem to work propaly. basically i've created a gravity rule so if you jump you come back down but it does still not stop when landing on a block but the first code you sent was perfect.
them codes are working now but it still doesn't let me land on the blocks from. i am using the code : on(keyPress"<Up>"){ this._x += 100} this still needs some editing but when my bloke comes down he just falls through the block still.
in the gravity portion of you code that controls your mario's downward movement (after jumping), insert the following (assuming that portion of your code is attached to your mario character).: for(var i=1;i<99;i++){ mc=_root["block"+i]; if(this.hitTest(mc)){ this._y=mc._y-mc._height; break; } }
Don't see what you're looking for? Try a search.
|