Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411709 Posts in 69403 Topics- by 58457 Members - Latest Member: FezzikTheGiant

May 20, 2024, 05:43:49 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)repainting the screen.. or something... idunno,,,
Pages: [1]
Print
Author Topic: repainting the screen.. or something... idunno,,,  (Read 1081 times)
pgil
Guest
« on: March 23, 2010, 04:23:33 PM »

So.... Let's say I have an object called ob_background and another called ob_player. In the code for ob_background I want to take a snapshot of the screen without ob_player on it. But I want to do this without ob_player disappearing from the screen? What would be the best way to do that?

I'm using this code:
Code:
set_automatic_draw(false)
instance_deactivate_object(ob_player)
screen_redraw()
screenshot = background_create_from_screen(0,0,room_width,room_height,false,false,true)
instance_activate_object(ob_player)
That gets the screenshot I want (background without ob_player), but ob_player disappears from the screen for a split-second. I want to get the same screenshot, but without ob_player flashing off the screen. Any ideas?
Logged
Desert Dog
Level 4
****



View Profile
« Reply #1 on: March 23, 2010, 05:06:20 PM »

Try chucking a screen_redraw() at the end of that code. Can't test, but from the top of my head.. why wouldn't it work?
Logged

ChevyRay
Guest
« Reply #2 on: March 23, 2010, 05:46:39 PM »

Yeah it seems to me like just just telling the screen to redraw again at the end of that should get rid of any flickering, no?
Logged
pgil
Guest
« Reply #3 on: March 23, 2010, 05:53:18 PM »

I added another redraw_screen at the end, but that didn't change anything...

SO I lied: there's more going on in my code than what I posted.  After I take the snapshot, I switch rooms, set an alarm that moves the player and the view, then draw the old room, making it scroll out while the new one scrolls in. That all works and looks great, except for the player flickering. Hang on, I'll try and post whatever code I can..

Code:
//User event: When player moves outside room
oldroomX = 0
oldroomY = 0
newX = ob_player.x
newY = ob_player.y

if ob_player.x <= 32 { //left edge
   global.roomX -=1
   oldroomX = 640
   newX = ob_player.x +640
}else
if ob_player.y <= 32 {//top edge
   oldroomY = 480
   global.roomY -=1
   newY = ob_player.y +480
}else
if ob_player.x >= room_width -32  { //right edge
   global.roomX +=1
   oldroomX = -640
   newX = ob_player.x -640
}else
if ob_player.y >= room_height -32 { //bottom edge
   global.roomY +=1
   oldroomY = -480
   newY = ob_player.y -480
}
x=ob_player.x
y=ob_player.y

set_automatic_draw(false)
instance_deactivate_object(ob_player)
screen_redraw()
bg_transition = background_create_from_screen(0,0,room_width,room_height,false,false,true)
instance_activate_object(ob_player)
scrolling = true
next_level = "room_goto(" + "rm_" + string(global.roomX) + "_" + string(global.roomY) + ")";
execute_string(next_level);
//screen_redraw()
alarm[0]=1

Code:
//Alarm 0 event:
view_xview[0]=oldroomX
view_yview[0]=oldroomY
ob_player.x = newX
ob_player.y = newY
screen_redraw()
set_automatic_draw(true)

Code:
//Draw event:
if scrolling = true{
   draw_background(bg_transition,oldroomX,oldroomY)
   if view_xview[0] < 0 view_xview[0] += 32
   if view_yview[0] < 0 view_yview[0] += 32
   if view_xview[0] > 0 view_xview[0] -= 32
   if view_yview[0] > 0 view_yview[0] -= 32
}


EDIT: Solved it! Now I draw the screenshot to a surface instead of to the screen. Took me a while to figure out what order to do everything in, though..

Code:
set_automatic_draw(false)
surf_transition = surface_create(640,480)
instance_deactivate_object(ob_player)
surface_set_target(surf_transition)
screen_redraw()
bg_transition = background_create_from_surface(surf_transition,0,0,640,480,false,false,true)
instance_activate_object(ob_player)
surface_reset_target()
surface_free(surf_transition)
screen_refresh()

 Beer!Hand Thumbs Up Right
« Last Edit: March 23, 2010, 06:26:48 PM by pgil » Logged
Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic