Author Topic: Basic Game Tutorial  (Read 75996 times)

Austin East

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #120 on: Sat, Dec 5, 2009 »
I can't find the Preloader.as in the flixel files anywere... :-\

Austin East

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #121 on: Sat, Dec 5, 2009 »
I can't find the Preloader.as in the flixel files anywere... :-\

Never mind, I found it. For those with the same problem, look here. http://github.com/AdamAtomic/Mode

Atleast, thats a form of the preloader.

Could you also explain step 10 in more detail? Which class do we make an extension of FLxGame? And how would I do that?
« Last Edit: Sat, Dec 5, 2009 by Austin East »

Tycho

  • Guest
Re: Basic Game Tutorial
« Reply #122 on: Sat, Dec 5, 2009 »
I can't find the Preloader.as in the flixel files anywere... :-\

Never mind, I found it. For those with the same problem, look here. http://github.com/AdamAtomic/Mode

Atleast, thats a form of the preloader.

Could you also explain step 10 in more detail? Which class do we make an extension of FLxGame? And how would I do that?
That is a whole game I believe. But I'm sure downloading that game's preloader would work. Though I think it would be the same as just creating a new class titled "Preloader" I just don't want to have to create a new class every time I want to make a game.

Austin East

  • Member
  • **
  • Posts: 22
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #123 on: Sat, Dec 5, 2009 »
I can't find the Preloader.as in the flixel files anywere... :-\

Never mind, I found it. For those with the same problem, look here. http://github.com/AdamAtomic/Mode

Atleast, thats a form of the preloader.

Could you also explain step 10 in more detail? Which class do we make an extension of FLxGame? And how would I do that?
That is a whole game I believe. But I'm sure downloading that game's preloader would work. Though I think it would be the same as just creating a new class titled "Preloader" I just don't want to have to create a new class every time I want to make a game.

That's what I mean't ;D You could just use the preloader from Mode.

Haledire

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #124 on: Tue, Dec 8, 2009 »
Hi, pretty new here (came across flixel only a week ago).  I've got a couple questions (sorry if I'm a bit wordy).

Since I grabbed Flixel 1.27 without realizing it, I'd been trying to work through the tutorial with it as best I could but I seem to have come to a dead spot as soon as I reached the part of the tutorial concerning implementing the jumping enemies.

Reading up on the v1.3 planning thread in the bugs forum, I see that the collidearray2 was removed entirely and the hitfloor function requires a flxcore to activate (which reading the tutorial I assume it didn't need anything at the time).  I see fedekun's solution for collidearray2 above for the attacks, but is that the same solution for the tilemap collision?  It seems odd to remove a dedicated function for tilemap collision to arrays in favor of a manual coding method.  Granted I haven't seen what the old function did (haven't looked for a download for v1.25 just yet, and I didn't see a link on the site for it).

What would I need to add to the override for hitfloor to be able to use it?  I assume it needs to know about the map?  I'm a little sketchy on OOP so I'm not sure if the function would even be able to check the map from where it's being written, or if that is even the point of concern here (I've messed with AS 2 before, lightly touched on AS3, but I never really hit situations of overrides before).

I first ran across this issue when I was looking around and came across an old post from august about a more mario-styled timing based jumping system (this one) and didn't realize it was because the implementation of hitfloor had changed.  And apparently I didn't realize I left it commented out...

I was considering updating the wiki entry for this (since I see it hasn't been finished past section 3) but I don't really know the extent of the issues that the new flixel version has caused or how to fix them so... yeah... that would just be silly of me now wouldn't it...  I at least have the tutorial running to the point of having a little green ninja who can't jump...

Curois

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #125 on: Tue, Dec 8, 2009 »
Hey Haledire,
I ran into the same problem as you did. I however am stubborn, so I just copied the CollideArray2 method from an older Flixel build, into the newer, and the game works fine after that :)

BullitSpeed

  • Contributor
  • ****
  • Posts: 264
  • Karma: +0/-0
    • View Profile
    • My Website!
Re: Basic Game Tutorial
« Reply #126 on: Tue, Dec 8, 2009 »
Hey Haledire,
I ran into the same problem as you did. I however am stubborn, so I just copied the CollideArray2 method from an older Flixel build, into the newer, and the game works fine after that :)

haha the same moment you posted this, I posted a question about how to get around CollideArray2:

http://flixel.org/forums/index.php?topic=599.0

