我按照這裏的教程... http://x01010111.com/haxeflixel.php#w3Haxeflixel:以下嘖嘖,只得到一個黑色的屏幕
我到了他說,部分「真棒,但」並試圖編譯,只有什麼都沒有顯示。我試着比較我的代碼和他的許多次,進入教程(當他第一次提到應該只有一個白色背景,並且我編譯進行比較時,我最初停止了)來查看問題是否會消失(想想它可能已經有些過時了,等等)。我搜索了四周尋找解釋,發現我不知道要搜索什麼,並沒有發現任何有用的東西。
我在安裝過程中沒有改變任何東西,我以前沒有問題編譯過很多次(在同一個教程中無數次),所以它是前進部分中的一些東西,我錯了我的想法。
因此,沒有任何顯示,這是我的PlayState.hx代碼。
package;
import flixel.FlxG;
import flixel.FlxSprite;
import flixel.FlxState;
import flixel.FlxObject;
import flixel.tile.FlxTilemap;
import flixel.text.FlxText;
import flixel.ui.FlxButton;
import flixel.util.FlxMath;
import flixel.util.FlxStringUtil;
import flixel.FlxCamera;
import flixel.group.FlxGroup;
import flixel.text.FlxText;
import flixel.util.FlxTimer;
import openfl.Assets;
/**
* A FlxState which can be used for the actual gameplay.
*/
class PlayState extends FlxState
{
var level:FlxTilemap;
var player:FlxSprite;
/**
* Function that is called up when to state is created to set it up.
*/
override public function create():Void
{
FlxG.camera.bgColor = 0xFF6DC2CA;
addLevel();
addPlayer(2, 22);
setCamera();
super.create();
}
/**
* Function that is called when this state is destroyed - you might want to
* consider setting all objects this state uses to null to help garbage collection.
*/
override public function destroy():Void
{
super.destroy();
}
/**
* Function that is called once every frame.
*/
override public function update():Void
{
super.update();
FlxG.collide(level, player);
playerMovement();
}
function playerMovement():Void
{
player.velocity.x = 0;
if(FlxG.keys.pressed.LEFT) player.velocity.x -= 100;
if(FlxG.keys.pressed.RIGHT) player.velocity.x += 100;
if(FlxG.keys.justPressed.SPACE && player.isTouching(FlxObject.FLOOR)) player.velocity.y = -200;
}
function addLevel():Void
{
level = new FlxTilemap();
level.loadMap(Assets.getText("assets/data/Map1_Level.csv"), "Assets/images/tiles.png", 16, 16);
add(level);
}
function setCamera():Void
{
FlxG.camera.follow(player, FlxCamera.STYLE_PLATFORMER);
FlxG.camera.setBounds(0, 0, level.width - 16, level.height - 16, true);
}
function addPlayer(X:Int, Y:Int):Void
{
player = new FlxSprite(X * 16, Y * 16 - 8);
player.makeGraphic(6, 8, 0xFFFF0000);
player.acceleration.y = 800;
add(player);
}
}
而且Main.hx ...
package;
import flash.display.Sprite;
import flash.display.StageAlign;
import flash.display.StageScaleMode;
import flash.events.Event;
import flash.Lib;
import flixel.FlxGame;
import flixel.FlxState;
class Main extends Sprite
{
var gameWidth:Int = 320; // Width of the game in pixels (might be less/more in actual pixels depending on your zoom).
var gameHeight:Int = 240; // Height of the game in pixels (might be less/more in actual pixels depending on your zoom).
var initialState:Class<FlxState> = PlayState; // The FlxState the game starts with.
var zoom:Float = 2; // If -1, zoom is automatically calculated to fit the window dimensions.
var framerate:Int = 60; // How many frames per second the game should run at.
var skipSplash:Bool = false; // Whether to skip the flixel splash screen that appears in release mode.
var startFullscreen:Bool = false; // Whether to start the game in fullscreen on desktop targets
// You can pretty much ignore everything from here on - your code should go in your states.
public static function main():Void
{
Lib.current.addChild(new Main());
}
public function new()
{
super();
if (stage != null)
{
init();
}
else
{
addEventListener(Event.ADDED_TO_STAGE, init);
}
}
private function init(?E:Event):Void
{
if (hasEventListener(Event.ADDED_TO_STAGE))
{
removeEventListener(Event.ADDED_TO_STAGE, init);
}
setupGame();
}
private function setupGame():Void
{
var stageWidth:Int = Lib.current.stage.stageWidth;
var stageHeight:Int = Lib.current.stage.stageHeight;
if (zoom == -1)
{
var ratioX:Float = stageWidth/gameWidth;
var ratioY:Float = stageHeight/gameHeight;
zoom = Math.min(ratioX, ratioY);
gameWidth = Math.ceil(stageWidth/zoom);
gameHeight = Math.ceil(stageHeight/zoom);
}
addChild(new FlxGame(gameWidth, gameHeight, initialState, zoom, framerate, framerate, skipSplash, startFullscreen));
}
}
我一直在Haxeflixel並與先前的例外過時教程它一直運行的東西變成了一些問題至今愚蠢的是我做錯了。
編輯:我試着使用調試模式來顯示更多信息,但它沒有顯示任何錯誤,或任何其他事情。我打了〜看看有沒有我錯過的地方,而且什麼也沒有。我在調試模式下尋找什麼?
我使用的Flash播放器投影機調試的內容來運行我的.swf
新增Main.hx
Map1_level.csv是否存在? – 5Mixer
在閃存上,「黑屏」通常意味着拋出異常。您需要使用Flash _Debug_ Player查看例外情況。錯誤信息應該有助於確定問題。 – Gama11
Map1_Level.csv存在,位於正確的文件夾中。 我已經看到發佈中的錯誤,所以我想它會很好,感謝糾正我! – Ajacmac