Toggle navigation
Sign Up
Log In
Explore
Works
Folders
Tools
Collections
Artists
Groups
Groups
Topics
Tasks
Tasks
Jobs
Teams
Jobs
Recommendation
More Effects...
JS
$(window).load(function () { init(); }); function init() { createJSInit(); } var canvas; var stage; var texture; var textureData; var skeletonData; function createJSInit() { canvas = document.getElementById("canvas"); stage = new createjs.Stage(canvas); texture = new Image(); texture.onload = function() { $.getJSON( "http://www.effecthub.com/uploads/codefile/7F39CDDA-53DB-D998-F1E6-8BECCB8523CC/texture.json", function(data) { textureData = data; $.getJSON( "http://www.effecthub.com/uploads/codefile/6BF02133-3705-824C-FC86-895168570B83/skeleton.json", function(data) { skeletonData = data; dragonBonesInit(); } ) } ); } texture.src = "http://www.effecthub.com/uploads/codefile/71E3CBF9-FD82-783F-794E-AB02DA40E6BB/texture.png"; } var factory; var armature; function dragonBonesInit() { factory = new dragonBones.factorys.CreateJSFactory(); factory.addSkeletonData(dragonBones.objects.DataParser.parseSkeletonData(skeletonData)); factory.addTextureAtlas(new dragonBones.textures.CreateJSTextureAtlas(texture, textureData)); armature = factory.buildArmature("dragonBoy"); armature.getDisplay().x = 400; armature.getDisplay().y = 400; armature.getDisplay().scaleX = armature.getDisplay().scaleY = 0.5; updateAnimation(); dragonBones.animation.WorldClock.clock.add(armature); stage.addChild(armature.getDisplay()); createjs.Ticker.setFPS(60); createjs.Ticker.addEventListener("tick", update); document.onkeydown = keyHandler; document.onkeyup = keyHandler; canvas.onmousewheel = mouseWheelHandler; canvas.onclick = mouseClickHandler; } function update() { updateSpeed(); dragonBones.animation.WorldClock.clock.advanceTime(1/60); stage.update(); } var _currentClothesID = 0; function mouseClickHandler(e) { _currentClothesID ++; if(_currentClothesID > 4) { _currentClothesID = 0; } if(_currentClothesID) { armature.getSlot("clothes").setDisplay(factory.getTextureDisplay("parts/clothes" + _currentClothesID)); } else { armature.getSlot("clothes").setDisplay(null); } } function mouseWheelHandler(e) { e = e || window.event; var delta = Math.max(-1, Math.min(1, (e.wheelDelta || -e.detail))); if (delta < 0) { if (armature.animation.timeScale > 0.2) { armature.animation.timeScale -= 0.1; } } else { if (armature.animation.timeScale < 4) { armature.animation.timeScale += 0.1; } } } var _left; var _right; function keyHandler(e) { e = e || window.event; var currKey = e.keyCode || e.which || e.charCode; var isDown = e.type == "keydown"; switch (currKey) { case 37 : case 65 : _left = isDown; updateMove(-1); break; case 39 : case 68 : _right = isDown; updateMove(1); break; case 38 : case 87 : if (isDown) { jump(); } break; case 83 : case 40 : squat(isDown); break; } } function updateMove(dir) { if (_left && _right) { move(dir); } else if (_left) { move(-1); } else if (_right) { move(1); } else { move(0); } } var _speedX = 0; var _speedY = 0; var _moveDir = 0; var _face = 0; var _isJumping; var _isSquat; function move(dir) { if (_moveDir == dir) { return; } _moveDir = dir; updateAnimation(); } function jump() { if (_isJumping) { return; } _speedY = -24; _isJumping = true; armature.animation.gotoAndPlay("jump", 0.1); } function squat(isSquat) { if (_isSquat == isSquat) { return; } _isSquat = isSquat; updateAnimation(); } function updateAnimation() { if (_isJumping) { return; } if (_isSquat) { _speedX = 0; armature.animation.gotoAndPlay("squat"); return; } if (_moveDir == 0) { _speedX = 0; armature.animation.gotoAndPlay("stand"); } else { _speedX = _moveDir * 6; armature.animation.gotoAndPlay("walk", 0.2); armature.getDisplay().scaleX = -_moveDir * 0.5; } } function updateSpeed() { if (_isJumping) { var speed = 1 * armature.animation.timeScale; if(_speedY <= 0 && _speedY + speed > 0) { armature.animation.gotoAndPlay("fall", 0.2); } _speedY += speed; } if (_speedX != 0) { armature.getDisplay().x += _speedX * armature.animation.timeScale; if (armature.getDisplay().x < 0) { armature.getDisplay().x = 0; } else if (armature.getDisplay().x > 800) { armature.getDisplay().x = 800; } } if (_speedY != 0) { armature.getDisplay().y += _speedY * armature.animation.timeScale; if (armature.getDisplay().y > 400) { armature.getDisplay().y = 400; _isJumping = false; _speedY = 0; _speedX = 0; armature.addEventListener(dragonBones.events.AnimationEvent.FADE_OUT_COMPLETE, animationFadeOutCompleteHandler); armature.animation.gotoAndPlay("fallEnd"); } } } function animationFadeOutCompleteHandler(e) { switch(e.animationState.name) { case "fallEnd": armature.removeEventListener(dragonBones.events.AnimationEvent.FADE_OUT_COMPLETE, animationFadeOutCompleteHandler); updateAnimation(); break; } }
CSS
body{ background:#F0F0ED; }
HTML
Join Effecthub.com
Working with Global Gaming Artists and Developers!
Login
Sign Up
Or Login with Your Email Address:
Email
Password
Remember
Or Sign Up with Your Email Address:
Your Email
This field must contain a valid email
Set Password
Password should be at least 1 character
Stay informed via email