0

私はジャンパーに関するチュートリアルに従ってきましたが、現在パート 3 まで進んでいます。

参照: [url]http://chipacabra.blogspot.in/2010/12/project-jumper-part-3.html[/url]

パート 2 では、プレーヤーをマップに衝突させることに成功しましたが、パート 3 の指示をゲームに追加するように更新したところ、衝突が停止し、キャラクターが再び自由落下を開始しました。プログラムを作成するために、コードにいくつかの変更を加えました。コンパイルします (チュートリアルに書かれているコードの一部が古くなっているため、コメントに書かれているコードも古くなっています)。これは、コードに欠けている可能性のある何かが他にもあると信じることにつながります。私が使用しているマップの cvs および png ファイルは、第 3 部の最後にダウンロード リンクから入手できるソース コードに含まれているものです。

ここに私が持っているコードがあります:

Playstate.as:

package com.chipacabra.Jumper
{
    import org.flixel.*;

    public class PlayState extends FlxState
    {
        [Embed(source = '../../../../levels/mapCSV_Group1_Map1.csv', mimeType = 

'application/octet-stream')]public var levelMap:Class;
        [Embed(source = "../../../../levels/mapCSV_Group1_Map1back.csv", mimeType = 

"application/octet-stream")]public var backgroundMap:Class;
        //[Embed(source = '../../../../art/tilemap.png')]public var levelTiles:Class;
        // This was the old art, not using it anymore.
        [Embed(source = "../../../../art/area02_level_tiles2.png")]public var levelTiles:Class;
        //This is the new art.
        public var map:FlxTilemap = new FlxTilemap;
        public var background:FlxTilemap = new FlxTilemap;
        public var player:Player; 

        override public function create():void
        {
            add(background.loadMap(new backgroundMap, levelTiles, 16, 16));
            background.scrollFactor.x = background.scrollFactor.y = .5;
            add(map.loadMap(new levelMap, levelTiles, 16, 16));
            add(player = new Player(10, 10));
            FlxG.camera.setBounds(0, 0, 1600, 800);
            FlxG.camera.follow(player, FlxCamera.STYLE_PLATFORMER);
            //FlxG.follow(player);
            //FlxG.worldBounds.x = 0;
            //FlxG.worldBounds.y = 0;
            //FlxG.worldBounds.width = 1600;
            //FlxG.worldBounds.height = 800;

            super.create();
        }

        override public function update():void 
        {
            super.update();
            FlxG.collide(map, player);
        }
    }
}

Player.as:

package com.chipacabra.Jumper 
{
    import org.flixel.*;
    /**
     * ...
     * @author A. Velitsky
     */
    public class Player extends FlxSprite
    {
        [Embed(source = "../../../../art/helmutguy.png")]public var Helmutguy:Class;
        protected static const RUN_SPEED: int = 80;
        protected static const GRAVITY: int = 300; //originaly 420
        protected static const JUMP_SPEED: int = 200;

        public function Player(X:int,Y:int):void
        {
            super(X, Y);
            loadGraphic(Helmutguy, true, true);
            addAnimation("walking", [1, 2], 12, true);
            addAnimation("idle", [0]);
            drag.x = RUN_SPEED * 8 
            // Drag is how quickly you slow down when you're not
            // pushing a button.  By using a multiplier, it will
            // always scale to the run speed, even if we change it.
            acceleration.y = GRAVITY;
            // Always try to push helmutguy in the direction of gravity
            maxVelocity.x = RUN_SPEED;
            maxVelocity.y = JUMP_SPEED;
        }
        public override function update(): void
        {
            super.update();
            acceleration.x = 0; 
            // Reset to 0 when no button is

            if (FlxG.keys.LEFT)
            {
                facing = LEFT;
                acceleration.x = -drag.x;
            }
            else if (FlxG.keys.RIGHT)
            {
                facing = RIGHT;
                acceleration.x = drag.x;
            }
            if (FlxG.keys.justPressed("UP") && !velocity.y)
            {
                velocity.y = -JUMP_SPEED;
            }
            //Animation
            if (velocity.x != 0) { play("walking"); }
            else if (!velocity.x) { play("idle"); }

            super.update();
        }
    }

}

Jumper.as:

package
{
    import org.flixel.*; //Allows you to refer to flixel objects in your code
    import com.chipacabra.Jumper.PlayState;
    [SWF(width = "640", height = "480", backgroundColor = "#000000")] //Set the size and color of the 

Flash file
    [Frame(factoryClass="Preloader")]
    public class Jumper extends FlxGame
    {
        public function Jumper()
        {
            super(320, 240, PlayState, 2); //Create a new FlxGame object at 320x240 with 2x pixels, 

then load PlayState
            FlxG.bgColor = 0x8DEBFC;
        }
    }
}

Preloader.as:

package  
{
    import org.flixel.system.FlxPreloader;
    /**
     * ...
     * @author A. Velitsky
     */
    public class Preloader extends FlxPreloader
    {

        public function Preloader() 
        {
            className = "Jumper";
            super();
        }

    }

}

編集:うーん...チュートリアルへのコメントから取得したコードが...ほぼ正しいことがわかったようです...唯一間違っていたのは、カメラのビュースタイルが指定されていなかったことです。また、FlxG.camera.setBounds(0, 0, 1600, 800); のようです。呼び出す必要はありません... FlxG.camera.setBounds(); を使用する理由を知りたいのですが。これは、飛行機/宇宙船のシューティングゲームで使用するものでしょうか?

4

1 に答える 1

3

FlxG.camera.setBounds() は、レベルの境界を設定します。これを使用して、カメラがどこにあり、移動が許可されていないかをカメラに伝えることができます。setBounds が実際の世界の寸法よりも小さい場合、ゲームはその領域で更新されず、カメラも動きを停止します。

あなたの例では、FlxG.camera.setBounds(0, 0, 1600, 800) は 1600 の静的幅を設定しますが、これはおそらく必要以上であるため、カメラへの影響は実際には見られません。

ゲームの実際の幅に基づいて境界を設定するのが最善だと思います。私のゲームコードの一部は次のようになります。

//Set the max bounds of the stage
FlxG.worldBounds = new FlxRect (0,0,collisionMap.width-TILE_WIDTH,collisionMap.height);

//Attach the camera
FlxG.camera.setBounds(32,-64,FlxG.worldBounds.width-64,FlxG.worldBounds.height);
FlxG.camera.follow(player,FlxCamera.STYLE_PLATFORMER);

それが役立つことを願っています!

于 2014-12-22T19:40:03.243 に答える