23,087
社区成员




制作温馨浪漫爱心表白动画特效HTML5+jQuery【附源码】
我的网站已经上线了 http://javapub.net.cn/
博主介绍: 🚀自媒体 JavaPub 独立维护人,全网粉丝15w+,csdn博客专家、java领域优质创作者,51ctoTOP10博主,知乎/掘金/华为云/阿里云/InfoQ等平台优质作者、专注于Java技术领域和副业。🚀
公众号:JavaPub ⭐ ⭐简历模板、学习资料、面试题库等都给你💪
🍅
文末获取源码
🍅 无套路,免费领取
点赞再看,养成习惯
适合人群:初级学习者和爱好者,下面有展示图。计算机毕业设计
🚀获取源码,文末公众号回复【制作温馨浪漫爱心表白动画特效】,即可。
⭐欢迎点赞留言
公众号:JavaPub
1MB GIF可以欣赏:
https://tvax1.sinaimg.cn/large/007F3CC8ly1h3dn7ib17ig30ug0lxe5x.gif
<!DOCTYPE html>
<html lang="en">
<head>
<title>Backbone Game Engine</title>
<meta name="description" content="Elementary HTML5 Canvas Game Engine based on Backbone. Specialized for 2D platformers, and optimized for mobile.">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="apple_touch_icon.png" rel="apple-touch-icon" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<script src="docs/jquery.min.js" type="text/javascript"></script>
<script src="docs/bootstrap.min.js" type="text/javascript"></script>
<link href="docs/bootstrap.min.css" rel="stylesheet" type="text/css" charset="utf-8">
<link href="docs/docs.css" rel="stylesheet" type="text/css" charset="utf-8">
</head>
<body data-spy="scroll" data-target="#sidebar" data-offset="100">
<header class="navbar navbar-inverse" role="banner">
<div class="navbar-header">
<button type="button" class="navbar-toggle pull-left" data-toggle="collapse" data-target="#navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="index.html" title="Elementary HTML5 Canvas Game Engine based on Backbone."><img src="apple_touch_icon.png" /> Backbone Game Engine</a>
</div>
<div id="navbar-collapse" class="collapse navbar-collapse" role="navigation">
<ul class="nav navbar-nav">
<li><a href="index.html">Documentation</a></li>
<li><a href="examples.html">Examples</a></li>
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="github-icon"><a href="https://github.com/martindrapeau/backbone-game-engine" title="Fork me on Github"><img src="docs/github.png" />Github</a></li>
</ul>
</div>
</header>
<div class="container">
<div class="row">
<div class="col-md-9">
<div id="introduction" class="row">
<div class="col-md-12">
<h1>HTML5 Canvas & Backbone</h1>
</div>
</div>
<div class="row">
<div class="col-md-6 col-xs-6">
<p>
An elementary HTML5 Canvas game engine built on Backbone. Specialized for 2D platformers, and optimized for mobile.
</p>
<h4>Examples</h4>
<ul>
<li>Real game: <a href="http://www.ludosquest.com" target="_blank">Ludo's Quest</a> - <a href="https://itunes.apple.com/ca/app/ludos-quest/id1047863228" target="_blank">launched on iOS</a> using <a href="https://www.cocoon.io" target="_blank">Cocoon.io</a></li>
<li>Test game: <a href="http://www.mariocraft.club" target="_blank">Mariocraft</a></li>
<li>Advanced: <a href="super-mario-bros/index.html" target="_blank">Super Mario Bros, level 1-1</a></li>
<li>Elementary: <a href="ball/index.html" target="_blank">Bouncing ball</a></li>
<li>Basic: <a href="mario/index.html" target="_blank">Mario in an empty world</a></li>
<li>Basic: <a href="gui/index.html" target="_blank">GUI</a></li>
<li>Basic: <a href="frog/index.html" target="_blank">Hoppy frog</a></li>
</ul>
<p>
These examples are on <a href="https://github.com/martindrapeau/backbone-game-engine">Github</a>.
</p>
</div>
<div class="col-md-3 col-xs-6">
<p>
<div class="carousel slide" data-ride="carousel">
<div class="carousel-inner">
<a class="item active" href="super-mario-bros/index.html" target="_blank">
<img src="docs/super-mario-bros-level-1-1.png" alt="" class="img-responsive" alt="Super Mario Bros level 1-1" title="Super Mario Bros level 1-1" />
<span class="carousel-caption">Click to play</span>
</a>
</div>
</div>
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h4>CocoonJS Example</h4>
<p>
Backbone Game Engine was written to run inside of CocoonJS Canvas+, so you can turn your HTML5 game into a native application on iOS or Android. If you have the CocoonJS launcher loaded on your iOS or Android device, you can load Super Mario Bros level 1-1 via this URL:
</p>
<pre>
http://martindrapeau.github.io/cocoon-mario/cocoon-mario.zip
</pre>
</div>
</div>
<div id="features" class="row">
<div class="col-md-12">
<h3>Features:</h3>
<ul>
<li><strong>Built on Backbone</strong>. Events, models, collections, inheritance and RESTful persistence. Why reinvent the wheel?</li>
<li><strong>HTML5 canvas only</strong>. No jQuery, as little DOM manipulations as possible.</li>
<li><strong>Mobile optimized</strong>. Build to run on mobile devices with transparent touch and viewport support. Everything is optimized for maxium frames per seconds (FPS).</li>
<li><strong>Go Native with CocoonJS.</strong>. Built to run in Ludei's <a href="http://support.ludei.com/hc/en-us/articles/200767118-Canvas-development-Guide" target="_blank">CocoonJS canvas+</a>. Deploy native on iOS and Android.</li>
<li><strong>2D platformer</strong>. Built with side-scrollers in mind. Built-in classes for sprites, sprite sheets, characters, hero, quad-tree collision detection, world and editor.</li>
<li><strong>No compilation</strong>. You don't need to install node, grunt or whatever else. Just code and press F5 to run.</li>
<li><strong>No server required</strong>. Fork this repo and your Github site is up and going. Create your own game and point your friends to it. Rebase to pull in latest engine updates.</li>
<li><strong>Built for mobile</strong>. Conceived to run on tablets. Share your URL with Mom so she can add it to the home screen of her iPad.</li>
<li><strong>Take if offline</strong>. With HTML5 Application Cache, your game runs offline. Perfect for taking it on the road or on a fishing trip.</li>
<li><strong>Save state</strong>. With HTML5 Local Storage, save where you are.</li>
<li><strong>World editor</strong>. Conceived for tile-based games, comes with a world editor. Place your tiles and characters, then hit play to try it out. Hit save to save your world.</li>
</ul>
</div>
</div>
<div id="dependencies" class="row">
<div class="col-md-12">
<h3>Dependencies</h3>
<ul>
<li><a href="http://underscorejs.org/" target="_blank">Underscore</a> </li>
<li><a href="http://backbonejs.org/" target="_blank">Backbone</a> </li>
<li><a href="https://github.com/inkling/backbone.native/" target="_blank">backbone.native</a>. To drop jQuery.</li>
<li><a href="https://github.com/asaarinen/qtree/" target="_blank">simple-quadtree</a></li>
</ul>
<p>
All included in the <code>3rd</code> folder. That and nothing else.
</p>
<h3>Why Backbone?</h3>
<p>
Backbone implements <a href="http://backbonejs.org/#Events" target="_blank">events</a>, <a href="http://backbonejs.org/#Model" target="_blank">models</a>, <a href="http://backbonejs.org/#Collection" target="_blank">collections</a>, <a href="http://backbonejs.org/#Model-extend" target="_blank">inheritance</a> and <a href="http://backbonejs.org/#Sync" target="_blank">persistence</a>. Models implement getters and setters for object attributes. Models and Collections have an <code>extend</code> function to easily do inheritance. They implement methods for persistence (RESTful JSON by default). They can also trigger events and bind to them. Everything you need to build a great extensible game engine. Plus, Backbone is now widely used and provides these features in a standard fashion with a huge community to support them. I hope this project can make game programming accessible to developers already familiar with Backbone.
</p>
<h3>Using and Contributing</h3>
<p>
Backbone Game Engine was built to get you going fast. <a href="https://github.com/martindrapeau/backbone-game-engine">Fork this repository</a>, and your own Github page will be ready in minutes. You can then create your own games by simply creating a new directory, and putting files in it.
</p>
<p>
The default branch is <code>gh-pages</code> so that any changes get published automatically to the Github page. Changes typically take only a few seconds to get published. This allows you to develop, test, document and deploy rapidly. It is a double-edge sword though. Any untested code you push to your fork on that branch will be felt by your users. It is therefore a good practice to create and work on another branch, and fast-forward merge to the <code>gh-pages</code> branch when done.
</p>
<p>
To report a bug, use <a href="https://github.com/martindrapeau/backbone-game-engine/issues" target="_blank">Github issues</a>. To contribute improvements, bug fixes or new examples, make changes to your fork and do a pull request. For anyone looking to help, here is a short to-do list:
</p>
<ul>
<li>Implement vertical panning in Backbone.Camera.</li>
<li>Revamp collision detection: optimize lookup and better functions.</li>
<li>Implement sound.</li>
<li>Add missing behaviors in Super Mario: character death, break brick, etc.</li>
</ul>
<br/>
</div>
</div>
<!-- Documentation -->
<div id="getting-started" class="row">
<div class="col-md-12">
<h1>Getting Started</h1>
</div>
</div>
<div id="documentation-Backbone" class="row">
<div class="col-md-12">
<h3>Backbone</h3>
<p>
The engine is based on Backbone so it is essential to understand its core structure: a <a href="http://backbonejs.org/#Model" target="_blank">Backbone.Model</a>. A model has hash of <code>attributes</code> that are changed via getter and setter methods <code>get</code> and <code>set</code>. These attributes should only contain state information as it is those attributes which get saved and restored. A model is a Javascript object. Hence behaviour can be stored as properties and methods directly on the object. For example a sprite sheet points to an image. Attribute <code>img</code> contains the <code>Image</code> object or DOM selector (by id) for retrieving the Image object. Property <code>img</code> contains reference to the Image object. It is automatically set when the sprite sheet model is initialized.
<pre>
var spriteSheet = new Backbone.SpriteSheet({
id: "mario",
img: "#mario",
tileWidth: 32,
tileHeight: 64,
tileColumns: 21,
tileRows: 6
});
spriteSheet.get("img"); // attribute
// #mario
spriteSheet.img; // property
// <img id="mario" src="../super-mario-bros/super-mario-2x.png" style="display:none;">
spriteSheet.img.width
//672
spriteSheet.img.height
//384
</pre>
</p>
<p>
In fact, a model stores its attributes in the object property <code>attributes</code>. Methods <code>get</code>, <code>set</code> and <code>toJSON</code> operate on that property. Just remember that state date like sprite coordinates, velocity, etc go in there. However references to other objects do not.
</p>
<div class="alert alert-info">
Note on nomenclature: The word <strong>attribute</strong> is used to define state data (get and set stored in obejct property attributes) while the word <strong>property</strong> is used to define behavioural data stored directly on the object.
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3 id="documentation-no-jQuery">Living without jQuery</h3>
<p>
Backbone Game Engine does not use jQuery. Instead, it depends on <a href="https://github.com/inkling/backbone.native/" target="_blank">backbone.native</a> which re-creates the ubiquitous <code>$</code> function/object with only essentials required by Backbone. As such, you are limited to simple DOM selectors enabled by <a href="https://developer.mozilla.org/en/docs/Web/API/Document.querySelectorAll" target="_blank">querySelectorAll</a> and events. Since the framework is for canvas-based games, avoid HTML manipulations. Canvas-based only allows for easier wrapping with CocoonJS. Consult the documentation of backbone.native to understand limitations.
</p>
</div>
</div>
<div class="row">
<div class="col-md-12">
<h3 id="documentation-Structure">Directory structure</h3>
<p>
To create a new example (or game), create an empty directory at the same level as <code>super-mario-bros</code>. Then, add some files. Here is the recommended file structure:
</p>
<pre>
3rd/
src/
...
super-mario-bros/
my-game/
index.html
main.js
</pre>
<p>
<code>index.html</code> is the HTML document which loads your assets, and defines your canvas. File <code>main.js</code> is where you instantiate the game engine and sprites. It must get loaded last.
</p>
<h3 id="documentation-HTML">index.html</h3>
<p>
The HTML document (usually named <code>index.html</code> in its own folder) declares the assets to be loaded and the <code>canvas</code> element. Javascript assets are declared in the <code>HEAD</code> element. Images are loaded via <code>IMG</code> elements. They must be hidden with inline CSS. Everything is bootstrap-loaded as declared in the HTML file. There is no asynchronous loading.
</p>
<p>
Here is an example HTML file taken from the example <a href="mario/index.html" target="_blank">Mario</a>.
</p>
<pre>
<!doctype html>
<html style="touch-action: none;">
<head>
<title>Mario - Backbone Game Engine</title>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../favicon.ico" rel="shortcut icon" type="image/x-icon" />
<link href="../apple_touch_icon.png" rel="apple-touch-icon" />
<meta name="viewport" content="width=960, user-scalable=no"/>
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
<script src="../3rd/underscore.js" type="text/javascript"></script>
<script src="../3rd/backbone.native.js" type="text/javascript"></script>
<script src="../3rd/backbone.js" type="text/javascript"></script>
<script src="../src/shapes.js" type="text/javascript"></script>
<script src="../src/core.js" type="text/javascript"></script>
<script src="../src/input.js" type="text/javascript"></script>
<script src="../src/hero.js" type="text/javascript"></script>
<script src="../src/world.js" type="text/javascript"></script>
<script src="main.js" type="text/javascript"></script>
<style>
body {
margin: 0;
background-color: #000;
}
canvas {
position: fixed;
top: 0;
left: 0;
}
</style>
</head>
<body>
<img id="mario" src="../super-mario-bros/super-mario-2x.png" style="display:none;" />
<canvas id="foreground" width="960" height="700">
Your browser does not support canvas element.
</canvas>
</body>
</html>
</pre>
<p>
Some important notes:
</p>
<ul>
<li>HTML meta tags <code>viewport</code>, <code>apple-mobile-web-app-capable</code>, <code>mobile-web-app-capable</code> and <code>apple-mobile-web-app-status-bar-style</code> ensure the canvas is properly sized and styled on iPads and other mobile devices. The width specified there should be the same as the canvas elements. On <a href="#mobile-devices">mobile devices</a>, an orientation change will recalculate and change the width to fit the canvas in the viewport. </li>
<li>Style <code>touch-action: none;</code> on the <code>HTML</code> tag disables touch behaviors, like pan and zoom for IE10.</li>
<li>Elements must all have ids since we use the native <code>getElementById</code> Javascript function to retrieve the <code>Canvas</code> and <code>Image</code> objects from their respective DOM elements.</li>
</ul>
<h3 id="documentation-main">main.js</h3>
<p>
File <code>main.js</code> is where you declare and initialize your objects. It is recommended that you wrap that code in a function which gets executed once the document and all assets are loaded (i.e. window.onload event). You can use for example <code>$(window).on("load", function() {});</code>.
</p>
<li><a href="#documentation">Reference</a></li>
<li><a href="#documentation-Engine"> Backbone.Engine</a></li>
<li><a href="#documentation-SpriteSheet"> Backbone.SpriteSheet</a></li>
<li><a href="#documentation-SpriteSheetCollection"> Backbone.SpriteSheetCollection</a></li>
<li><a href="#documentation-Sprite"> Backbone.Sprite</a></li>
<li><a href="#documentation-Input"> Backbone.Input</a></li>
<li><a href="#documentation-World"> Backbone.World</a></li>
<li><a href="#documentation-WorldEditor"> Backbone.WorldEditor</a></li>
<li><a href="#documentation-Character"> Backbone.Character</a></li>
<li><a href="#documentation-Hero"> Backbone.Hero</a></li>
<li><a href="#documentation-Camera"> Backbone.Camera</a></li>
<li><a href="#documentation-Clock"> Backbone.Clock</a></li>
<li><a href="#documentation-Element"> Backbone.Element</a></li>
<li><a href="#documentation-Button"> Backbone.Button</a></li>
<li><a href="#documentation-DebugPanel"> Backbone.DebugPanel</a></li>
<li><a href="#documentation-Shapes"> Shape functions</a></li>
<li><a href="#mobile-devices">Mobile Devices</a></li>
<li><a href="#going-offline">Going Offline</a></li>
<li><a href="#persistence">Persistence</a></li>
<li><a href="#performance">Performance</a></li>
<li><a href="#publishing">Publishing</a></li>
<li><a href="#change-log">Change Log</a></li>
</ul>
</div>
</div>
</div>
</div>
<br/>
<footer class="navbar navbar-default">
<p class="navbar-text navbar-left">
© 2014 <a href="http://martindrapeau.tumblr.com/">Martin Drapeau.</a>
<a href="https://github.com/martindrapeau/backbone-game-engine/blob/gh-pages/LICENSE">Licensed under MIT.</a>
</p>
<p class="navbar-text navbar-right">Written in Montréal, Canada.</p>
<p class="navbar-text navbar-right"> </p>
</footer>
</body>
</html>
获取源码,公众号回复【制作温馨浪漫爱心表白动画特效】,即可。更多最新Java面试题加群、见群公告。~
不会还有人没 点赞 + 关注 + 收藏 吧!
项目源码获取方法
点赞本文,然后私信我,我免费分享给你哈~
源码获取:
大家
点赞、收藏、关注、评论
啦 、查看👇🏻👇🏻👇🏻微信
公众号获取联系方式👇🏻👇🏻👇🏻
精彩专栏推荐订阅:在下方专栏👇🏻👇🏻👇🏻👇🏻