Curois

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #127 on: Tue, Dec 8, 2009 »
Hahahaha so I noticed :)
I would really like some to explain to me (a AS3 noob) why the removed CollideArray2, and what the alternative is (going to be). As long as I don't understand it, I'll leave my "hack" in place ;)

Haledire

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #128 on: Tue, Dec 8, 2009 »
quoting from the v1.3 planning thread:

4 - no need for CollideArray2() anymore, as all collision is between FlxCores and other FlxCores

Granted the Tilemap is a flxcore, but if you call out an array of another core (like the enemies in the tutorial), none of the built in collide functions seem to allow a collision to an array (only arrays to arrays) without specifically calling the cores within, so yeah - I'm just as confused.  I might have to grab that section of code in myself in the future unless I can figure out exactly what's going on.

The for loop from gummifer (I think i miscredited that before) works.  It seems the only thing different from collideArray2 is that it doesn't spend time checking to see if the Core exists.

I'm having a problem with the method 'collideArray2', it cant find it, has it changed name or something?

I had that problem too. In the end I used a for-loop to work around it. Like this:

for (var j:int = 0; j < playersStars.length;++j) {
   map.collide(playersStars[j]);
}

It seems to work. Though I'm experiencing a bug that sometimes makes the stars explode into sparks before throw them away. Like if they collide with the ground you're standing on or something.

Quote from: Flixel1.25 Code
   
Code: [Select]
static public function collideArray2(Core:FlxCore,Sprites:FlxArray):void
{
if((Core == null) || !Core.exists || Core.dead) return;
var sprite:FlxSprite;
for(var i:uint = 0; i < Sprites.length; i++)
{
sprite = Sprites[i];
if((Core === sprite) || (sprite == null) || !sprite.exists || sprite.dead) continue;
Core.collide(sprite);
}
}
Now if only I could understand what to do about the hitFloor/Wall/Roof functions to be able to properly implement any necessary update changes (I had ideas for gameplay that might require me calling the functions in some way).
« Last Edit: Tue, Dec 8, 2009 by Haledire »

Curois

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #129 on: Tue, Dec 8, 2009 »
Now that I'm finished with the tutorial, and I got the game working (can be found at www.dandymusic.eu/ninja), I have some questions about it:

* What is the deal with _move_speed and maxVelocity.x as defined in both Player and Enemy classes? How do they interact?

Code: [Select]
             private var _move_speed:int = 400;
private var _jump_power:int = 210;   
public var _max_health:int=10;
public var _hurt_counter:Number = 0;
private var _stars:FlxArray;
                      private var _attack_counter:Number = 0;

public function Player(X:Number,Y:Number,Stars:FlxArray):void
{
super(ImgPlayer, X, Y, true, true);
_stars = Stars;
//Max speeds
                      maxVelocity.x = 1000;
                      maxVelocity.y = 1000;
                      //Set the player health
                      health = 10;
                      //Gravity
                      acceleration.y = 420;

* In the Enemy class, I changed the enemy's health to 4:
Code: [Select]
_eStars = EnemyStars;
            _p = ThePlayer;
            //Max speeds
            maxVelocity.x = 1000;
            maxVelocity.y = 200;
            [b]health = 4;[/b]
            acceleration.y = 420;
The first enemy that spawns has 4 health, all the other enemies only 1. Can anyone explain why?
« Last Edit: Tue, Dec 8, 2009 by Curois »

Haledire

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #130 on: Tue, Dec 8, 2009 »
I hadn't gotten to that part myself just yet, but looking at the tutorial I think I can venture a guess:

Quote from: Tutorial
1. Add this to  your Enemy class after the last function. That last function should be the override of the kill function.

Code:
Code: [Select]
        public function reset(X:Number, Y:Number):void
        {
            x = X;
            y = Y;
            dead = false;
            exists = true;
            visible = true;
            play("normal");
        }

It seems the reset code in the tutorial doesn't reset the health of the respawning ninjas (note I say RE- the code logic is that if an enemy is alive, a new one is created, but if it is killed, it is respawned to reuse that portion of the array).  If you never kill the first ninja, the new ninjas are created with proper health, but if the first one is killed, it only reappears - with 0 health.  The change you made to the health code seems to have been placed on the enemies weapons, rather than their respawn.

And on _move_speed and maxVelocity.x:

I'm assuming _move_speed is your rate of acceleration, and maxVelocity is the limit to the speed at which you can move.  You can somewhat see it with how your character starts off really slow, but given the proper motivation can zip to the wall very quickly, if only for a split second.

Tycho

  • Guest
Re: Basic Game Tutorial
« Reply #131 on: Wed, Dec 9, 2009 »
Still need a clearer explanation to step 10   :)

