Enchant.js sample
How do I make an enchant.js sample?
Thankshttp://enchantjs.com/ http://dotinstall.com/lessons/basic_enchant_js_v2/11511 http://tmlife.net/programming/javascript/javascript-lib-stats-js-memo.html. What is a enchant.js sample? How do you make a enchant.js sample? This script and codes were developed by Uriuriuriu on 10 January 2023, Tuesday.
Enchant.js sample - Script Codes HTML Codes
<!DOCTYPE html>
<html >
<head> <meta charset="UTF-8"> <title>enchant.js sample</title> <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/meyer-reset/2.0/reset.min.css"> <link rel="stylesheet" href="css/style.css">
</head>
<body> <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5/dat.gui.min.js"></script>
<script type="text/javascript" src="https://dl.dropboxusercontent.com/u/90712768/js/libs/Stats.js"></script> <script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>
<script src='https://dl.dropboxusercontent.com/u/90712768/js/libs/enchant.js'></script> <script src="js/index.js"></script>
</body>
</html>
Enchant.js sample - Script Codes CSS Codes
body { margin: 0; padding: 0;
}
Enchant.js sample - Script Codes JS Codes
/* thanks http://enchantjs.com/ http://dotinstall.com/lessons/basic_enchant_js_v2/11511 http://tmlife.net/programming/javascript/javascript-lib-stats-js-memo.html
*/
enchant();
window.onload = function(){ var stats = enableStats(); var GAME_W = window.innerWidth; var GAME_H = window.innerHeight; var charaSrc = "https://dl.dropboxusercontent.com/u/90712768/img/chara1.png"; // dat.gui setting var Setting = function(){ this.chara_num = 200; this.chara_num_max = 3000; this.buttleMode = false; } var setting = new Setting(); var core = new Core(GAME_W, GAME_H); core.fps = 30; core.scale = 1; core.preload(charaSrc); core.onload = function(){ // Bear class var Bear = Class.create(Sprite,{ initialize:function(x,y){ Sprite.call(this, 32, 32); this.image = core.assets[charaSrc]; this.x = x; this.y = y; this.charaSet = rand(3) *5; var v = Math.random() * 8 + 1; this.on("enterframe", function(){ this.frame = this.age % 3 + this.charaSet; if(this.flgButtle){ this.x += Math.random() * 16 + 1; }else{ this.x += v; } this.y += (Math.cos(this.age/3 + v)*2); if(GAME_W < this.x)this.x = -10; }) core.rootScene.addChild(this); },remove:function(){ core.rootScene.removeChild(this); },changeButtleMode:function(flg){ this.flgButtle = flg; },charaSet:0 ,flgButtle:setting.buttleMode }) // create bears var bears = []; for (var i = 0; i < setting.chara_num; i++) { bears.push(new Bear(rand(GAME_W), rand(GAME_H))); }; // enterframe event core.addEventListener('enterframe', function(){ // fps chaek stats.update(); }); // dat.gui var gui = new dat.GUI(); gui.add(setting, 'chara_num', 0, setting.chara_num_max).onFinishChange(function(value){ var nowNum = bears.length; var resultNum = Math.floor(value); if(nowNum < resultNum){ var addNum = resultNum - nowNum; for (var i = 0; i < addNum; i++) { bears.push(new Bear(rand(GAME_W), rand(GAME_H))); }; }else if(resultNum < nowNum){ var removeNum = nowNum - resultNum; for (var i = 0; i < removeNum; i++) { var removeBear = bears.pop(); removeBear.remove(); removeBear = null; }; } }); gui.add(setting, 'buttleMode').onFinishChange(function(value){ for (var i = 0; i < bears.length; i++) { bears[i].changeButtleMode(value); }; }); } core.start(); // event window.addEventListener('resize', onWindowResize, false); function onWindowResize(){ GAME_W = window.innerWidth; GAME_H = window.innerHeight; core.width = GAME_W; core.height = GAME_H; }
}
// mixin
function rand (n) { return Math.floor(Math.random() * (n+1));
}
// Stats.js
var enableStats = function() { if (window.Stats === undefined) return null; var stats = new Stats(); // 左上に設定 stats.domElement.style.position = "fixed"; stats.domElement.style.left = "15px"; stats.domElement.style.top = "0px"; document.body.appendChild(stats.domElement); return stats;
};
Developer | Uriuriuriu |
Username | uriuriuriu |
Uploaded | January 10, 2023 |
Rating | 3.5 |
Size | 3,131 Kb |
Views | 4,048 |
Find the perfect freelance services for your business! Fiverr's mission is to change how the world works together. Fiverr connects businesses with freelancers offering digital services in 500+ categories. Find Developer!
Name | Size |
Three.js ver.1 rotate camera | 2,769 Kb |
Glitch Video | 3,178 Kb |
Masonry | 5,005 Kb |
AngularJS - first step - | 3,009 Kb |
ClickPanel | 3,068 Kb |
Glitch test | 4,246 Kb |
Three.js earth | 3,423 Kb |
Css action sideBar | 3,928 Kb |
Now | 4,505 Kb |
SANGETUKI separator | 11,128 Kb |
Jasper is the AI Content Generator that helps you and your team break through creative blocks to create amazing, original content 10X faster. Discover all the ways the Jasper AI Content Platform can help streamline your creative workflows. Start For Free!
Name | Username | Size |
Heartbeat | Apetrov | 2,079 Kb |
Prism | Pyrografix | 2,843 Kb |
Donald Trump - The New Yorker | Agbales | 2,502 Kb |
Flexbox slider | Rendro | 3,459 Kb |
Wikipedia viewer | Chpecson | 2,865 Kb |
Improved Page Flipping Effect | Usaphp | 5,201 Kb |
Flexbox Test | Icutpeople | 2,486 Kb |
Resize image | Happyhj | 1,892 Kb |
SVG Icons Template | Legofsalmon | 2,618 Kb |
Pomodoro Clock | Yas46 | 3,328 Kb |
Surf anonymously, prevent hackers from acquiring your IP address, send anonymous email, and encrypt your Internet connection. High speed, ultra secure, and easy to use. Instant setup. Hide Your IP Now!