It is currently Mon Sep 06, 2010 5:43 pm

All times are UTC - 8 hours




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: ZOOM
PostPosted: Wed Jan 27, 2010 12:50 am 
Offline
Valid User
User avatar

Joined: Tue Jan 19, 2010 8:37 pm
Posts: 239
Location: New Zealand cus
Hay.

I am making a sniper game on flash 8 professional.

I am having a bit of trouble coding a zoom function. I have tried a resizing vcam that follows your mouse but that made it possible for the mouse to move off the screen.

If anyone could help that would be great.

thanks in advance.

_________________
Image


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Wed Jan 27, 2010 4:17 am 
Offline
Golden Veteran
User avatar

Joined: Tue Apr 15, 2008 1:37 am
Posts: 1803
Location: Deserves conflagration
Dude, go make an introduction or something. You need to become part of the site lol.
I'll help anyway.

Well, the vCam actually changes the co-ordinates of the frame (_root), so it's not ideal for this.
Fortunately, there's a handy little function called Stage, which deals with the properties of the .swf itself, in a browser or on its own. Like the actual width and height of the .swf itself. These properties can't be changed with Actionscript. This is useful because you can keep track of the .swf's width (Stage.width) separate of the _root, if that makes sense. Changing the width of the _root will stretch all the contents of the frame, but it won't make the .swf any larger or smaller.

Anyway, you can simply set the frame's position relative to the mouse's position minus the center of the Stage using this line of code:
  1. _root._x = (_xmouse-Stage.width/2)*-0.5

You do Stage.width/2 to get the centre of the swf. The *-0.5 decides the boundaries (and adds a little easing).

In a function, it'd look like this:

  1. onEnterFrame = function () {
  2. _root._x = (_xmouse-Stage.width/2)*-0.5;
  3. _root._y = (_ymouse-Stage.height/2)*-0.5;
  4. }


If you want the crosshair (or anything else) to stay in the center of the stage, use this:
  1.  crosshair._x = (_root._x-(Stage.width/2))*-1;
  2. crosshair._y = (_root._y-(Stage.height/2))*-1;


Only problem is that it can get a little bit complex here, because now you're not positioning the bulletholes and the clicks and everything where the mouse is, but where the crosshair is. So just remember to set the bulletholes and such at crosshair._x and crosshair._y rather than _xmouse and _ymouse, (and you can't be clicking buttons; you have to use hitTest or other methods)

Good luck. I'll try to help out as much as possible, and I could make an example file for you to study if this is a little too confusing.

_________________
Bananas


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Wed Jan 27, 2010 5:48 am 
Offline
Valid User
User avatar

Joined: Tue Jan 19, 2010 8:37 pm
Posts: 239
Location: New Zealand cus
thanks heaps man. If you could make a sample, that would be great. cos im lost =S ^_^


ill make an intro now

_________________
Image


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Wed Jan 27, 2010 10:20 pm 
Offline
Golden Veteran
User avatar

Joined: Tue Apr 15, 2008 1:37 am
Posts: 1803
Location: Deserves conflagration
Alright, here's a sample.
FLA: http://www.truploader.com/view/069630
SWF: http://www.truploader.com/view/123120
(for some reason, Google Chrome is making it so that the mouse is visible for me. I dunno why.)
Don't bother just using this engine and changing graphics and stuff. It's very confusing and there's lots of crap to sift through (lucky you :D)
It's just an example for you to TRY to read through it and understand what's going on, then MAKE YOUR OWN WITH YOUR OWN CODE.
If this isn't exactly how you want the zooming to look, just say. There are other ways.

_________________
Bananas


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Wed Jan 27, 2010 10:47 pm 
Offline
Valid User
User avatar

Joined: Tue Jan 19, 2010 8:37 pm
Posts: 239
Location: New Zealand cus
thanks so much =)

this is the best sniper engine I have ever seen ^_^

just one problem...

I try opening it and it says unexpected file format =S

_________________
Image


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Wed Jan 27, 2010 11:56 pm 
Offline
Golden Veteran
User avatar

Joined: Wed Apr 16, 2008 11:09 am
Posts: 1130
Location: Pleasanton Ca
Malfunction i am always thoroughly impressed by your coding skills. Always.

_________________
My RHG "Ð"
Image
Quote:
Our two characters are going to cancel each other out constantly if not creating a black hole of infinite redundancy.


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Thu Jan 28, 2010 12:01 am 
Offline
Valid User
User avatar

Joined: Tue Jan 19, 2010 8:37 pm
Posts: 239
Location: New Zealand cus
so am I but I can't open the file...

I'm on flash 8 pro... any suggestions?

_________________
Image


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Thu Jan 28, 2010 12:03 am 
Offline
Golden Veteran
User avatar

Joined: Tue Apr 15, 2008 1:37 am
Posts: 1803
Location: Deserves conflagration
Oh sorry, Flash 8 version: http://www.truploader.com/view/550897

_________________
Bananas


Top
 Profile Send private message  
 
 Post subject: Re: ZOOM
PostPosted: Thu Jan 28, 2010 12:08 am 
Offline
Valid User
User avatar

Joined: Tue Jan 19, 2010 8:37 pm
Posts: 239
Location: New Zealand cus
thank you so much.

I owe you one. Really.

_________________
Image


Top
 Profile Send private message  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC - 8 hours


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Blue Moon by Trent © 2007
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group