Curois

  • Member
  • **
  • Posts: 6
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #132 on: Wed, Dec 9, 2009 »
I hadn't gotten to that part myself just yet, but looking at the tutorial I think I can venture a guess:

Quote from: Tutorial
1. Add this to  your Enemy class after the last function. That last function should be the override of the kill function.

Code:
Code: [Select]
        public function reset(X:Number, Y:Number):void
        {
            x = X;
            y = Y;
            dead = false;
            exists = true;
            visible = true;
            play("normal");
        }

It seems the reset code in the tutorial doesn't reset the health of the respawning ninjas (note I say RE- the code logic is that if an enemy is alive, a new one is created, but if it is killed, it is respawned to reuse that portion of the array).  If you never kill the first ninja, the new ninjas are created with proper health, but if the first one is killed, it only reappears - with 0 health.  The change you made to the health code seems to have been placed on the enemies weapons, rather than their respawn.

I'm sure the code I changed refers to the Enemies, and not their weapons (those are in the ninjastar code), but I think you could be right about the respawning part. So I'm gonna try that.
And on _move_speed and maxVelocity.x:

I'm assuming _move_speed is your rate of acceleration, and maxVelocity is the limit to the speed at which you can move.  You can somewhat see it with how your character starts off really slow, but given the proper motivation can zip to the wall very quickly, if only for a split second.

This means that if I want to make a powerup that makes the player run faster, I should change both variables right? Because if I only change the rate of acceleration, the player's speed still gets "capped" at maxVelocity.x if I'm correct.
Similarly, if I want to make a powerup that enables the player to jump higher, I have to change both the _jump_power, and maxVelocity.y, because I'd forget to change maxVelocity.y, the player would never be able to overcome the gravity enough to actually make use of a higher _jump_power. Am I correct in this?

Haledire

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #133 on: Wed, Dec 9, 2009 »
Curois -

ah yes, i saw the indent and assumed what was under it was a code process for the stars, didn't read it right and like I said, I haven't gotten that far in the tutorial.  I'm too busy messing with the jumping physics now that I understand what to do about the override.

On the jumping, if you just want to go higher, you simply need to change the max or the power, not both.  Quite honestly, after researching the code, I'm curious as to why the jump_power variable is even necessary as implemented in this tutorial, perhaps more a visual thing than an implementation purpose.  If they expanded it into the concept of powerups I would understand better.

I'll try to explain what I mean.  Jump Power sets the velocity of the jump, but it is cut off by the maxVelocity in the calculation.  The update function of a FlxSprite sets the velocity.y to what is calculated from FlxG.computeVelocity (literally, when you send 800, the first thing that is done on the first update is that 200 is set in it's place, so the 800 was irrelevant, and merely set so that you have a number that's larger than your max to get cut down).  The next calculation sent is that same 200, subtracted by the first percentage of gravity.  So the value sent never goes above the max value in the case of this tutorial.

Essentially, you can make your initial jump power lower than your max, and make the powerup add onto the jump power to make it reach the max (or at least get closer).

Conversely, you can send the max as your current velocity, and the powerup will change the max.

Either way, you will jump higher as the decay from the slowly growing acceleration (acceleration is 0 to start, and grows at a percentage) will need more time to completely overcome your velocity.

Tycho -

I assume you're talking about the first part of the tutorial?  If so, what is meant there is that in the class declaration, you add extends FlxGame to the end of that line.  Every time in the tutorial you are asked to extend the class, it means adding the word extends and the class name mentioned at the end of the line that says "public class".  

