Jump to content


Photo

Surfaces and Views


  • Please log in to reply
3 replies to this topic

#1 Conk

Conk

    GMC Member

  • New Member
  • 142 posts

Posted 21 March 2012 - 09:18 PM

I created a simple lighting system which allowed for many lights as well as dynamic lights to blend together using surfaces and it was all good. I then implemented it into a game I had created and suddenly it wasn't working, everything which was suppose to be drawn at the view had shifted strangely, after some research I figured it was because I had placed all of the surface code in the draw event, apparently something which doesn't work with views...

draw event
Surf = surface_create(400,300)
surface_set_target(Surf)
draw_clear(c_white) ;

if global.light = 1
draw_sprite_ext(cyan_light_s,0,mouse_x,mouse_y,1,1,
0,c_white,image_alpha) 
draw_sprite_ext(cyan_light_s,0,Player_Obj.x,Player_Obj.
y,1,1,0,c_white,image_alpha) 


surface_reset_target()
draw_set_blend_mode(bm_subtract)
draw_surface_ext(Surf,view_xview[0],view_yview[
0],1,1,0,c_white,0.95)
draw_set_blend_mode(bm_normal)

What I'm asking is for someone to enlighten me on where to put things, I've tried putting parts in step event, all in step, with no succession ):

I have asked this in Novice and Intermediate forum but no one could really focus on my problem or seem to offer any help ):

This is really starting to bug me, help is greatly appreciated

EDIT: Forgot I can't post in both advanced and novice with the same question >.> Sorry if this is a problem, little late now though.

Edited by Conk, 21 March 2012 - 09:20 PM.

  • 0

#2 Shoba

Shoba

    GMC Member

  • GMC Member
  • 56 posts

Posted 22 March 2012 - 12:30 PM

Hi there,

lets see. You already stated correctly, that you should not use surfaces in the drawing event (unless you draw said surface). I normally prepare surfaces in the step_end event, since I handle most movement in the step event, and everything should be in place during the step_end event.

surface_create should be in the create_event, since you use the same surface all the time. Another Thing you might consider is, that you use the blend mode bm_subtract, I allays thought, that one is confusing as hell, since it subtracts the colour from the colour below (so your white surface with cyan light creates the illusion of a red light source. If you use graphic programs like Photoshop or Gimp, you should use something like multiply. Then you can create a black surface with a red spot on it to simulate red light. This should works with draw_set_blend_mode_ext(9,6).

Anyway to complete your problem, my solution would look kinda like this:

Create Event:
Surf = surface_create(400,300);

Step End Event:
surface_set_target(Surf)
  draw_clear(c_black);
  draw_set_blend_mode(bm_add);
  if (global.light == 1)
    draw_sprite_ext(cyan_light_s,0,-view_xview[0]+mouse_x,-view_xview[0]+mouse_y,1,1,0,c_white,image_alpha);

  draw_sprite_ext(cyan_light_s,0,-view_xview[0]+Player_Obj.x,-view_yview[0]+Player_Obj.y,1,1,0,c_white,image_alpha);
  draw_set_blend_mode(bm_normal);
surface_reset_target();

draw event:
draw_set_blend_mode_ext(9,6);
draw_surface_ext(Surf,view_xview[0],view_yview[0],1,1,0,c_white,0.95);
draw_set_blend_mode(bm_normal);

  • 0

#3 Conk

Conk

    GMC Member

  • New Member
  • 142 posts

Posted 23 March 2012 - 06:54 PM

Yes, that has fixed it :P Thank you (:

my cyan light did use a red sphere :P I have experimented with this before and realised I'd need to use the inverse. I don't understand this bit though

draw_set_blend_mode_ext(9,6);

what's 9,6?
  • 0

#4 brac37

brac37

    GMC Member

  • GMC Member
  • 765 posts
  • Version:GM7

Posted 23 March 2012 - 07:47 PM

(bm_dest_color, bm_inv_src_alpha)

You can compute all bm_ values for extended blend modes in debug mode.

bm_zero = 1
bm_one = 2
bm_src_color = 3
bm_inv_src_color = 4
bm_src_alpha = 5
bm_inv_src_alpha = 6
bm_dest_alpha = 7
bm_inv_dest_alpha = 8
bm_dest_color = 9
bm_inv_dest_color = 10
bm_src_alpha_sat = 11
  • 0




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users