Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving view point in 2d 1

Status
Not open for further replies.

WElliott

MIS
Sep 3, 2002
1
NZ
I wish to shift the view when the mouse is moved away from the center of stage.

A similar effect to rts strategy games when the mouse is moved to the side of the screen and the view point moves.

Cheers
WElliott
 
Here's the script. If you'd rather have a file, tell me yur email and I'll send it to you. Put this script on any picture thats bigger than the stage and it shood work.

---Begin Copying---

--Put this script on any picture (map, photo, etc.). Configure the first 3 varibles to you needs, then BAM! it works.
property stageRect, noMoveRect, mys, scrollSpeed

on beginsprite me

--These Variables must be configured to match each movie or user's preference
kickOn = 30 --How many pixles away from the edge of the stage the mouse needs to be to start moving picture
scrollSpeed = 4 --How many pixels-per-frame to scroll
stageRect = rect(0,0,500,330) --The top, bottom, left, and right of the stage
-----------------------------------------------------------------------------

mys = me.spritenum --Find and store spriteNumber
noMoveRect = [stageRect[1] + kickOn, stageRect[2] + kickOn, stageRect[3] - kickOn, stageRect[4] - kickOn] --Inner Rectangle
sprite(mys).loc = point(stageRect[3] / 2, stageRect[4] /2) --Reset picture middle to stage middle

end

on prepareframe me

--Store the mouse X and Y location
theX = the mouseh
theY = the mousev

--Check the location of mouse, and if need be, scroll the picture.
if inside(the mouseloc, stageRect) then

if theX < noMoveRect[1] then
if sprite(mys).left + scrollSpeed <= stageRect[1] then
sprite(mys).loch = sprite(mys).loch + scrollSpeed
end if
end if

if theX > noMoveRect[3] then
if sprite(mys).right - scrollSpeed >= stageRect[3] then
sprite(mys).loch = sprite(mys).loch - scrollSpeed
end if
end if

if theY < noMoveRect[2] then
if sprite(mys).top + scrollSpeed <= stageRect[2] then
sprite(mys).locv = sprite(mys).locv + scrollSpeed
end if
end if

if theY > noMoveRect[4] then
if sprite(mys).bottom - scrollSpeed >= stageRect[4] then
sprite(mys).locv = sprite(mys).locv - scrollSpeed
end if
end if

end if

end

--Stop Copying--
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top