There's a sample code at the end of that part of the tutorial to double check what you've typed is right (though if you have Flixel v1.27 or 1.28, ignore the fact that it says com.adamatomic.flixel, it's become org.flixel now).
« Last Edit: Wed, Dec 9, 2009 by Haledire »

OnionsXD

  • Guest
Re: Basic Game Tutorial
« Reply #134 on: Thu, Dec 10, 2009 »
This is a really good tutorial! Hope it helps a lot of people out! Sure did 4 me!!

murkinesis

  • Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #135 on: Thu, Dec 10, 2009 »
i just started this tutorial. I'm on page 1. Here's my code so far:

platformTest2.as
Code: [Select]
package platformTest2
{
import com.adamatomic.flixel.*;

[SWF(width = "640", height = "480", backgroundColor = "#000000")]
[Frame(factoryClass = "Preloader")]

/**
* ...
* @author Murkinesis
*/
public class platformTest2
{

public function platformTest2()
{

}

}

}

and here's the error I'm getting:

Code: [Select]
G:\Progams\Flash Develop\new projects\platformTest2\src\platformTest2.as: Error: A file found in a source-path must have the same package structure '', as the definition's package, 'platformTest2'.
Build halted with errors (fcsh).

It doesn't say WHICH file doesn't have the same package structure, so I don't know which one. Is this because I unzipped flixel into my src folder as per the instructions, and the .as files contained therein are written with different packages?
Also, why is the flixel preloader no longer packaged with Flixel?

Haledire

  • Member
  • **
  • Posts: 74
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #136 on: Thu, Dec 10, 2009 »
It actually is telling you which file is wrong.  Your very first line:

package platformTest2

Since this is your main class, you don't need that platformTest2 there.  You are actually telling it to look for a sub folder called platformTest2 (which if you are following the tutorial would be in your src folder).

If you check the sample code at the end of the first post, you'll see that the package has nothing after it.

On the preloader - no idea.  You should be able to grab the preloader file from Mode on github.  It may be because Adam actually made this nice little python script that builds a game class, preloader class, menustate and playstate classes that can be set up pretty easily after they're all created.  Or it could be just how ridiculously small the file really is.

The file really isn't anything special, it's a simple class extending FlxFactory with two simple lines in it:

className = "Your Game Class' Name Here";
super();

This is what the entire code of a preloader is:
Code: [Select]
package
{
import org.flixel.data.FlxFactory;
 
public class Preloader extends FlxFactory
{
public function Preloader()
{
className = "Tutorial";
super();
}
}
}
 

Per project, the only thing you change is the text sent to className.  Granted, it would help if the tutorial had the information on either where to get the file or how to create it, as it wouldn't be the most obvious thing to set up regardless how small it is.

murkinesis

  • Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #137 on: Thu, Dec 10, 2009 »
Tycho -

I assume you're talking about the first part of the tutorial?  If so, what is meant there is that in the class declaration, you add extends FlxGame to the end of that line.  Every time in the tutorial you are asked to extend the class, it means adding the word extends and the class name mentioned at the end of the line that says "public class". 

There's a sample code at the end of that part of the tutorial to double check what you've typed is right (though if you have Flixel v1.27 or 1.28, ignore the fact that it says com.adamatomic.flixel, it's become org.flixel now).
Still need a clearer explanation to step 10   :)

The first post in this thread, containing the tutorial, should be updated to reflect this. Many people don't know what "To do this, we make this class an 'extension' of the FlxGame class." means.

Also, why is the package org.flixel? The flixel zipfile contains a different structure: AdamAtomic-Flixel-numbers/org/flixel actually. I had issues with my import because of this. Shouldn't the tutorial reflect this structure, or shouldn't the zip file have one less folder in it (specifically the AdamAtomic folder) so that the tutorial is accurate?

murkinesis

  • Member
  • **
  • Posts: 57
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #138 on: Thu, Dec 10, 2009 »
Ammending my previous post, much of the tutorial is now inaccurate.

Step 14, page 1:
Quote
Add a new folder to the "com" folder, and name it "Tutorial". Add a new Class to this folder, and name is "MenuState.as", and then, in your Tutorial.as file - right underneath your "import", add a new line...

There is no longer a com folder. Where should we put this "Tutorial" folder with the new flixel structure?

It seems like there's a lot of confusion about this recent flixel restructuring. Seems like the tutorial needs a good working-over to stay current. This tutorial is a programming foundation of people who are new to flixel, like myself. The arrival of Level Up! brought many people here, and it would be tragic if they were turned away by the frustration of following a defunct tutorial.

xmorpher

  • Member
  • **
  • Posts: 39
  • Karma: +0/-0
    • View Profile
Re: Basic Game Tutorial
« Reply #139 on: Thu, Dec 10, 2009 »
The solution is simple:
Specify that this tutorial is based on version 1.26 (linking to this version) and voilá