Hello, I'm still pretty new to as3 and especially new to WCK. I have managed to hack a plethora of tutorials together, and I'm confident I'm getting somewhere.
I've managed to get one of Emanuele Feronato's tutorials (Tutorial) to work with the WCK.
I'm trying to implement a panning feature, exactly like line rider, where the player holds down a key and can pan through their world. If myWorld.scrolling = true and myWorld's focus is attached to a movie clip already centered to the stage, everything is fine while drawing lines. The problem comes when I try to move myWorld, or myWorld's focus is on a mc that isn't placed in the center of the stage,and draw more lines. The lines still draw to the stage, but the boxes created have an offset that doesn't seem relative to the amount the view port of the stage has moved.
I feel like I understand enough of this code to be a little dangerous, but not enough to know if I need to simply change a couple variables with globalToLocal. (I have tried changing a few variables this way but have had no luck.)
Here's the code I'm using to draw:
public function mousePressed(e:MouseEvent):void {
isDrawing = true;
canvas.graphics.moveTo(mouseX, mouseY)
pointsArray = new Array;
savedX = mouseX;
savedY = mouseY;
pointsArray.push(savedX);
pointsArray.push(savedY);
}
canvas is a Sprite.
public function mouseMoved(e:MouseEvent): void {
if(isDrawing) {
var distX:int = mouseX - savedX;
var distY:int = mouseY - savedY;
if (distX * distX + distY * distY > pixelDist * pixelDist) {
canvas.graphics.lineTo(mouseX,mouseY);
savedX = mouseX;
savedY = mouseY;
pointsArray.push(savedX);
pointsArray.push(savedY);
}
}
}
Everything so far has been just about the same code as Emanuele's, but this next function I altered a bit to work with WCK.
public function createBox(px,py,w,h,a):void {
var box:Wall = new Wall;
box.position =(px,py);
box.x = px*30;
box.y = py*30;
box.width = w*60;
box.height = h*60;
box.rotation = a*rad2Deg;
box.type = "STATIC";
myWorld.addChild(box);
}
Changing this function took me a while and I've been playing with the variables, but all of them need to be set to exactly what they are right now for the boxes to be created where the line was drawn.
I've looked through the forum and especially at burtonposey's BoundaryDemo but I haven't been able to solve this one.
Please let me know if I need to clarify further.
I'd be grateful for any help, or any push in the right direction.
I've managed to get one of Emanuele Feronato's tutorials (Tutorial) to work with the WCK.
I'm trying to implement a panning feature, exactly like line rider, where the player holds down a key and can pan through their world. If myWorld.scrolling = true and myWorld's focus is attached to a movie clip already centered to the stage, everything is fine while drawing lines. The problem comes when I try to move myWorld, or myWorld's focus is on a mc that isn't placed in the center of the stage,and draw more lines. The lines still draw to the stage, but the boxes created have an offset that doesn't seem relative to the amount the view port of the stage has moved.
I feel like I understand enough of this code to be a little dangerous, but not enough to know if I need to simply change a couple variables with globalToLocal. (I have tried changing a few variables this way but have had no luck.)
Here's the code I'm using to draw:
Code:
public function mousePressed(e:MouseEvent):void {
isDrawing = true;
canvas.graphics.moveTo(mouseX, mouseY)
pointsArray = new Array;
savedX = mouseX;
savedY = mouseY;
pointsArray.push(savedX);
pointsArray.push(savedY);
}
canvas is a Sprite.
Code:
public function mouseMoved(e:MouseEvent): void {
if(isDrawing) {
var distX:int = mouseX - savedX;
var distY:int = mouseY - savedY;
if (distX * distX + distY * distY > pixelDist * pixelDist) {
canvas.graphics.lineTo(mouseX,mouseY);
savedX = mouseX;
savedY = mouseY;
pointsArray.push(savedX);
pointsArray.push(savedY);
}
}
}
Code:
public function mouseReleased(e:MouseEvent):void {
isDrawing=false;
var sx:int;
var ex:int;
var sy:int;
var ey:int;
var dist_x:int;
var dist_y:int;
var dist:Number;
var angle:Number;
var segments:int=pointsArray.length/2-1;
for (var i:int=0; i<segments; i++) {
sx=pointsArray[i*2];
sy=pointsArray[i*2+1];
ex=pointsArray[i*2+2];
ey=pointsArray[i*2+3];
dist_x=sx-ex;
dist_y=sy-ey;
dist=Math.sqrt(dist_x*dist_x+dist_y*dist_y);
angle=Math.atan2(dist_y,dist_x);
createBox((sx+ex)/60,(sy+ey)/60,Math.abs(dist)/60,2/30,angle);
}
canvas.graphics.clear();
canvas.graphics.lineStyle(5);
}
isDrawing=false;
var sx:int;
var ex:int;
var sy:int;
var ey:int;
var dist_x:int;
var dist_y:int;
var dist:Number;
var angle:Number;
var segments:int=pointsArray.length/2-1;
for (var i:int=0; i<segments; i++) {
sx=pointsArray[i*2];
sy=pointsArray[i*2+1];
ex=pointsArray[i*2+2];
ey=pointsArray[i*2+3];
dist_x=sx-ex;
dist_y=sy-ey;
dist=Math.sqrt(dist_x*dist_x+dist_y*dist_y);
angle=Math.atan2(dist_y,dist_x);
createBox((sx+ex)/60,(sy+ey)/60,Math.abs(dist)/60,2/30,angle);
}
canvas.graphics.clear();
canvas.graphics.lineStyle(5);
}
Everything so far has been just about the same code as Emanuele's, but this next function I altered a bit to work with WCK.
Code:
public function createBox(px,py,w,h,a):void {
var box:Wall = new Wall;
box.position =(px,py);
box.x = px*30;
box.y = py*30;
box.width = w*60;
box.height = h*60;
box.rotation = a*rad2Deg;
box.type = "STATIC";
myWorld.addChild(box);
}
Changing this function took me a while and I've been playing with the variables, but all of them need to be set to exactly what they are right now for the boxes to be created where the line was drawn.
I've looked through the forum and especially at burtonposey's BoundaryDemo but I haven't been able to solve this one.
Please let me know if I need to clarify further.
I'd be grateful for any help, or any push in the right direction.