Comments (3)
var player = {
x: 200,
y: 100,
width: 32,
height: 32
};
var enemy = {
x: 10,
y: 10,
width: 32,
height: 32
};
/* create fullscreen canvas */
cq().framework({
onResize: function(width, height) {
/* resize canvas with window */
this.canvas.width = 700;
this.canvas.height = 600;
},
/* in canvasquery you just need to type in keynames!!!! */
/* enemy moves with player(must fix) */
onKeyDown: function(key) {
if(key == "left" ) player.x -= 10;
if(key == "right") player.x += 10;
if(key == "up") player.y -= 10;
if(key == "down") player.y += 10;},
/* testing out moving seperate objects */
/* enmey keeps moving far left when moue enters screen... */
onMouseMove: function(x, y) {
enemy.x = x;
enemy.y = y;
},
onStep: function(delta) {},
onRender: function() {
/* draw player */
this.save()
.clear("cyan")
/* when this is translate is removed the enemy block is centeterd corectly on mouse cursor */
.translate(player.x, player.y)
.fillStyle("white")
.fillRect( -player.width / 2, -player.height / 2, player.width, player.height)
.fill()
.fillStyle("red")
.translate(enemy.x, enemy.y)
.fillRect( -enemy.width / 2, -enemy.height / 2, enemy.width, enemy.height)
.fill()
.restore();
}
}).appendTo("body");
Check out this Pen!
<script async src="http://codepen.io/assets/embed/ei.js"></script>from canvasquery.
Add another restore() and save() right after the player is drawn
save()
drawPlayer()
restore()
save()
drawEnemy
restore()
from canvasquery.
Thanks for the quick response! Wow the solution was so simple that it just flew right over my head >_<
from canvasquery.
Related Issues (20)
- Are colors broken right now? HOT 2
- Demos or tutorials? HOT 1
- Version 0.9.1 HOT 1
- drawSprite missing HOT 1
- text size HOT 1
- Logitech Universal Reciever is incorrectly recognised as a gamepad HOT 1
- Old browsers compatibility requestAnimationFrame HOT 2
- preventContextMenu not working HOT 1
- Sprites in Playground HOT 15
- Align HOT 8
- drawAtlasFrame() does not use x,y HOT 1
- Touchend is unreliable in multitouch HOT 4
- Integrating Playground with THREE.js
- Plugins in Playground HOT 1
- Mouselock Movement-Delta unprecise and IExplorer incompatible
- npm and browserify support HOT 14
- playground.Keyboard.prototype.keypress Event is an empty Function. HOT 7
- swapping color palettes
- cq.loadImages can not to use!
- Flip Sprite HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from canvasquery.