Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 11:44:40 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Is this a gml bug? image_alpha problem....
Pages: [1]
Print
Author Topic: Is this a gml bug? image_alpha problem....  (Read 1010 times)
CatchAFish
Level 0
*


View Profile
« on: February 19, 2017, 03:16:55 PM »

I'm pulling my hair out with this one in Game Maker Studio. Little snippet of code;

Code:
image_blend = global.tal_colour;
image_alpha -= 0.005;

The code is self explanatory, it blends the image to a global colour pallette and then slowly fades the image to 0 alpha. Works perfectly fine if executed directly in the object Step event, but if I call a script in the step event it won't play nice, the blend works but the alpha does nothing. Any ideas? The full code is below but I have tried simplifying it to eliminate problems and I still get the same issue with no alpha reduction... I'm using a State Machine btw

So my Step event is

Code:
script_execute(state);

my Create event is

Code:
///setup the logo
// set properties
fadespeed = room_speed/12000;
image_alpha = 1;
image_blend = c_white;

// set state and positioning
if (room == rm_splashscreen)
    {
    state = scr_normal();
    x = room_width/2;
    y = room_height/3;
    image_xscale = 0.4;
    image_yscale = 0.4;
    }

if (room == rm_hangar)
    {
    x = room_width-96;
    y = room_height-96;
    image_xscale = 0.1;
    image_yscale = 0.1;
    state = scr_animate_logo(0.1, 0.3, 0.6);
    }

and the script is

Code:
///scr_animate_logo(animation_speed, lower_bound, upper_bound)
var animation_speed = argument0;
var lower_bound = argument1;
var upper_bound = argument2;

//colour the logo
image_blend = global.tal_colour;
image_alpha -= 0.005;
Logged
emptyfortress
Level 0
**



View Profile WWW
« Reply #1 on: February 20, 2017, 02:55:41 PM »

Your script_execute statement seems to be the problem. When you set your state in your create event, you're not setting state to the name of the script to use, but to the return value of running the script once; so in your Step event script_execute doesn't run your script like you want it to, and the image_alpha value doesn't change.

Try this:

if (room == rm_hangar)
    {
    x = room_width-96;
    y = room_height-96;
    image_xscale = 0.1;
    image_yscale = 0.1;
    state = scr_animate_logo;
    }


The script_execute call should now run correctly.

Hope that helps!
Logged
CatchAFish
Level 0
*


View Profile
« Reply #2 on: February 21, 2017, 12:15:09 AM »

Ah! That is it... thank you. It now works on the script I posted.

However, the script code was a truncated version for testing, the full version needs 3 variables that are fed by the arguments. So how do I set the state to a script, and feed arguments to the script without returning the value of running the script?

I'm really sorry if this is a basic question...!
Logged
emptyfortress
Level 0
**



View Profile WWW
« Reply #3 on: February 21, 2017, 10:26:41 AM »

There are several ways to do it, me I'd just store the variable in the object itself, like so:

if (room == rm_hangar)
    {
    x = room_width-96;
    y = room_height-96;
    image_xscale = 0.1;
    image_yscale = 0.1;
    state = scr_animate_logo;
    animation_speed = 0.1;
    lower_bound = 0.3;
    upper_bound = 0.6;

    }

The state script can access any of the variables stored in the object calling it (like you did with image_alpha). There are other ways to do it but if you only have a handful of variables I think this is the simplest and easiest way to do it.
Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic