Skip to content

Instantly share code, notes, and snippets.

@Dynom
Created January 19, 2012 13:42
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dynom/1640107 to your computer and use it in GitHub Desktop.
Save Dynom/1640107 to your computer and use it in GitHub Desktop.
space: function() {
var rad = ((this.rotation-90) * Math.PI)/180,
dx = 10 * Math.cos(rad),
dy = 10 * Math.sin(rad);
var sprite = Ext.getCmp('theShip').surface.add({
type: 'path',
stroke: 'green',
path: 'M50 50 L40 80 L60 80 Z',
rotation: Ext.getCmp('theShip').surface.items.first().attr.rotation
});
var posX = this.posX,
posY = this.posY;
var intervalId = setInterval(function () {
posX += dx;
posY += dy;
sprite.setAttributes({
translate: {
x: posX,
y: posY
}
}, true);
if (posX > (Ext.getCmp('theShip').width + sprite.surface.width) ||
posY > (Ext.getCmp('theShip').height + sprite.surface.height) ||
posX < (0 - Ext.getCmp('theShip').width) ||
posY < (0 - Ext.getCmp('theShip').height)
) {
clearInterval(intervalId);
//console.log('Destroyed at: X: ', posX, ' - And Y: ', posY);
} else {
//console.log('Currently at: X: ', posX, ' - And Y: ', posY);
}
}, 10);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment