Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length

 
Advanced search

1075913 Posts in 44152 Topics- by 36120 Members - Latest Member: Royalhandstudios

December 29, 2014, 02:37:08 PM
TIGSource ForumsDeveloperTechnical (Moderators: Glaiel-Gamer, ThemsAllTook)Framing a view with a sprite in game maker
Pages: [1]
Print
Author Topic: Framing a view with a sprite in game maker  (Read 1495 times)
moonmagic
Level 4
****



View Profile WWW Email
« on: July 16, 2009, 09:31:46 PM »

I don't know if this is even possible, but here's what I want to do:

I want to use a sprite as a "frame" for a view, so that I can have a scrolling background inside of a largely transparent sprite.

So, I have a room set up with two views. The first view is the playing field, and the second view will be inside of (or underneath) a sprite; I need it to match the outline of the sprite so that the sprite is effectively a portal or a window you can look through to the other view.

Is this possible?
Logged

|
xerus
Vice President of Marketing, Romeo Pie Software
Level 10
*


kpulv

Storm+X+MH
View Profile WWW
« Reply #1 on: July 16, 2009, 10:00:15 PM »

I feel like surfaces might be something you'd be interested in, rather than using multiple views.
Logged

moonmagic
Level 4
****



View Profile WWW Email
« Reply #2 on: July 16, 2009, 10:04:49 PM »

Makes sense. I'll look up some tutorials.

I'm still new to Game Maker (any kind of programming or scripting, actually), so sometimes I take the long way around.
Logged

|
xerus
Vice President of Marketing, Romeo Pie Software
Level 10
*


kpulv

Storm+X+MH
View Profile WWW
« Reply #3 on: July 17, 2009, 12:16:26 AM »

I'm not really understanding your post entirely, but it sounds like if you created a surface the size of your frame, and then took the objects that you want to show through to this frame, and drew them to this surface instead of the screen, it might work.  Then you draw the surface itself to the screen on top of this frame after drawing everything else you want to just show normally.  If you're new to game maker *and* programming, it might be a little tough.

I confused myself writing that.
Logged

moonmagic
Level 4
****



View Profile WWW Email
« Reply #4 on: July 17, 2009, 12:58:58 AM »

I think that what I want to happen isn't going to happen without some texture mapping of some sort, and I don't think I want to tackle that yet. I have a sprite - a brachiosaurus - and I wanted it to have a field of stars moving around inside of it in response to keyboard input (like the Hooded Man in Twin Peaks).

I thought that if there was a way to make a surface that was a "cut-out" of the sprite, it would be easy, but I'm not finding a simple way of making a surface from a sprite.
Logged

|
Kadoba
Level 3
***


Casey_Baxter@Hotmail.com
View Profile
« Reply #5 on: July 17, 2009, 06:45:33 AM »

A surface is always square. You can't make a brachiosaurus shaped surface. You can however, make use of the draw_clear() function.

draw_clear(color) will replace all of the indicated color with full alpha transparency. What you need to do is make a different sprite that's the same dimensions as your surface except one pixel longer vertically, but fill all of the space you want transparent with a specific color. Like Pixel 25(255,92,160). The reason you want it one pixel longer is because game maker reads the bottom left corner as the transparent color for your sprite, but you want that pixel to be pink so you cheat by making the sprite longer.

Stick this in your drawing event and replace the resource names accordingly:
Code:
surface_set_target(surface);          // Set drawing to surface
draw_sprite(spBrachio,0,0,0);             // Draw sprite
draw_set_alpha(100);                      // Change drawing alpha so stars are transparent.
                    // Draw Stars Here
draw_set_alpha(255);              // Reset alpha to normal
draw_sprite(spBrachioPinkpart);           // Draw the pink part over the surface.
draw_clear(make_color_rgb(255,92,160));   // Erase the pink part from the surface
surface_reset_target();           // Reset surface to screen
draw_surface(surface,x,y);   // Draw the resulting surface

In case you're having trouble visualizing that. here's some pictures!

First we set the drawing surface and draw the original brachio sprite to it.


Next we set the alpha transparency and draw the stars.


Here's the other sprite I was talking about to fill with the pink color:

Ok. now see the green line at the bottom? That's the extra I was talking about. When you add it Game Maker will read that and know that color green is the transparent color for the sprite.

So when you write that over the sprite from before you get this:


Now we use the draw_clear(make_color_rgb(255,92,160)) function to erase the pink part and that leaves us with this (pretend the white part is transparent):


And then you reset the drawing surface to the screen and draw the resulting surface where you like!

Ok so I'm at work and I can't test this but it's the theory I wanted to get across. If you have any questions let me know.

Logged
moonmagic
Level 4
****



View Profile WWW Email
« Reply #6 on: July 17, 2009, 11:11:16 AM »

Thanks very much. I'll give that a go and see what happens.

--edit--

Ok, everything seems to be working as expected except for the draw_clear() function. As far as I can tell, draw_clear simply clears the entire surface to the color specified. I tried using draw_clear_alpha(), and got similar results: a rectangle with nothing behind it.



I took the clear function out, and the two sprites are performing as expected, just with a huge green rectangle around the top sprite. So now I am just looking for a way to erase the green rectangle.

Code:
surface_set_target(surface);
draw_sprite(barbery_wilkins,0,0,0);
draw_set_alpha(0)
draw_background_tiled(stars,0,0);
draw_set_alpha(1);
draw_sprite(barbery_wilkins_alpha,0,0,0);
draw_clear(make_color_rgb(0,255,0));
surface_reset_target();
draw_surface(surface,96,100);
« Last Edit: July 17, 2009, 12:06:24 PM by moonmagic » Logged

|
Kadoba
Level 3
***


Casey_Baxter@Hotmail.com
View Profile
« Reply #7 on: July 17, 2009, 04:31:06 PM »

Yeah you're right. I was mistaken about the draw_clear() function. Ok, new approach.

Actually my first guess was to use the draw_set_blend_mode_ext() function but I didn't fully understand how it worked and it requires the pro edition. But I've figured out how to at least make it do what we want. And it's probably a lot faster performance wise too.

You want to draw the stars first and then set the blend mode, then draw the sprite, and then reset the blend mode to normal.

Code:
surface_set_target(surface);
draw_background_tiled(stars,0,0);
draw_set_blend_mode_ext(bm_inv_src_alpha, bm_src_alpha);
draw_sprite(barbery_wilkins,0,0,0);
draw_set_blend_mode(bm_normal);
surface_reset_target();
draw_surface(surface,96,100);

Much easier to implement. Since there are lots of different blending combinations I made a little blend testing app to try and figure out the right pair.

You can download it here.

You can do lots of other cool stuff with the blend modes too.


Logged
Hima
Level 4
****


OM NOM NOM


View Profile WWW Email
« Reply #8 on: July 19, 2009, 08:48:00 AM »

Awesome!  I've never known that you can do something like this in GM! Coincidentally, what I wanted to do can be done using this method. Thank you thank you  :D
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic