Raphael path.animate recursive function syntax - javascript

Does anyone know the syntax to call a function recursively to chain path.animate events using the Raphael library?
I have posted a JS Fiddle for reference at http://jsfiddle.net/Quarkist/c4TzV/
The function animString() (result on left) chains events properly and is animated.
The recursive function animRecursion() (result on right) does not animate.
Any insight is appreciated. Thank you!
<!doctype html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title>Recursive animatePath w/Raphael</title>
<style type="text/css">
<!--
#displayA { position: absolute; top: 0px; left: 0px; }
#displayB { position: absolute; top: 0px; left: 112px; }
// -->
</style>
<script type="text/javascript" src="raphael-min.js"></script>
<script type="text/javascript">
// Paths to animate
var path1 = "M200,50c-27.5,0,50,78,50,50 c0-27.5-77.5,50-50,50c28,0-50-77.5-50-50C150,127.5,228,50,200,50z";
var path2 = "M200,150c-27.5,0-50-22.5-50-50 s22.5-50,50-50s50,22.5,50,50S227.5,150,200,150z";
var path3 = "M200,171 130,100 200,30 271,100 200,171z";
var path4 = "M250,150 150,150 150,50 250,50 250,150z";
var path5 = "M200,50 200,83.5 200,116.5 200,150";
// animString works by stringing code along
function animString()
{ var tempCanvas = Raphael(document.getElementById('displayA'), 0, 0, 320, 240);
var path = tempCanvas.path( path1 );
var speed = 1000;
path.animate(
{ path: path1 }, 1000, // twist
function(){ path.animate( { path: path1 }, speed, 2000,
function(){ path.animate( { path: path2 }, speed, 2000,
function(){ path.animate( { path: path3}, speed, 2000,
function(){ path.animate( { path: path4}, speed, 2000,
function(){ path.animate( { path: path5}, speed, 2000
) } ) } ) } ) } ) } );
}
// animRecursion fails
function animRecursion(pathArray, speedArray, initialization)
{ var newPath=pathArray.shift(pathArray);
var newSpeed=speedArray.shift(speedArray);
if ( !initialization )
{ initialization=1;
var tempCanvas = Raphael(document.getElementById('displayB'), 0, 0, 320, 240);
var path = tempCanvas.path( newPath );
path.animate({path:newPath},newSpeed,animRecursion(pathArray, speedArray, initialization));
} else
{ if ( pathArray.length !=1 )
{ path.animate({path:newPath},newSpeed,animRecursion(pathArray, speedArray, initialization));
} else
{ if ( pathArray.length ==1 )
{ path.animate({path:newPath},newSpeed);
}
}
}
}
var sendArray = new Array();
var sendSpeed = new Array();
sendArray = [path1, path2, path3, path4, path5];
sendSpeed= [100,200,300,400,500];
</script>
</head>
<body onLoad="animString(); animRecursion(sendArray,sendSpeed);">
<div id="displayA"></div>
<div id="displayB"></div>
</body>
</html>

Notice that the working code does this:
path.animate(x,y,z,function(){path.animate()});
instead of this:
path.animate(x,y,z,path.animate());
But the failing code does this:
path.animate(x,y,z,animRecursion());
What you should have done is to do it the way the working code does it:
path.animate(x,y,z,function(){animRecursion()});
That is, pass a function to be called, not call a function.

Related

In three.js does not work material selection through span

