- 浏览: 314951 次
- 性别:
- 来自: 益阳
文章分类
最新评论
-
duckbit:
楼主是否能把共享layout的例子发给我,有点没明白 谢谢额! ...
Android换肤apk -
天涯海角262253:
...
Androidpn里的Xmpp的理解 -
lbstudy:
Activity之间的切换动画 -
dumbnesslys:
楼主可不可以给个源码 ,就build.xml的 772774 ...
Ant自动打包 -
finaljava:
build.xml 这么复杂,看看这个吧http://angr ...
Ant自动打包
Replica Island is a tile-based game, which means that the levels are laid out using small (32x32), reusable tiles. I chose this approach for two reasons: it's memory efficient and exceedingly common for this genre. With a tile-based game you define a set of tiles--in the case of Replica Island, a single texture representing each possible tile--and then draw the level by combining those tiles together. Even if you have a lot of levels you don't need to spend a lot of disk space (or runtime memory) on the actual art for the tiles, and the data describing the layout of each level is very small. So tiles are useful for games that have a lot of levels and wish keep the total size of their application down. Tiles are also the standard way to make side scrolling games. Pre-Sony Playstation 1 game hardware (and some post-PS1 hardware, like the Nintendo GameBoy Advance) was hardwired to deal with tiles because of these efficient properties, and as a result the vast majority of side-scrolling games are tile-based. So going with a tile-based game engine also made sense because it helps the game feel like a proper side scroller.
So when it came time to write a collision system to represent level geometry for Replica Island, tiles seemed like a natural choice. I already had a tool for editing tiles and tile maps, as well as runtime code for loading tile sets and maps, so using tiles for collision meant I could leverage a lot of existing infrastructure. Also, maintaining a 2D array of collision tiles in memory was appealing because it's very fast to query the contents of any particular tile; while many collision systems organize their data in trees, doing so requires that the tree be traversed for every collision test. A 2D array, on the other hand, can be indexed directly into, which is very fast (the down side is that these arrays are generally sparse, so there is a lot of runtime memory wasted; however, for the size of the levels I was considering and the available ram on Android devices, the memory required of an array to describe the level is trivially small).
Tile-Based Line Segment Collision? Huh?
The problem with using tiles for collision is that they are basically square. The simplest implementation is to simply consider the collision world a 2D grid of booleans, set to true in grid cells that are "solid" and false to cells that are "empty." Using this method you can calcuate the location of a collision cell in game space and then check to see if it is solid or not before deciding if, for example, your player can move forward. While that's a very simple approach (and I shipped a few games that worked that way back in the day), it's not really going to scale to the types of interesting level designs that modern players expect. At the very least you want to be able to support a sloped surface so you can make hills and valleys, and ideally you should be able to express bumps, spikes, curves, and other shapes that are much more complicated than a simple solid cube.So, for Replica Island, I decided to implement a collision system based on arbitrary line segments, stored as shapes in tiles and laid out in the world as a tile map. The idea is pretty straightforward: within a 32x32 collision tile I can define any number of line segments, which can have arbitrary angles and normals. I can use my tile editor tools to lay the collision tiles out and at runtime I can leverage the speed of a 2D array (direct index into the current tile) to find a set of potentially-intersecting line segments. The nice thing about line segments is that they can contain both a slope and a normal, which allows for all kinds of interesting physics calculations without a lot of code (for example, to make a ball bounce convincingly off an angled surface you can simply reflect the ball's velocity about the normal of the surface). I've used similar systems (though never stored as tiles) on a lot of other games and, at least for 2D collision worlds, I'm quite happy with the approach.
Data Generation
Once I had settled on the line-segments-in-tiles approach, the problem became actually generating the line segment data for each tile. Genki, the artist behind Replica Island, generated a set of collision tiles that would serve as the basic building blocks of our levels, but now I needed a way to represent that same data as line segments. I've had success with edge-tracing algorithms in the past but my experience with them also suggested that they require a bit of tuning to get right. And since collision detection and response is so closely tied into core game play, I wanted a way to hand-modify individual segments. When I worked in games development full time we would just sit down and write an editor tool for this kind of thing, but one of my goals with Replica Island is to see how simply (read: cheaply) I can get it finished, so writing a dedicated tool was a little out of scope. So I decided to piggyback on some existing tool to generate the data that I needed. After thinking about it for a bit, I settled on Photoshop.Did you know that you can actually script Photoshop with Javascript? I did not know this, but it's actually pretty easy to do (if neigh undebuggable). After a day of futzing around with Photoshop's Javascript API I had a tool that would walk Photoshop paths and generate a list of line segments with normals (calculated by requiring the path be closed and by assuming that all normals point away from the centroid of the path shape). Since I couldn't figure out a way to actually write out a text file from Photoshop, the script opens a new document, creates a text layer, and then dumps its output into that layer. Once the script was written I went over Genki's collision tileset with the path tool and generated unique paths for each tile. I also added a very simple tool to take the text output of my script and pack it as binary data for loading at runtime. It took a total of about three days to go from having no collision data to having a full tileset of data, ready for use at runtime.
Querying Collision at Runtime
So, now I have two different sets of data: I have a single collision tile set, which maps collision tile indicies to collections of line segments, and a bunch of collision tile maps (one for each level) that place individual collision tiles in space to describe level geometry. I can load the collision tile set once and keep it around; each level that I load brings with it its own collision tile map. At runtime, to check to see if a region of space in the game world is blocked or not, I can cast a ray through the tile map (using one of my favorite algorithms: the Bresenham line algorithm) and check it against the collision tiles that it touches. The actual line segment vs line segment test is pretty simple (here's a useful reference), and it produces an exact intersection point. As soon as an intersection is detected the ray test can be aborted and the results returned (note that it's necessary to test the ray against all segments in a particular tile, though; you always want the intersection point closest to the origin of the ray, so all segments within a given tile must be tested and only the closest intersection returned). It's also possible to test a collision volume against the world by simply visiting each cell that intersects the volume and doing a volume vs line test, but in Replica Island this sort of test did not end up being necessary. The game play is described using ray casts alone.So, given a collection of collision tiles, each containing a collision of line segments, and a map of those tiles laid out on a 2D grid, I was able to make a pretty expressive 2D collision system without a whole lot of effort. The next tricky bit, which I'll cover in a subsequent post, was what sort of tests, and what sort of response, are actually the best for game play. And this system only deals with intersections between entities and the background; in the future I'll write about the system I used to detect collisions between individual entities.
发表评论
-
Want to Change the Game Industry? Support the Xperia PLAY.
2011-12-07 21:05 0The problems with the console g ... -
Replica Island Updated
2011-12-07 21:04 0Yesterday I uploaded the first ... -
Hot Failure
2011-12-07 21:04 0An article I originally wrote f ... -
Building a Reflective Object System in C++
2011-12-07 21:03 0Every game engine I've worked w ... -
Leveraging Java and C++ for Hybrid Games
2011-12-07 21:02 0I've been thinking a lot lately ... -
Game Object Construction Rabbit Hole
2011-12-07 21:01 0Today I want to write a little ... -
Long Time, No See
2011-12-07 21:00 0I haven't written anything here ... -
Replica Island Passes a Million Installs
2011-12-07 20:59 0Holy crap!Replica Island passed ... -
Control Configuration and Abstraction
2011-12-07 20:58 0The #1 thing that I've learn ... -
Design Post-Mortem: Three Mistakes
2011-12-07 20:58 0While I'm pretty happy with Rep ... -
Replica Island: One Month On
2011-12-07 20:57 0As of today, Replica Island ... -
My New Favorite User Feedback
2011-12-07 20:56 0You can't write this stuff ... -
Replica Island User Comments Are Hilarious
2011-12-07 20:55 0Update: Blogger apparently isn' ... -
Design Post-Mortem: The Possession Orb
2011-12-07 20:55 0Rather than write a big lo ... -
Replica Island Released!
2011-12-07 20:54 0I released Replica Island almos ... -
Fragmentation? More like Fragmentawesome.
2011-12-07 20:53 0I'm lucky enough to have occasi ... -
The Elusive Perfect Platformer Camera
2011-12-07 20:52 0I've come to believe that platf ... -
Game Play Video
2011-12-07 20:51 0Here's some footage of an early ... -
Tuning With Metrics Redux
2011-12-07 20:50 0A while back I posted about the ... -
Some Screenshots
2011-12-07 20:49 0I've posted some screenshots of ...
相关推荐
### 概述 本文介绍了一种名为“级联部分解码器(Cascaded Partial Decoder,简称CPD)”的方法,旨在实现快速且准确的显著性目标检测。该方法通过摒弃浅层的大分辨率特征来加速计算过程,并利用深层特征生成的较为...
Accurate Pixel Collision Detection. This program demonstrates both Extent and Pixel collision detection. Very useful for games. Feedback Welcomed.
al [8] that uses a large number of input frames and multiple iterative minimization steps for obtaining very accurate calibration results. We propose several modifications to this estimation pipeline...
"ALIKE: Accurate and Lightweight Keypoint Detection and Descriptor Extraction" ALIKE 是一种高效的关键点检测和描述符提取算法,其特点是具有高准确性和轻量级网络架构。下面是对 ALIKE 的详细介绍: 关键点...
- **标题**:“Danqi Chen的A Fast and Accurate Dependency Parser using Neural Networks” - 该标题明确指出了论文的主题是介绍了一种基于神经网络的快速且准确的依存关系解析器。 #### 描述解读: - **描述**...
### 学习SURF级联实现快速准确的目标检测 #### 摘要 本文提出了一种新颖的学习框架,用于从大规模数据集中训练基于提升级联(boosting cascade)的对象检测器。该框架源自著名的Viola-Jones (VJ)框架,但通过三项...
rate lead to more accurate models and faster decoding. CD phone modeling leads to further improvements. We also present initial results for LSTM RNN models outputting words directly. Index Terms: ...
1、 训练数据准备 所有数据均放置于Sample\Build\下,其中Build为数据类型,根据自己需要进行修改,本示例数据为512*512大小GF2建筑,训练数据按照: Sample\Build\train\ IMG_T1 -----------------------\ IMG_LABEL...
FCHD 本工程是官方工程的python3版本,重构了部分代码,并训练得到了一个效果不错的模型。 论文地址: 官方工程地址: 安装 Clone ...安装依赖 cd FCHD pip install -r requirements.txt ...在下载Brainwash数据集,caffe...
Lidar based 3D object detection is inevitable for autonomous driving, because it directly links to environmental understanding and therefore builds the base for prediction and motion planning....
本文探讨了在资源有限的设备上进行条码检测与解码的问题,并提出了一种快速且稳健的方法,特别针对2D Data Matrix类型的条码扫描。该方法首先采用轮廓追踪技术来识别关键角点和段落,随后进行一到两步拟合过程。这种...
【资源说明】 1、该资源包括项目的全部源码,下载可以直接使用! 2、本项目适合作为计算机、数学、电子信息等专业的课程设计、期末大作业和毕设项目,作为参考资料学习借鉴。 3、本资源作为“参考资料”如果需要实现...
### 快速准确的流量矩阵测量技术 #### 摘要 本文提出了一种基于基数计数的流量矩阵(Traffic Matrix, TM)测量方法,并采用自适应计数算法来生成包级和流级别的流量矩阵。这种方法非常适合基于TM的网络异常检测。...
MTorres Accurate unwinding and splicing with Rockwell Automationpdf,MTorres Accurate unwinding and splicing with Rockwell Automation
文章全名: Deep Laplacian Pyramid Networks for Fast and Accurate Super-Resolution 2017 CVPR图像超分辨算法代码
In the second step, the adaptive quadratic sum-square error with unknown inputs (AQSSE-UI) is used for the on-line system identification and damage detection of the reduced order system. The proposed...