dcsimg
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: A Line In AS2 Is Freezing The Game

Hybrid View

  1. #1
    Junior Member
    Join Date
    Aug 2015
    Posts
    26

    A Line In AS2 Is Freezing The Game

    I started to work on a new code (last one was for a fighting game but as the guy never finished them, I can't do anything else atm) that does work---but it freezes the game, why? Here's the code.

    stop();
    xSpeed = 0;
    maxSpeed = 20;
    maxSpeed2 = -20;
    slowSpeed = 1;
    var grav:Number = 0;
    var gravity:Number = 10;
    var maxJump:Number = -9;
    var toughingGround:Boolean = false;
    Son.onEnterFrame = function() {
    this._x += xSpeed;
    //gravity
    Son._y += grav;
    grav += gravity;
    while (ground.hitTest(Son._x, Son._y, true)) {
    }
    if (ground.hitTest(Son._x, Son._y+5, true)) {
    toughingGround = true;
    jumping = false;
    } else {
    toughingGround = false;
    }
    if (Key.isDown(Key.SPACE) && toughingGround) {
    jumping = true;
    grav-maxJump;
    } else if (Key.isDown(Key.RIGHT)) {
    this._xscale = 100;
    if (xSpeed>10) {
    this.gotoAndStop("SonRun");
    } else {
    this.gotoAndStop("SonWalk");
    }
    if (xSpeed<maxSpeed) {
    xSpeed += 1;
    }
    } else if (Key.isDown(Key.LEFT)) {
    this._xscale = -100;
    if (xSpeed<-10) {
    this.gotoAndStop("SonRun");
    } else {
    this.gotoAndStop("SonWalk");
    }
    if (xSpeed>maxSpeed2) {
    xSpeed -= 1;
    }
    } else if (xSpeed>0) {
    this.gotoAndStop("SonBreak");
    xSpeed -= slowSpeed;
    } else if (xSpeed<0) {
    this.gotoAndStop("SonBreak");
    xSpeed += slowSpeed;
    }
    };
    So what's freezing the game? The line

    while (ground.hitTest(Son._x, Son._y, true)) {
    is causing it to freeze up. I tested it and when I change the word "while" to "if" Sonic falls off screen, but the game no longer freezes. I spent over an hour with an friend to try and fix this and I even messaged the guy who made the tut videos (still awaiting a reply), but so far no luck is fixing this.

    Can anyone tell me how to fix this? I really hate AS, I do, but it is what it is. I can't fix it so asking for help. If get a reply back from the guy I'll post here saying so.

    https://www.youtube.com/watch?v=mkrt24B_Lvs&index=59

    AND BEFORE YOU ASK! No, his fla files are a unexpected format so flash 8 can't open them.

  2. #2
    Senior Member
    Join Date
    Aug 2012
    Posts
    124
    what about the fla that you use to work on, not need other fla.
    you not like AS becose you not know it well, simple as.

  3. #3
    Junior Member
    Join Date
    Aug 2015
    Posts
    26
    Quote Originally Posted by Terrencing View Post
    what about the fla that you use to work on, not need other fla.
    you not like AS becose you not know it well, simple as.
    That was for a fighting game, the guy stopped before showing how to do AI movement and such. This code is for a Sonic game, I didn't give up on the other code it's just there's nothing more to do with it atm until the guy posts another part or I find an AI script, which the Sonic tuts above will get into later as I checked ahead of time.

    Quote Originally Posted by realMakc View Post
    change

    while (ground.hitTest(Son._x, Son._y, true)) {

    to

    var count = 10;
    while (ground.hitTest(Son._x, Son._y, true) && (count-->0)) {
    I'll try it, I'll edit in whether or not it works (flash takes like a full min to open)

    EDIT:Well the game doesn't freeze but Sonic falls off screen, gonna mess around a bit but I'll look back to see if you posted anything else.
    Last edited by Cody2819; 06-21-2016 at 11:28 AM. Reason: Updating.

  4. #4
    Junior Member
    Join Date
    Aug 2015
    Posts
    26
    OK I edited it to

    while (ground.hitTest(Son._x, Son._y, true) && grav-->0) {

    and Sonic does touch the ground, but he won't stop bouncing up and down. At least we're getting somewhere.

    EDIT:With the var count do I add it increasing and decreasing wherever the grav/gravity does?
    Last edited by Cody2819; 06-21-2016 at 11:56 AM.

  5. #5
    Senior Member realMakc's Avatar
    Join Date
    Oct 2002
    Posts
    916
    change

    while (ground.hitTest(Son._x, Son._y, true)) {

    to

    var count = 10;
    while (ground.hitTest(Son._x, Son._y, true) && (count-->0)) {
    who is this? a word of friendly advice: FFS stop using AS2

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center