Flash CS6
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: Flash CS6

  1. #1
    Junior Member
    Join Date
    Nov 2013
    Posts
    3

    Flash CS6

    Hi guys i really need help in making code for a side scroll score.

    I want to make the score based on distance traveled pretty the same as temple run i have my game and enemy's with hit box's collisions etc however i am having trouble coding the score on the HUD that i want

    Any help would be very appreciated guys and thank you in advance.

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,808
    Hi,

    It would be great if you could give a short summary of what you've already tried and what you have, 'cause we could then help you out with what you've already got

    but I'm going to try this in a simple way. Make first a Dynamic Textfield, give it an instance name of something like, score_txt, then click on your Frame and press F9 to open Actions panel, and type something like this:

    Code:
    score = 0;
    
    onEnterFrame = function(){
        score++;
        score_txt.text = score;
    }
    I am assuming you already have an onEnterFrame function, so just copy what's inside the onEnterFrame function in my code, and paste it in yours. What we essentially do, is to declare a variable named score with the starting value of 0, and then using onEnterFrame, which executes a set of codes over and over again, we keep increasing the score variable as time passes, and at the same time we set the textfield's text as the value of the score variable, so that we may see the value on screen

    If you have difficulties with variables, we can do this even simpler. Instead of giving your Dynamic Textfield an INSTANCE name, instead, give it a Variable name (find the field Var: in the properties panel after selecting your textfield), and type in there something like, score_txt. Then on your Frame, press F9, and type this in the actions panel:

    Code:
    score_txt = 0;
    
    onEnterFrame = function(){
        score_txt++;
    }
    Now, we assign the value of the variable score_txt as the value of our textfield, so it's automatically going to show that value. Then, we just keep increasing it by adding +1 to the value, and keep doing that over and over again using onEnterFrame function.

    If you find anything confusing, feel free to ask me about anything regarding this I hope this helps
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  3. #3
    Junior Member
    Join Date
    Nov 2013
    Posts
    3

    Flash cs6

    Quote Originally Posted by Nig 13 View Post
    Hi,

    It would be great if you could give a short summary of what you've already tried and what you have, 'cause we could then help you out with what you've already got

    but I'm going to try this in a simple way. Make first a Dynamic Textfield, give it an instance name of something like, score_txt, then click on your Frame and press F9 to open Actions panel, and type something like this:

    Code:
    score = 0;
    
    onEnterFrame = function(){
        score++;
        score_txt.text = score;
    }
    I am assuming you already have an onEnterFrame function, so just copy what's inside the onEnterFrame function in my code, and paste it in yours. What we essentially do, is to declare a variable named score with the starting value of 0, and then using onEnterFrame, which executes a set of codes over and over again, we keep increasing the score variable as time passes, and at the same time we set the textfield's text as the value of the score variable, so that we may see the value on screen

    If you have difficulties with variables, we can do this even simpler. Instead of giving your Dynamic Textfield an INSTANCE name, instead, give it a Variable name (find the field Var: in the properties panel after selecting your textfield), and type in there something like, score_txt. Then on your Frame, press F9, and type this in the actions panel:

    Code:
    score_txt = 0;
    
    onEnterFrame = function(){
        score_txt++;
    }
    Now, we assign the value of the variable score_txt as the value of our textfield, so it's automatically going to show that value. Then, we just keep increasing it by adding +1 to the value, and keep doing that over and over again using onEnterFrame function.

    If you find anything confusing, feel free to ask me about anything regarding this I hope this helps
    Hi thankyou for your response much appreciated

    here is the code i have on my game after the menu start game screen

    package
    {
    import flash.display.MovieClip;
    import flash.events.Event;
    import flash.utils.Timer;
    import flash.events.TimerEvent;



    public class Game extends MovieClip
    {
    private var scrollSpeed:Number = 5;
    public var enemy:Enemy;
    public var tank:Tank1;
    public var plane:Plane1;
    public var gameTimer:Timer;



    public function Game()
    {
    addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
    enemy = new Enemy();
    addChild( enemy );

    tank = new Tank1();
    addChild( tank );

    plane = new Plane1 ();
    addChild ( plane );

    }

    private function loop(e:Event):void
    {
    gb_01.x -= scrollSpeed;

    scrollSpeed += 0.05;
    enemy.moveDownABit(scrollSpeed);
    tank.moveDownABit(scrollSpeed);
    plane.moveDownABit(scrollSpeed);

    if ( ninja.hitTestObject( enemy ) || ninja.hitTestObject( tank ) || ninja.hitTestObject( plane ) )
    {
    gotoAndStop(2);
    removeEventListener(Event.ENTER_FRAME, loop);
    }
    }

    }

    }

    I don't use onEnterFrame so how would i go about imputing your code into mine so it works?

    Please excuse my complete lack of knowledge for coding i am a complete beginner as I'm currently studying computer Game design at uni and coding is not my strong point ;(

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

Poll by Flashkit.com