1
\$\begingroup\$

My game has a zoom function. There is a man in a spaceship, we can see the interior of the room room from side on as the outside is totally transparent. When I zoom out I want the outside of the spaceship to become gradually less transparent and the window sprite to shrink to give the illusion of depth. When zooming the opposite will happen. With my current code the scaling and alpha changes are triggered when a the zoom factor is above or below 1.5.

My question is this - How can I make the scaling and alpha changes directly link to the zoom level so the change is smooth and directly correlates to the zoom value at all times, not just at a set point such as 1.5?

Thanks for your help, here is my code :

*****(Event: oWindow_Step_1)*****

    ///set up transparency & scaling

//make transparent to start
if oPlayer.zoom = 1 
    {
    image_alpha = 0
    image_xscale = 1
    }

//if camera zooms out make window smaller and more opaque
if oPlayer.zoom > 1.5
    {
    image_alpha += 0.01
    image_xscale -= 0.03
    image_yscale -= 0.03
    }

//if camera zooms in make window bigger and more transparent
if oPlayer.zoom < 1.5
    {
    image_alpha -= 0.01
    image_xscale += 0.03
    image_yscale += 0.03
    }

//stop image_xscale exceeding 3   
if image_xscale >= 1.5
    {
    image_xscale = 1.5
    image_yscale = 1.5
    }

//stop image_xscale being less than 1  
if image_xscale <= 1
    {
    image_xscale = 1
    image_yscale = 1
    }

///set up transparency & scaling

//make transparent to start
if oPlayer.zoom = 1 
    {
    image_alpha = 0
    image_xscale = 1
    }

//if camera zooms out make window smaller and more opaque
if oPlayer.zoom > 1.5
    {
    image_alpha += 0.01
    image_xscale -= 0.03
    image_yscale -= 0.03
    }

//if camera zooms in make window bigger and more transparent
if oPlayer.zoom < 1.5
    {
    image_alpha -= 0.01
    image_xscale += 0.03
    image_yscale += 0.03
    }

//stop image_xscale exceeding 3   
if image_xscale >= 1.5
    {
    image_xscale = 1.5
    image_yscale = 1.5
    }

//stop image_xscale being less than 1  
if image_xscale <= 1
    {
    image_xscale = 1
    image_yscale = 1
    }
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.