• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Attacks and things

So Im working on some kinda undertale fan game... but the fight system was very well, but i cant use this. My box is made from 2 rectangles, one white, one black, bla bla bla...
So I have x1, y1 and x2, y2 and the attacks are objects. And I want to hide the sprite part who is not in the box, and of corse the entyre object if is outside the door
 

jo-thijs

Member
You've got 4 options I can directly think of:
1) Use draw_sprite_part or something like that to only draw the relevant part.
2) Use draw_drimitive_texture with pr_trianglestrip together to do something like draw_sprite_part.
3) Use shaders to discard pixels outside the range.
4) Use surfaces to hold whatever is drawn inside the rectangle, draw everything in the rectangle to the surface, then draw the surface to the screen.

I suggest you either use 3 or 4.

If you use 3, beware that not every device instantly supports it
and if you choose 4, beware that surface might get deleted at any time (when you minimize the game for example).
 
I tried to draw sprite part, but it start drawing me a little part from other sprites... and I dont know how I can handle this, I have no idea
 

jo-thijs

Member
That's possible, if you give invalid values for left, top, width or height.
Can it be you were trying to draw parts of the sprite that don't exist or that you misinterpreted the coordinate system for this function?

Personally, I would just go with surfaces though.
They do cost more memory, but they're really convenient to use here.
 

jo-thijs

Member
Using what method? draw_sprite_part?
Then you would do something like:
Code:
draw_sprite_part(sprite, image, max(0, x1 - x), max(0, y1 - y), min(x + spriteWidth, x2) - max(x, x1), min(y + spriteHeight, y2) - max(y, y1), x, y);
Beware though that draw_sprite_part ignores the origin of your sprite.
 
Using what method? draw_sprite_part?
Then you would do something like:
Code:
draw_sprite_part(sprite, image, max(0, x1 - x), max(0, y1 - y), min(x + spriteWidth, x2) - max(x, x1), min(y + spriteHeight, y2) - max(y, y1), x, y);
Beware though that draw_sprite_part ignores the origin of your sprite.
wow, nice work dude. Im not 100% if I understand that but I will look over the manual, useful :)
 
Yeah, maybe I want too much, but I want to understand what have you done there, the max and min part what represent??? Can you explain? I dont force you, that would be strange... anyways what are these? I know how work min and max but in this context I cant understand how it return values

Edit:I took this logic after some thinking
 
Last edited:
Top