四方向A星寻路

这篇博客详细介绍了四方向的A*寻路算法在游戏开发中的应用,包括块类的设计、主场景类的实现,并针对可能出现的问题进行了讨论,如寻路过程中多出一两步的情况及其解决方案。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

步骤解释可参考http://blog.youkuaiyun.com/agroupofruffian/article/details/77700338,本示例即按照该步骤而来;
主场景皮肤:
<?xml version="1.0" encoding="utf-8"?>
<e:Skin class="aStarWin" width="800" height="600" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing">
	<e:Rect width="800" height="600"/>
	<e:Rect width="600" height="600" horizontalCenter="0" verticalCenter="0" fillColor="0x53ea09"/>
	<e:ToggleButton id="btnSetTag" label="设置障碍" x="700" y="0"/>
	<e:ToggleButton id="btnStartPos" label="设置起点" x="700" y="60"/>
	<e:ToggleButton id="btnSetEndPos" label="设置终点" x="700" y="120"/>
	<e:ToggleButton id="btnFindWay" label="开始寻路" x="700" y="180"/>
	<e:ToggleButton id="btnReset" label="重置" x="700" y="240"/>
	<e:Group id="blockGroup" width="600" height="600" horizontalCenter="0" verticalCenter="0">
		<e:layout>
			<e:TileLayout requestedRowCount="10" requestedColumnCount="10" horizontalGap="0" verticalGap="0"/>
		</e:layout>
	</e:Group>
</e:Skin>
-------------------------------分割线-------------------------------
单块皮肤
<?xml version="1.0" encoding="utf-8"?>
<e:Skin class="block" width="60" height="60" xmlns:e="http://ns.egret.com/eui" xmlns:w="http://ns.egret.com/wing">
	<e:Rect id="rectBG" width="50" height="50" x="5" y="5" fillColor="0x096BE8"/>
	<e:Label id="lbX" text="Label" size="15" horizontalCenter="0.5" verticalCenter="-16.5" touchEnabled="false"/>
	<e:Label id="lbY" text="Label" size="15" horizontalCenter="0.5" verticalCenter="3.5" touchEnabled="false"/>
	<e:Label id="lbCode" text="Label" y="41" size="15" horizontalCenter="0"/>
</e:Skin>

-------------------------------分割线-------------------------------
块类

module ui {
    export class Block extends eui.Component {
        private rectBG: eui.Rect;
        private lbX: eui.Label;
        private lbY: eui.Label;
        private lbCode: eui.Label;
        public data: BlockData = null;
        public lastBlcok: ui.Block = null;
        constructor(data: ui.BlockData) {
            super();
            this.data = data;
            this.addEventListener(eui.UIEvent.COMPLETE, this.uiComplete, this);
            this.addEventListener(egret.Event.ADDED_TO_STAGE, this.addToStage, this);
            this.skinName = "resource/ui/block.exml
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值