Haxeflixel:跟随啧啧,只得到黑屏
Haxeflixel: following tut, only getting a black screen
我正在学习这里的教程...http://x01010111.com/haxeflixel.php#w3
我到了他说 "Awesome, but" 的部分并尝试编译,只是没有显示任何内容。我多次尝试将我的代码与他的代码进行比较,进一步深入教程(当他第一次提到应该只有白色背景时我最初停止了,我编译进行比较)看看问题是否会消失(思考它可能有些过时,等等)。我四处寻找解释,发现我不太清楚要搜索什么,也没有找到任何有用的东西。
我没有在我的安装中做任何更改,我之前编译过很多次都没有问题(在同一个教程中多次),所以我认为在前进部分我做错了。
所以,没有显示任何内容,这是我的 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 Player Projector Content Debugger 运行 我的 .swf
已添加Main.hx
尝试运行使用教程提供的资源编写代码时,我在编辑器输出面板中收到以下[=23=]时间错误(我使用的是 sublime 文本)
Assets.hx:149: [openfl.Assets] There is no BitmapData asset with an ID of "Assets/images/tiles.png"
如果我们查看第 76 行的 PlayState.hx,我们可以看到它正在尝试加载资产 "Assets/images/tiles.png"
。资产查找区分大小写,资产目录实际上默认为小写,因此需要更改为 "assets/images/tiles.png"
这样做之后,代码 运行 对我来说很好。
请注意,我没有使用 flash 来调试它,而是使用 neko。如果您在 flash 中读取调试输出时遇到问题,您可能最好先使用 neko 进行测试,然后再针对 flash 或您的目标 platfokrm 进行部署。
我正在学习这里的教程...http://x01010111.com/haxeflixel.php#w3
我到了他说 "Awesome, but" 的部分并尝试编译,只是没有显示任何内容。我多次尝试将我的代码与他的代码进行比较,进一步深入教程(当他第一次提到应该只有白色背景时我最初停止了,我编译进行比较)看看问题是否会消失(思考它可能有些过时,等等)。我四处寻找解释,发现我不太清楚要搜索什么,也没有找到任何有用的东西。
我没有在我的安装中做任何更改,我之前编译过很多次都没有问题(在同一个教程中多次),所以我认为在前进部分我做错了。
所以,没有显示任何内容,这是我的 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 Player Projector Content Debugger 运行 我的 .swf
已添加Main.hx
尝试运行使用教程提供的资源编写代码时,我在编辑器输出面板中收到以下[=23=]时间错误(我使用的是 sublime 文本)
Assets.hx:149: [openfl.Assets] There is no BitmapData asset with an ID of "Assets/images/tiles.png"
如果我们查看第 76 行的 PlayState.hx,我们可以看到它正在尝试加载资产 "Assets/images/tiles.png"
。资产查找区分大小写,资产目录实际上默认为小写,因此需要更改为 "assets/images/tiles.png"
这样做之后,代码 运行 对我来说很好。
请注意,我没有使用 flash 来调试它,而是使用 neko。如果您在 flash 中读取调试输出时遇到问题,您可能最好先使用 neko 进行测试,然后再针对 flash 或您的目标 platfokrm 进行部署。