At first, span worked for me, then I set up materialsLib and initMaterialSelectionMenus from documentation and examples, but now or the span does not work, then the model does not appear.
Help, please!
UPD
The problem was in the functions. Apparently they were looped or something like that.
Some of code
main.html:
<canvas id="c" width="100" height="100" allowtransparency frameborder="no" scrolling="yes"</canvas>
<div id="menu">
<div></div>
<span>Kar color: <select id="kar-mat"></select></span><br/><br/>
<span>Prof color: <select id="pro-mat"></select></span>
</div>
<style>
#c {width: 100px; height: 100px; display: block;}
#menu {position: absolute; left: 1em; top: 1em; padding: 1em; background: rgba(0, 0, 0, 0.8); color: white; font-family: monospace;}
</style>
<script type="module" src="./main.js"></script>
main.js:
var karMatSelect = document.getElementById( 'kar-mat' );
var proMatSelect = document.getElementById( 'pro-mat' );
var objParts = {
karkass: [],
proff: [],
};
...
function loadModel() {
var LOADER = new GLTFLoader();
LOADER.crossOrigin = true;
LOADER.load('1.glb',
(gltf) => {
console.log('loading complete')
const objbox = gltf.scene;
SCENE.add(objbox);
console.log(objbox);
objParts.karkass.push(objbox.getObjectByName('karkasidver')); //all objects are [Mesh]es
objParts.proff.push(objbox.getObjectByName( 'profl' ),);
...
function initMaterials() {
materialsLib = {
karkaslib: [
new THREE.MeshStandardMaterial( {
color: 0x154889, metalness: 1, roughness: 0.2, name: '5005'
} ),
.....
proflib: [
......
} ),
],
};
}
function initMaterialSelectionMenus() {
function addOption(name, menu) {
var option = document.createElement( 'option' );
option.text = name;
option.value = name;
menu.add(option);
}
materialsLib.karkaslib.forEach( function ( material ) {
addOption(material.name, karMatSelect);
} );
materialsLib.proflib.forEach( function ( material ) {
addOption(material.name, proMatSelect);
} );
karMatSelect.selectedIndex = 2;
proMatSelect.selectedIndex = 5;
karMatSelect.addEventListener( 'change', updateMaterials );
proMatSelect.addEventListener( 'change', updateMaterials );
}
function updateMaterials() {
initMaterials()
var karkasMat = materialsLib.karkaslib[karMatSelect.selectedIndex];
var proflMat = materialsLib.karkaslib[proMatSelect.selectedIndex];
objParts.karkass.forEach(part => part.material = karkasMat);
objParts.proff.forEach(part => part.material = proflMat);
}
When I started the project, I had errors in the console. I made a few changes to fix it:
In loadModel I have add rows with initMaterials(); and initMaterialSelectionMenus();
objParts.karkass.push(objbox.getObjectByName('karkasidver'));
objParts.proff.push(objbox.getObjectByName('profl'));
console.log(dumpObject(objbox).join('\n')); //-список объектов в сцене
/* Add function call for initialization*/
initMaterials();
updateMaterials();
/* Add function call for UI initialization*/
initMaterialSelectionMenus();
I have add checks for undefined for karkasMat and proflMat in the function updateMaterials. Also I have removed call initMaterials().
function updateMaterials() {
/* Remove call for initMaterials() */
var karkasMat = materialsLib.karkaslib[karMatSelect.selectedIndex];
var proflMat = materialsLib.karkaslib[proMatSelect.selectedIndex];
/* added check for empty element */
if (karkasMat) {
objParts.karkass.forEach(part => part.material = karkasMat);
}
/* added check for empty element */
if (proflMat) {
objParts.proff.forEach(part => part.material = proflMat);
}
}
3.
function updateCamera() {
CAMERA.updateProjectionMatrix();
/* Remove next rows, because animation function already started, and will update controls and render scene*/
// CONTROLS.update();
// RENDERER.render(SCENE, CAMERA);
// animate()
}
Result
Alex has an error:
in function updateMaterials()
var proflMat = materialsLib.karkaslib[proMatSelect.selectedIndex];
instead of
var proflMat = materialsLib.proflib[proMatSelect.selectedIndex];

Admob Phonegap build Stuck

Ok I have an application on the market for testing purposes and Im trying to implement admob ads I have my account for banner ads and everything the only thing is that I dont know how to set it up I need help please this is the sample application. Thank you
Mostly what i need i need to show banner ads on my title screen game screen and game over screen Ive tried several tutorials none seem to get me anywhere so thats why i decided maybe here one of you can help Me with this.
This is the html file----------------------------------------------------
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8-8">
<meta name="viewport" content="user-scalable=0, initial-scale=1,minimum-scale=1, maximum-scale=1, width=device-width, minimal-ui=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<script type="text/javascript" src="js/phaser.js"></script>
<script src="js/stateTitle.js"></script>
<script src="js/characters.js"></script>
<style>
body {
padding: 0px;
margin: 0px;
background: black;
c
}
</style>
</head>
<body>
<script src="js/stateOver.js"></script>
<script src="js/main.js"></script>
</body>
</body>
</html>
----------------------------------------------------------------------------_
Main.js
var score =0;
var highscore =0;
var highScoreText;
var scoreText;
var MainState = {
//load the game assets before the game starts
preload: function () { /////////////////////////////preload
this.load.image('background', 'assets/city.png');
this.load.image('bird', 'assets/bird.png');
game.load.image('pipe', 'assets/pipe.png');
},
//executed after everything is loaded
create: function () {
this.background = this.game.add.sprite(0, 0, 'background');
highScoreText = this.game.add.text(600, 40, 'HS: ' + highscore, {
font: '25px Arial',
fill: 'black'
});
/////Bird///////////////////////////////////////////////////
this.bird = this.game.add.sprite(100, 200, 'bird');
game.physics.startSystem(Phaser.Physics.ARCADE);
game.physics.arcade.enable(this.bird);
this.bird.body.gravity.y = 1000;
var spaceKey = game.input.keyboard.addKey(
Phaser.Keyboard.SPACEBAR);
game.input.onDown.add(this.jump, this); //////touch screen jump
spaceKey.onDown.add(this.jump, this);
this.bird.body.collideWorldBounds=true;
this.bird.body.immovable= true;
///////////////////////////////////////////////////////Pipes
this.pipes = game.add.group();
//timer
this.timer = game.time.events.loop(1400, this.addRowOfPipes, this); /////////////timer for pipes
///////////////////////////////////////////////////////Score
this.score = -1;
this.labelScore = game.add.text(20, 20, "0",
{ font: "30px Arial", fill: "black" });
},
// this is execated multiple times per second
update: function () { //////////////////////////////////////////////////update
if (this.bird.y < 0 || this.bird.y > 480)
game.state.start("StateOver");
///Collision
game.physics.arcade.overlap(
this.bird, this.pipes, this.restartGame, null, this);
////////////////////////////////////////////////////////////////////////// Highscore counter
highScoreText.text = 'HS: ' + this.currentHighScore;
{
if (this.score > this.currentHighScore)
{
this.currentHighScore = this.score;
}
}
},
jump: function () {
//this is for so the bird wount fly once dead
if (this.bird.alive == false)
return;
///sound
///this.jumpSound.play();
// Add a vertical velocity to the bird
this.bird.body.velocity.y = -350;
// Jump Animation
var animation = game.add.tween(this.bird);
// Change the angle of the bird to -20° in 100 milliseconds
animation.to({angle: -20}, 100);
// And start the animation
animation.start();
game.add.tween(this.bird).to({angle: -20}, 100).start();
},
restartGame: function () {
// Start the 'main' state, which restarts the game
game.state.start(game.state.current);
///Hit pipe Null
game.physics.arcade.overlap(
this.bird, this.pipes, this.hitPipe, null, this);
},
addRowOfPipes: function() {
var hole = Math.floor(Math.random() * 5) + 1; ///Math.floor(Math.random() * 5) + 1;
for (var i = 0; i < 10 ; i++) ///// (var i = 0; i < 8; i++)
if (i != hole && i != hole + 1) ///// if (i != hole && i != hole + 1)
this.addOnePipe(440, i * 50 ); ///// 640 starting point of pipe 240 point of down ////this.addOnePipe(480, i * 60 + 10);
///Score for pipes
this.score += 1;
this.labelScore.text = this.score;
},
addOnePipe: function(x, y) {
var pipe = game.add.sprite(x, y, 'pipe');
this.pipes.add(pipe);
game.physics.arcade.enable(pipe);
pipe.body.velocity.x = -200;
pipe.checkWorldBounds = true;
pipe.outOfBoundsKill = true;
},
hitPipe: function() {
// If the bird has already hit a pipe, do nothing
// It means the bird is already falling off the screen
if (this.bird.alive == false)
return;
else {
game.state.start("StateOver");
}
// Set the alive property of the bird to false
this.bird.alive = false;
// Prevent new pipes from appearing
game.time.events.remove(this.timer);
// Go through all the pipes, and stop their movement
this.pipes.forEach(function(p){
p.body.velocity.x = 0;
}, this);
},
};
// Initilate the Phaser Framework
var game = new Phaser.Game(480, 640, Phaser.AUTO);
game.state.add("main", MainState);
game.state.add("stateTitle", stateTitle);
game.state.add("StateOver", StateOver);
game.state.add("characters", characters);
game.state.start("stateTitle");
-----------------------------------------------------------------------------
Game over screen stateover.js
var StateOver={
preload:function()
{
game.load.spritesheet('button', 'assets/button.png', 215, 53, 8);
game.load.image("title", "assets/title.png");
game.load.image("game", "assets/extra/gameover.png");
},
create:function()
{
this.title = game.add.tileSprite(0, game.height-640,game.width, 640, 'title');
this.title.autoScroll(-100,0);
this.btnPlayAgain=game.add.button(110,400,'button',this.playAgain,this,2,3,2);
this.btnMainMenu=game.add.button(110,300,'button',this.mainMenu,this,4,5,4);
this.btnStore=game.add.button(110,200,'button',this.Store,this,6,7,6);
this.game.add.sprite (118, 100, "game");
highScoreText = this.game.add.text(130, 150, 'HS: ' + highscore, {
font: '25px Arial',
fill: 'black'
});
},
playAgain:function()
{
game.state.start("main");
},
mainMenu:function()
{
game.state.start("stateTitle");
},
Store:function()
{
game.state.start("characters");
},
update:function()
{
highScoreText.text = 'HIGHSCORE: ' + localStorage.getItem("highscore");
{
if (this.score > localStorage.getItem("highscore"))
{
localStorage.setItem("highscore", this.score);
}
}
},
};
This is the main title screen
var stateTitle={
preload:function()
{
game.load.image("logo", "assets/extra/Logo.png");
game.load.image("title", "assets/title.png");
game.load.spritesheet('button', 'assets/button.png', 215, 53, 8);
},
create:function()
{
this.title = game.add.tileSprite(0, game.height-640,game.width, 640, 'title');
this.title.autoScroll(-100,0);
this.btnStart=game.add.button(110,400,'button',this.startGame,this,0,1,1);
this.btnStore=game.add.button(110,480,'button',this.Store,this,6,7,6);
this.logo = game.add.sprite(60, 150, 'logo');
},
startGame:function()
{
game.state.start("main");
},
Store:function()
{
game.state.start("characters");
},
update:function()
{
},
};
Html with sample
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta charset="UTF-8-8">
<meta name="viewport" content="user-scalable=0, initial-scale=1,minimum-scale=1, maximum-scale=1, width=device-width, minimal-ui=1">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, minimum-scale=1, user-scalable=no">
<script type="text/javascript" src="js/phaser.js"></script>
<script src="js/stateTitle.js"></script>
<script src="js/characters.js"></script>
<style>
body {
padding: 0px;
margin: 0px;
background: black;
c
}
</style>
</head>
<body>
<script src="js/stateOver.js"></script>
<script src="js/main.js"></script>
<script type="text/javascript">
function onDeviceready() {
admob.createBannerView({publisherId: "ca-app-pub-XXXXXXXXXXXXXXXX/BBBBBBBBBB"});
}
document.addEventListener('deviceready', onDeviceready, false);
</script>
</body>
</html>
Firstly add admob plugin then just add below lines to your html file:
<script>
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
if (AdMob)
AdMob.prepareInterstitial({
adId : 'ca-app-pub-xxx/yyy',
autoShow : false
});
if (AdMob)
AdMob.createBanner({
adId : 'ca-app-pub-xxx/yyy',
position : AdMob.AD_POSITION.BOTTOM_CENTER,
autoShow : true,
overlap : true
});
}
</script>
You can change the place of the banner; use TOP_CENTER (I am not sure about this) instead of BOTTOM_CENTER.
Ok SOOOOO many tries alone I was able to fix this by simply inserting the extra needed plugins. Internet connection etc. BOOOOOOOOOOOOOOM Fixed any questions ask.

Adding objects into an array in javascript

I am trying to get the mouse pointer coordinates and store them into an array(tail) such that the array is limited only to 100 objects. If extra objects comes,the old one's are to be replaced with the new one's. Basically like a queue.
Basically i am trying to create a trail after the basic circle using a circle of smaller radius.
Here's my js:
$(document).ready(function() {
var tail = {
x:0,
y:0
};
var i = 0;
var stage = new Kinetic.Stage({
container: 'container',
width: window.innerWidth,
height: window.innerHeight,
listening: true
});
var layer = new Kinetic.Layer({
listening: true
});
var layer = new Kinetic.Layer();
var player = new Kinetic.Circle({
x: 20,
y: 20,
radius: 6,
fill: 'cyan',
stroke: 'black',
draggable: true
});
var pixel = new Kinetic.Circle({
x: 20,
y: 20,
radius: 2,
width: stage.getWidth(),
height: stage.getHeight(),
fill: "white"
});
layer.add(player);
stage.add(layer);
// move the circle with the mouse
stage.getContent().addEventListener('mousemove', function() {
player.setPosition(stage.getPointerPosition());
console.log(stage.getPointerPosition());
var obj = {
x: stage.getPointerPosition().x,
y: stage.getPointerPosition().y
}
tail[i].push(obj);
++i;
console.log(tail[i]);
// pixel.setPosition(tail[i], tail[i + 1]);
layer.draw();
});
});
And here's the html:
<!DOCTYPE html>
<html>
<head>
<title>Collision Detection</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width">
<link rel="stylesheet" href="../css/style.css"/>
</head>
<body>
<div id="container" style=" background:#000; margin:auto; float:left;"></div>
<script src="../js/jquery.min.js"></script>
<script src="../js/kinetic-v5.0.0.min.js"></script>
<script src="../js/main_kinetic.js"></script>
</body>
</html>
Output:
Uncaught TypeError: Cannot call method 'push' of undefined main_kinetic.js:46
Object {x: 656, y: 175} --> console output which returns the cursor position.
Here's the fiddle: http://jsfiddle.net/BVeTH/
You could create your own container for your data points that handles only keeping 100 (or however many you want). Something like this:
var LimitedArray = function (upperLimit) {
var storage = [];
// default limit on length if none/invalid supplied;
upperLimit = +upperLimit > 0 ? upperLimit : 100;
this.push = function (item) {
storage.push(item);
if (storage.length > upperLimit) {
storage.shift();
}
return storage.length;
};
this.get = function (i) {
return storage[i];
};
this.iterateItems = function (iterator) {
var i, l = storage.length;
if (typeof iterator !== 'function') { return; }
for (i = 0; i < l; i++) {
iterator(storage[i]);
}
};
};
(see here: http://jsfiddle.net/Frm27/4/)
Then you can track your datapoints easily:
var trail = new LimitedArray(100);
// code...
// move the circle with the mouse
stage.getContent().addEventListener('mousemove', function() {
player.setPosition(stage.getPointerPosition());
console.log(stage.getPointerPosition());
var obj = {
x: stage.getPointerPosition().x,
y: stage.getPointerPosition().y
}
trail.push(obj);
trail.iterateItems(function (item) {
// Do something with each item.x and item.y
});
// pixel.setPosition(tail[i], tail[i + 1]);
layer.draw();
});
Unless you reassign it somewhere I am not seeing tail is not an array.
var tail = {
x:null,
y:0
};
If you wanted to store objects with x and y coordinates in it you would need
var tail = [{
x:null,
y:0
}];
tail.push(...);

How to change image source on mouseover in Fabric.js?

My JS file:
(function() {
var canvas = this.__canvas = new fabric.Canvas('c', {
hoverCursor: 'pointer',
selection: false
});
fabric.Object.prototype.transparentCorners = false;
canvas.findTarget = (function(originalFn) {
return function() {
var target = originalFn.apply(this, arguments);
if (target) {
if (this._hoveredTarget !== target) {
canvas.fire('object:over', {target: target});
if (this._hoveredTarget) {
canvas.fire('object:out', {target: this._hoveredTarget});
}
this._hoveredTarget = target;
}
}
else if (this._hoveredTarget) {
canvas.fire('object:out', {target: this._hoveredTarget});
this._hoveredTarget = null;
}
return target;
};
})(canvas.findTarget);
canvas.on({
'object:over': function(e) {
if (e.target.name === 'Production') {
e.target.src = 'Resources/Shape/Production_Hover.svg';
canvas.renderAll.bind(canvas);
}
}
});
canvas.on('object:out', function(e) {
e.target.setFill('green');
canvas.renderAll();
});
var shapeImages = [
{
name: 'Director',
top: 120,
left: 545
},
{
name: 'script',
top: 297,
left: 575
},
{
name: 'Production',
top: 43,
left: 500
}
];
function imageDisplay() {
var currentImage = shapeImages[0];
fabric.Image.fromURL('Resources/Shape/' + currentImage.name + '.svg', function(img) {
img.set({
left: currentImage.left,
top: currentImage.top,
name: currentImage.name
});
img.perPixelTargetFind = true;
img.targetFindTolerance = 4;
img.hasControls = img.hasBorders = false;
img.lockMovementX = img.lockMovementY = true;
canvas.add(img);
});
shapeImages.shift();
if (typeof shapeImages[0] !== 'undefined') {
imageDisplay();
}
}
imageDisplay();
})();
Since fabric.js uses objects for images,i cant change it by using ID.(By using document.getElementById)
So i would love if someone finds anything wrong with the code above..
Basically am trying to change the image of "Production" to "Production_Hover.svg" on mouseover.
This is what am trying to build :
http://www.ismfilms.com/diagram/diagramAS3.swf
I have only just started ,and reached till production part..
This is my Index File:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="js/fabric.js"></script>
</head>
<body>
<div id="canvas-container">
<canvas id="c" height="700" width="1000"></canvas>
</div>
<script src="js/flash_conversion.js"></script>
</body>
</html>
I don't think Fabric supports mouseover/mouseout out of the box but this might help: http://fabricjs.com/hovering/

Drag and drop using Raphael.js has laggy performance with more than 10 draggable elements

I'm making a simple HTML5 app, that will be wrapped to be used on Android, iOS and web browsers. In my app I need a set of points to be dragged and sorted in a certain way, I'm using raphael.js for the animations and movememts and it works fine with 3 or 4 circles, but when I use more the laggy performance appears (mobile browser). I also need the app to be able to draw lines on freehand, like a marker, and the code i'm using refers to drag to, so the performance is awful. The interesting part is that the first moves work great, as i move more elements the performance drops down drastically. It works fine in the pc browser, but works fine for 3 or 4 movements on the mobie browser.
Is there any way to make drag and drop run fast and smooth with large quantity of elements?
Here's the code:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Raphaël · Drag-n-drop</title>
<link rel="stylesheet" href="demo.css" type="text/css" media="screen">
<meta name="apple-mobile-web-app-capable" content="yes">
<link rel="apple-touch-icon-precomposed" href="/Raphael.png">
<link rel="stylesheet" href="demo-print.css" type="text/css" media="print">
<style>
#background {
width: 100%;
height: 100%;
position: fixed;
left: 0px;
top: 0px;
z-index: -1; /* Ensure div tag stays behind content; -999 might work, too. */
}
.stretch {
width:100%;
height:100%;
}
</style>
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
<script src="raphael-min.js"></script>
<script>
window.onload = function () {
var y = $(window).height();
var x = $(window).width();
y=y/30;
var posX=y;
var posY=y;
var posX2=x-y;
var R = Raphael(0, 0, "100%", "100%");
var nJ=10
var jugador=new Array();
var rival=new Array();
crearJugadores(nJ);
crearRivales(nJ);
function crearJugadores(nJ) {
nJ=nJ;
for (var i=0;i<nJ;i++)
{
jugador[i]= R.circle(posX, posY, y).attr({fill: "hsb(0, 1, 1)", stroke: "none", opacity: .5});
posY=posY+(2*y);
};
};
function crearRivales(nJ) {
posX=x-y;
posY=y;
nJ=nJ;
for (var i=0;i<nJ;i++)
{
rival[i]= R.circle(posX, posY, y).attr({fill: "#214dcf", stroke: "none", opacity: .5});
posY=posY+(2*y);
};
};
var start = function () {
this.ox = this.attr("cx");
this.oy = this.attr("cy");
this.animate({r: (1.5*y), opacity: .3}, 100, ">");
},
move = function (dx, dy) {
this.attr({cx: this.ox + dx, cy: this.oy + dy});
},
up = function () {
this.animate({r: y, opacity: 1}, 500, ">");
};
R.set(rival).drag(move, start, up);
R.set(jugador).drag(move, start, up);
initDrawing(R);
};
var g_masterPathArray;
var g_masterDrawingBox;
var g_masterPaper;
function initDrawing(R) {
g_masterPaper = R;
var masterBackground = g_masterPaper.rect(0,0,"100%","100%");
masterBackground.attr({fill:"blue", opacity: 0});
masterBackground.mousemove(function (event) {
var evt = event;
var IE = document.all?true:false;
var x, y;
if (IE) {
x = evt.clientX + document.body.scrollLeft +
document.documentElement.scrollLeft;
y = evt.clientY + document.body.scrollTop +
document.documentElement.scrollTop;
}
else {
x = evt.pageX;
y = evt.pageY;
}
// subtract paper coords on page
this.ox = x;
this.oy = y;
});
var start = function () {
g_masterPathArray = new Array();
},
move = function (dx, dy) {
if (g_masterPathArray.length == 0) {
g_masterPathArray[0] = ["M",this.ox,this.oy];
g_masterDrawingBox = g_masterPaper.path(g_masterPathArray);
g_masterDrawingBox.attr({stroke: "#000000","stroke-width": 3});
}
else
g_masterPathArray[g_masterPathArray.length] =
["L",this.ox,this.oy];
g_masterDrawingBox.attr({path: g_masterPathArray});
},
up = function () {
;
};
masterBackground.drag(move, start, up);
masterBackground.toBack();
}
</script>
</head>
<body>
<div id="background">
<img src="cancha.jpg" class="stretch" alt="" />
</div>
<div id="holder"></div>
</body>
</html>
Any ideas??
Thanks

Categories