Post subject: sun and moon not following the view [SOLVED]
Posted: Mon Dec 06, 2010 11:27 pm
Lucario and/or Braixen = best avatar
[SOLVED]
The objects themselves that do the drawing must also follow the view, as the code makes the sun and moon fade out as they go offscreen.
The sun and moon in my game, I cannot get them to follow the screen D: they circle the screen perfectly, but won't follow the view. I'll post the code that the sun and moon use here. Anyone who could help, please give me a hand
obj_sun: Spoiler:
Create Event:
Code:
//Set up some arrays to hold information about the glare lines. var i; glareCount=50; for(i=0;i<glareCount;i+=1){ glareAngle[i]=random(360); glareDelta[i]=1-random(2);//How much the angles should change at each step. glareLength[i]=0.13+random(0.3); } alpha = 1 direction = 120 start = 120 speed = 0.05 x = view_xview[0]+352 y = view_yview[0]+64 touch = false fade = 0 //for the future lighting system dark = 125 orange = 0
Step Event:
Code:
//Update the angles for the glare lines. var i; for(i=0;i<glareCount;i+=1)glareAngle[i]+=glareDelta[i]; if y<view_yview[0]-28 or x<view_xview[0]-28 or y>view_yview[0]+100 alpha -= 0.01; if y>view_yview[0]-28 and y<view_yview[0]+100 alpha += 0.001; if alpha > 1 { alpha = 1; fade = 0; } if alpha < 0 alpha = 0; direction += 0.015; if direction > 360 direction = start; if y > view_yview[0]+100 && alpha = 0 && !instance_exists(obj_moon) instance_create(view_xview[0]+342,view_yview[0]+64,obj_moon); if alpha = 0 && x < view_xview[0]-28 && y > view_yview[0]+100 && fade < 0.35 fade += 0.005; if y>view_yview[0]-28 and y<view_yview[0]+100 && alpha < 1 fade -= 0.005; if fade > 0.35 fade = 0.35; if fade < 0 fade = 0; if x < view_xview[0]+64 && y > view_yview[0]+24 { if orange < 0.3 orange += 0.0025; if orange = 0.3 out = 1; dark -= 1; } if dark < 32 dark = 32; if dark > 125 dark = 125; if orange > 0.3 orange = 0.3; if orange < 0 orange = 0; if x > view_xview[0]+260 && y < view_yview[0]+210 dark += 1; if instance_exists(obj_moon) orange -= 0.0025;
Draw Event: draw_flare()
draw_flare Script:
Code:
//Draws a lens flare focused between the calling object and the center of the screen.
//Determine the x and y distances between the sun and the CENTER OF THE VISIBLE SCREEN... //var flareSizeX,flareSizeY;//Note that these are not declared. This is so that they can be accessed easily inside the draw_flare_part script. (They'll be local to the object instead of the script.) flareSizeX=view_wview[0]/2-x;//Realistically, you probably have views, which would require an actual calculation here. flareSizeY=view_hview[0]/2-y;//Note that means these two lines must very likely be replaced when put into actual use. //flareSizeX=(view_xview[0]+332)/2-x;//Realistically, you probably have views, which would require an actual calculation here. //flareSizeY=(view_yview[0]+240)/2-y;//Note that means these two lines must very likely be replaced when put into actual use.
//Set the drawing mode... draw_set_blend_mode(bm_add);//Flares are shiny. texture_set_interpolation(true);//Scale smoothly.
//Start drawing flares... draw_flare_part(0,0,1,make_color_rgb(100,100,40));//The colors should be precomputed for speed, bu for the purpose of this example, I left them like this, so they're easier to play around with. draw_flare_part(0,0,0.6,make_color_rgb(180,180,180));
//Start drawing the extra glare lines... var i,glareColor; glareColor=make_color_rgb(30,30,30); for(i=0;i<glareCount;i+=1)draw_sprite_ext(imgFlareLine,0,x,y,glareLength[i],1,glareAngle[i],glareColor,alpha);
//Return the drawing mode to normal. draw_set_blend_mode(bm_normal); texture_set_interpolation(false);
draw_flare_part Script:
Code:
//draw_flare_part(type, position, size, color); // This draws a single flare. Not the entire lens flare, but a single section of it. // type is between 0 and 3. It just indicated how this part of the flare should look. // position is between 0 and 2, and indicates where the flare should be drawn. // 0=Right on the sun. // 1=Center of the screen. // 2=Opposite of the sun. // size indicates how large the flare sould be. // color is the color that the flare should be drawn in. Most should be somewhat dark.
[b][size=150][SOLVED][/size][/b]
The objects themselves that do the drawing must also follow the view, as the code makes the sun and moon fade out as they go offscreen.
The sun and moon in my game, I cannot get them to follow the screen D: they circle the screen perfectly, but won't follow the view.
I'll post the code that the sun and moon use here. Anyone who could help, please give me a hand
obj_sun:
[spoiler][color=#fe0]Create Event:[/color]
[code]//Set up some arrays to hold information about the glare lines.
var i;
glareCount=50;
for(i=0;i<glareCount;i+=1){
glareAngle[i]=random(360);
glareDelta[i]=1-random(2);//How much the angles should change at each step.
glareLength[i]=0.13+random(0.3);
}
alpha = 1
direction = 120
start = 120
speed = 0.05
x = view_xview[0]+352
y = view_yview[0]+64
touch = false
fade = 0
//for the future lighting system
dark = 125
orange = 0[/code]
[color=#5a70b3]Step Event:[/color]
[code]//Update the angles for the glare lines.
var i;
for(i=0;i<glareCount;i+=1)glareAngle[i]+=glareDelta[i];
if y<view_yview[0]-28 or x<view_xview[0]-28 or y>view_yview[0]+100
alpha -= 0.01;
if y>view_yview[0]-28 and y<view_yview[0]+100
alpha += 0.001;
if alpha > 1
{
alpha = 1;
fade = 0;
}
if alpha < 0
alpha = 0;
direction += 0.015;
if direction > 360
direction = start;
if y > view_yview[0]+100 && alpha = 0 && !instance_exists(obj_moon)
instance_create(view_xview[0]+342,view_yview[0]+64,obj_moon);
if alpha = 0 && x < view_xview[0]-28 && y > view_yview[0]+100 && fade < 0.35
fade += 0.005;
if y>view_yview[0]-28 and y<view_yview[0]+100 && alpha < 1
fade -= 0.005;
if fade > 0.35
fade = 0.35;
if fade < 0
fade = 0;
if x < view_xview[0]+64 && y > view_yview[0]+24
{
if orange < 0.3
orange += 0.0025;
if orange = 0.3
out = 1;
dark -= 1;
}
if dark < 32
dark = 32;
if dark > 125
dark = 125;
if orange > 0.3
orange = 0.3;
if orange < 0
orange = 0;
if x > view_xview[0]+260 && y < view_yview[0]+210
dark += 1;
if instance_exists(obj_moon)
orange -= 0.0025;[/code]
[color=#fb8a00]Draw Event:[/color]
[color=#ee4a2d]draw_flare()[/color]
draw_flare Script:
[code]//Draws a lens flare focused between the calling object and the center of the screen.
//Determine the x and y distances between the sun and the CENTER OF THE VISIBLE SCREEN...
//var flareSizeX,flareSizeY;//Note that these are not declared. This is so that they can be accessed easily inside the draw_flare_part script. (They'll be local to the object instead of the script.)
flareSizeX=view_wview[0]/2-x;//Realistically, you probably have views, which would require an actual calculation here.
flareSizeY=view_hview[0]/2-y;//Note that means these two lines must very likely be replaced when put into actual use.
//flareSizeX=(view_xview[0]+332)/2-x;//Realistically, you probably have views, which would require an actual calculation here.
//flareSizeY=(view_yview[0]+240)/2-y;//Note that means these two lines must very likely be replaced when put into actual use.
//Set the drawing mode...
draw_set_blend_mode(bm_add);//Flares are shiny.
texture_set_interpolation(true);//Scale smoothly.
//Start drawing flares...
draw_flare_part(0,0,1,make_color_rgb(100,100,40));//The colors should be precomputed for speed, bu for the purpose of this example, I left them like this, so they're easier to play around with.
draw_flare_part(0,0,0.6,make_color_rgb(180,180,180));
draw_flare_part(2,0.35,0.35,make_color_rgb(80,60,20));
draw_flare_part(1,0.39,0.1,make_color_rgb(60,50,20));
draw_flare_part(1,0.43,0.07,make_color_rgb(50,40,10));
draw_flare_part(2,0.65,0.1,make_color_rgb(40,30,100));
draw_flare_part(0,0.9,0.03,make_color_rgb(0,30,180));
draw_flare_part(0,1.05,0.05,make_color_rgb(0,180,30));
draw_flare_part(1,1.65,0.7,make_color_rgb(30,20,10));
draw_flare_part(3,2,1.5,make_color_rgb(15,10,5));
//Start drawing the extra glare lines...
var i,glareColor;
glareColor=make_color_rgb(30,30,30);
for(i=0;i<glareCount;i+=1)draw_sprite_ext(imgFlareLine,0,x,y,glareLength[i],1,glareAngle[i],glareColor,alpha);
//Return the drawing mode to normal.
draw_set_blend_mode(bm_normal);
texture_set_interpolation(false);[/code]
draw_flare_part Script:
[code]//draw_flare_part(type, position, size, color);
// This draws a single flare. Not the entire lens flare, but a single section of it.
// type is between 0 and 3. It just indicated how this part of the flare should look.
// position is between 0 and 2, and indicates where the flare should be drawn.
// 0=Right on the sun.
// 1=Center of the screen.
// 2=Opposite of the sun.
// size indicates how large the flare sould be.
// color is the color that the flare should be drawn in. Most should be somewhat dark.
draw_sprite_ext(imgFlareCircle,argument0,x+flareSizeX*argument1,y+flareSizeY*argument1,argument2,argument2,0,argument3,alpha);[/code][/spoiler]
Last edited by smbmaster99 on Tue Dec 07, 2010 7:49 pm, edited 1 time in total. _________________
Post subject: Re: sun and moon not following the view
Posted: Tue Dec 07, 2010 7:48 pm
Lucario and/or Braixen = best avatar
I solved it ^( ^
I changed this:
Code:
flareSizeX=view_wview[0]/2-x;//Realistically, you probably have views, which would require an actual calculation here. flareSizeY=view_hview[0]/2-y;//Note that means these two lines must very likely be replaced when put into actual use.
to this:
Code:
flareSizeX=view_xview[0]+160-x;//Realistically, you probably have views, which would require an actual calculation here. flareSizeY=view_yview[0]+120-y;//Note that means these two lines must very likely be replaced when put into actual use.
and it works perfectly ^( ^
thanks to all ^( ^
I solved it ^( ^
I changed this:
[code]flareSizeX=view_wview[0]/2-x;//Realistically, you probably have views, which would require an actual calculation here.
flareSizeY=view_hview[0]/2-y;//Note that means these two lines must very likely be replaced when put into actual use.[/code]
to this:
[code]flareSizeX=view_xview[0]+160-x;//Realistically, you probably have views, which would require an actual calculation here.
flareSizeY=view_yview[0]+120-y;//Note that means these two lines must very likely be replaced when put into actual use.[/code]
and it works perfectly ^( ^
thanks to all ^( ^
Post subject: Re: sun and moon not following the view [SOLVED]
Posted: Wed Dec 29, 2010 12:08 am
Ready to launch! And set for action!
Hey, I tried finding out how to make a Sun on Game Maker! Thanks, can I use your code, please? I'll give credit!
Hey, I tried finding out how to make a Sun on Game Maker! Thanks, can I use your code, please? I'll give credit!
_________________
I go by the name Mikeystar, one of the GM programmin' experts in my fangame, SM: ASA! This is such a passionate fangame that I work on. I really do my best to make it a aesthetically and technically amazing SMB3 Fangame.
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