2 Replies - 3403 Views - Last Post: 11 May 2018 - 09:02 AM

#1 jwlickliter   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-May 18

Need help as3 with sin and cos

Posted 10 May 2018 - 04:36 PM

This may be a long post and sorry but im going to try and include as much info as I can.

My stage is set at 30fps and 1280x720

I loaded a jpg image and cut it up into 100 pieces. Each piece is 128x72. Then put them in the center of the stage. Added it to an array. Works good so far.

I have as3 bible and game programming university. In gpu theres some code to turn a car and a arrow that points at the mouse. I have all my images pieces starting in the center of the screen on top of each other. I want to explode all of the out following like a shockwave until they reach the corret locations to make the picture whole again. Ill reverse after I figure out forward.

Heres the code i need help with. I was thinking of getting the angle of the picture pieces and move them to the correct place but the code in the two examples rotate the images and i dont want to rotate them

My images use top left registration points and not center.

The car code:

 // calculate x and y speed and move car
Public function moveForward() 
Var speed:Number = 5.0;
Var angle:Number = 2*Math.PI*(car.rotation/360);
Var dx:Number = speed*Math.cos(angle);
Var dy:Number = speed*Math.sin(angle);
Car.x += dx;
Car.y += dy;




Sorry on my cell. The is my way of using the regular open and close for functions on computer.

The other code is

Public function pointAtCursor(event:Event) 
Var dx:Number = mouseX - pointer.x;
Var dy:Number = mouseY - pointer.y;

// determine angle, convert to degress
Var cursorAngle:Number = Math.atan2(dy,dx);
Var cursorDegress:Number = 360*(cursorAngle/(2*Math.PI));

// point at cursor
Pointer.rotation = cursorDegrees;



So i dont really understand math sin and cos and atan. I do understand how this works. I used it alot and buolt on top of it but it was always with moving images that did need to rotate.

I just need a path to follow the images to build the picture. I dont need keyboard or mouse clicks either as I will be exporting to mov file. Its not going to be any ui.

It there a way to change this code or write something that could help me? Thanks in advance!

Is This A Good Question/Topic? 0
  • +

Replies To: Need help as3 with sin and cos

#2 ndc85430   User is offline

  • I think you'll find it's "Dr"
  • member icon

Reputation: 977
  • View blog
  • Posts: 3,855
  • Joined: 13-June 14

Re: Need help as3 with sin and cos

Posted 11 May 2018 - 01:09 AM

View Postjwlickliter, on 11 May 2018 - 12:36 AM, said:

I have all my images pieces starting in the center of the screen on top of each other. I want to explode all of the out following like a shockwave until they reach the corret locations to make the picture whole again. Ill reverse after I figure out forward.


It sounds like what you want to do for each piece is move them radially outwards from the origin, keeping the same angle to the horizontal axis, right? It would help, then, to think about this in terms of polar coordinates instead of cartesian ones. If that's not what you're wanting to do, please clarify (perhaps with a diagram or something to aid us).
Was This Post Helpful? 0
  • +
  • -

#3 jwlickliter   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 10-May 18

Re: Need help as3 with sin and cos

Posted 11 May 2018 - 09:02 AM

Yeah you seem to understand. I want to explode it like a circle and then put the pieces back to the original image in there correct locations.

Needs to be smooth not like atari 8 bit system where it moves 1px on the x then 1px on the y.

Thanks for the reply and help!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1