Mirror image of the hero and his animation states in the mirror hanging on the wall (GMS 1.4)

Imiglikos

Member
Hi guys,

I tries to obtain the mirror image of the hero's sprite and possibly the back invisible wall in the mirror that is opposite the mirror
I use this solution, but it does not work well in my platfom game:

- all reflections of the hero's states and his sprite animations are missing. the hero when he comes to the mirror should see himself in the mirror image and every state of the animation. if I take out the weapon, the hero's sprite should appear in the mirror with the weapon drawn. e.t.c.
- mirror should work on the principle of stretching the mirror sprite, e.g. using a bbox and then in the part where I stretch this mirror sprite a mirror image of the sprite is created
- would it be possible to add a wall in this mirror that is on the opposite side of the mirror? it does not exist, but could it be generated with a sprite? that would give a depth effect in the mirror ..


This is how it should be ... this is a 2d platform game and the mirror is behind the protagonist ... when he approaches it, he sees his mirror image and all states of the animation.

mirror reflection.png




I am asking you for any help ... I have no experience with surfaces ...
 
Last edited:

curato

Member
You just need to draw sprites on a lower layer. They would just basically show where you have the mirror cut out. If mirrors are rare you could turn if off/on when close to a mirror.
 

Imiglikos

Member
You just need to draw sprites on a lower layer. They would just basically show where you have the mirror cut out. If mirrors are rare you could turn if off/on when close to a mirror.

how to draw them on the lower layer ??

Obj_mirror

Draw
GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);


// mirror position
_xx = x+32;
_yy = y+32;


// create the mirror
_surf = surface_create(52,18); // mirror size

surface_set_target(_surf);
draw_clear_alpha(c_black,0);
draw_sprite(obj_player.spr_index,1,obj_player.x - _xx, (_yy - obj_player.y) + 64); // draw player inverted
surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror
surface_free(_surf) // clear mirror
 

Imiglikos

Member
How to do it to get a similar effect as in the picture I presented?
is it enough to pick up the hero's sprite layer? what I have to do?
sprite in which the mirror is created has the dimensions of a 32x32 square and I stretch it to any size.
a mirror should be formed in this stretched sprite.
so it should have bbox values then?
It is a platform game and the mirror is behind the player

Thank you
 

curato

Member
The easiest way is the create a reflection instance that copies the movments of the player on that layer you need. You could also do it with a shader.
 

Imiglikos

Member
The easiest way is the create a reflection instance that copies the movments of the player on that layer you need. You could also do it with a shader.
Hmmm....and some example of this solution? with the implementation in this code above?
 

Tyg

Member
It really depends on how realistic you want it and what is to be reflected
a screenshot would help
i have an example of a very complex shader that reflects the the animated objects, and sky using raymarching
and a shader generated camera
there are much simpler tricks, and solutions, if you post a screenshot and let me know what you actually want reflected
look in the mirror, not only do you see yourself but whats behind you
in a very simple shader you would still want some kind of hidden surface behind the user
this would be ok for a 2D side scroller, but for 2.5D you would need to take into account passable objects, say there a pillar on the viewers side
also enemies may need to be refected
so this would require a different solution as well as 3D
then the best solution can be figured out, and the shader could be made to best suit it
i.e. does distance have to be accounted for, are there any environmental effects or other lighting
what is the FOV-field of view required
does scaling need to be involved, you see this level of complexity may not be required
asking for a one shader fits all is very vague
you see you could just reflect the player or what is on the other side like a castle wall
it can be a very simple shader, but you want it to handle itself
i can help, you write one and show you how to implement it but need a more detailed view
of what your trying to achieve :)

Sorry i just saw your artwork..lol, if its just the player then the position of a mirror copy could just be based on the players position
you would just need to figure out the x distance the player is from the mirror
 

Imiglikos

Member
It really depends on how realistic you want it and what is to be reflected
a screenshot would help
i have an example of a very complex shader that reflects the the animated objects, and sky using raymarching
and a shader generated camera
there are much simpler tricks, and solutions, if you post a screenshot and let me know what you actually want reflected
look in the mirror, not only do you see yourself but whats behind you
in a very simple shader you would still want some kind of hidden surface behind the user
this would be ok for a 2D side scroller, but for 2.5D you would need to take into account passable objects, say there a pillar on the viewers side
also enemies may need to be refected
so this would require a different solution as well as 3D
then the best solution can be figured out, and the shader could be made to best suit it
i.e. does distance have to be accounted for, are there any environmental effects or other lighting
what is the FOV-field of view required
does scaling need to be involved, you see this level of complexity may not be required
asking for a one shader fits all is very vague
you see you could just reflect the player or what is on the other side like a castle wall
it can be a very simple shader, but you want it to handle itself
i can help, you write one and show you how to implement it but need a more detailed view
of what your trying to achieve :)

Sorry i just saw your artwork..lol, if its just the player then the position of a mirror copy could just be based on the players position
you would just need to figure out the x distance the player is from the mirror
My game is an ordinary 2D platformer, I just need a shader to reflect the player in the mirror and a part of the non-existent scenery which is, for example, on the opposite side of the mirror.
I mean this effect :) would you be able to help me with it?
i'm using gsm 1.4 thank you:)
 

Tyg

Member
Ok, got ya, ill see what i can whip up
the non existant scenecy, is it distant or like a wall
the reason i am asking is to determine if it needs to scroll

actually i think most effective way would to be to make a small viewcam within the shader looking toward the player
that way everything passing it gets reflected
ill make a mirror object with a shader
 
Last edited:

muki

Member
I just need a shader to reflect the player in the mirror and a part of the non-existent scenery which is, for example, on the opposite side of the mirror.
To be clear, do you really want non-existent scenery to be visible in the mirror?

If so, you will need to get more creative than what a shader and surfaces can do. You'll need to actually make the art that is visible in the reflection.
 

Imiglikos

Member
Ok, got ya, ill see what i can whip up
the non existant scenecy, is it distant or like a wall
the reason i am asking is to determine if it needs to scroll

actually i think most effective way would to be to make a small viewcam within the shader looking toward the player
that way everything passing it gets reflected
ill make a mirror object with a shader
Tyg

a nonexistent scenario is like a wall ..
it doesn't have to be complicated, the most important thing is that the mirror image of the player behaves the same as the player:)
 

Imiglikos

Member
To be clear, do you really want non-existent scenery to be visible in the mirror?

If so, you will need to get more creative than what a shader and surfaces can do. You'll need to actually make the art that is visible in the reflection.

So there may be a problem with a non-existent piece of scenery reflected in the mirror?
and without this reflected piece of scenery it will be easier with the hero only reflected in the mirror? just a shader?
 

muki

Member
So there may be a problem with a non-existent piece of scenery reflected in the mirror?
and without this reflected piece of scenery it will be easier with the hero only reflected in the mirror? just a shader?
It's not a "problem" to have non-existent scenery in a mirror, if the angle makes sense. What I mean is a shader isn't going to draw objects/art in the mirror that you didn't set up already. Which is why you need to get a little creative.

Will the character turn their head towards the mirror at any point? Or will they always be looking forward? This will also determine what you'll need to do.

A shader isn't mandatory either. The look of the reflection you want will determine whether you need one or not. If you just need a clean and flat reflection, then you probably don't need a shader. A shader is useful for creating an "unclean" look to a surface, such as ripples in the reflection, or some kind of distortion. Whether you want that sort of stuff is up to you.

Personally, if all I want is a clean mirror reflection, with no distortion or blur, I wouldn't even use a shader. I'd do something like this.

1. Draw out a sprite of the mirror, which includes stationary objects on the "other side" being reflected. The other wall, lamps, bookshelf, whatever you want.
2. Create an object for the mirror as you would anything else.
3. In the draw event of the mirror, draw itself, but also use draw_sprite_part to draw part of the character you want to reflect, with an offset (character and reflection won't be directly on top of each other) and it'll take a bit of math to make sure the drawn character sprite stays within the mirror, but it absolutely can be done this way.
4. As a bonus, you could even add another draw_sprite for some extra grime and stains on the mirror, after drawing the character.

This is the simplest way to do it. But you won't get any distortion, blur or ripple in the reflection without a shader, if you want those things.


But before all of this, you need to set some rules of what *exactly* you want the mirror to do. Such as, does the character turn to face it or do they just look ahead. Is there parallax shifting of the environment as you walk by. Are there stains/dirt on the mirror. Will the mirror be perfectly leveled or will it be tilted at an angle. Will the reflection be blurry, broken, or distorted in any way.
 

Imiglikos

Member
It's not a "problem" to have non-existent scenery in a mirror, if the angle makes sense. What I mean is a shader isn't going to draw objects/art in the mirror that you didn't set up already. Which is why you need to get a little creative.

Will the character turn their head towards the mirror at any point? Or will they always be looking forward? This will also determine what you'll need to do.

A shader isn't mandatory either. The look of the reflection you want will determine whether you need one or not. If you just need a clean and flat reflection, then you probably don't need a shader. A shader is useful for creating an "unclean" look to a surface, such as ripples in the reflection, or some kind of distortion. Whether you want that sort of stuff is up to you.

Personally, if all I want is a clean mirror reflection, with no distortion or blur, I wouldn't even use a shader. I'd do something like this.

1. Draw out a sprite of the mirror, which includes stationary objects on the "other side" being reflected. The other wall, lamps, bookshelf, whatever you want.
2. Create an object for the mirror as you would anything else.
3. In the draw event of the mirror, draw itself, but also use draw_sprite_part to draw part of the character you want to reflect, with an offset (character and reflection won't be directly on top of each other) and it'll take a bit of math to make sure the drawn character sprite stays within the mirror, but it absolutely can be done this way.
4. As a bonus, you could even add another draw_sprite for some extra grime and stains on the mirror, after drawing the character.

This is the simplest way to do it. But you won't get any distortion, blur or ripple in the reflection without a shader, if you want those things.


But before all of this, you need to set some rules of what *exactly* you want the mirror to do. Such as, does the character turn to face it or do they just look ahead. Is there parallax shifting of the environment as you walk by. Are there stains/dirt on the mirror. Will the mirror be perfectly leveled or will it be tilted at an angle. Will the reflection be blurry, broken, or distorted in any way.

Muki

Ok it does not need a shader..My character should only be reflected in the mirror and if it is possible to reflect the non-existent fragment of the scenery which is on the opposite side.
the mirror is rectangular, perfectly level, not tilted.
The character of the hero looks straight ahead, not in the mirror, and this effect is enough for me
you know, it's a flat dump, after all, it's a 2D platform :)
Paralaxa occurs while the player is walking
I like this bonus to add another draw_sprite to get extra dirt and stains on the mirror after drawing the character
it is important that the sprite of the hero in the mirror behaves appropriately like a hero ... so his every state in the mirror is animated when I make a jump, you can see a jump in the mirror ... when I pull a weapon, you can see the weapon in the mirror etc.

So it is probably enough to use the aplication surface? no shader needed ... because it doesn't I need distortion etc ...

Ok I'm trying to imagine it..I will use an example that someone similar has already designed..but it still requires changes



I added the draw_sprite_part and image_index obj_player functions here to copy the hero's behavior in the mirror and all his animation states


obj_mirror

draw

GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);


// mirror position
_xx = x+32;
_yy = y+32;


// create the mirror
_surf = surface_create(52,18); // mirror size

surface_set_target(_surf);
draw_clear_alpha(c_black,0);
//draw_sprite(obj_player.spr_index,1,obj_player.x - _xx, (_yy - obj_player.y) + 64); // draw player inverted
draw_sprite_part(obj_player.sprite_index, obj_player.image_index, 0, 0, 34, 66, obj_player.x - _xx, (_yy - obj_player.y) +64);

surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror
surface_free(_surf) // clear mirror
it is best if the mirror could be created on the basis of an invisible sprite which I stretch on the board using the bbox function and a mirror is created in this fragment

Ok further I do not know how to properly put it together to get the effect I described
 
Last edited:

Tyg

Member
First ill make one without a shader so you can see your options
it uses a png image with a hole in the middle for the mirror
the sprite is copied with the draw_sprite_part_ext function
so basically when the player is in proximity to the mirror
it activates its draw function when it hits the left edge the left parameter is decreased and when it hits the right edge left is 0 and the width is decreased
another way would be to copy part of the application surface onto the mirror surface

 
Last edited:

Imiglikos

Member
First ill make one without a shader so you can see your options
it uses a png image with a hole in the middle for the mirror
the sprite is copied with the draw_sprite_part_ext function
so basically when the player is in proximity to the mirror
it activates its draw function when it hits the left edge the left parameter is decreased and when it hits the right edge left is 0 and the width is decreased

Thank you Tyg
I don't use gms 2x, but gms 1.4, can you convert it?
 

Imiglikos

Member
First ill make one without a shader so you can see your options
it uses a png image with a hole in the middle for the mirror
the sprite is copied with the draw_sprite_part_ext function
so basically when the player is in proximity to the mirror
it activates its draw function when it hits the left edge the left parameter is decreased and when it hits the right edge left is 0 and the width is decreased
another way would be to copy part of the application surface onto the mirror surface


Could any of you convert it to a version for gms 1.4 because I can't recreate this project because I'm using gms 1.4 and not 2x

Thank you
 

Imiglikos

Member
Can someone tell me to direct me .. what is wrong that the sprite of the hero in the mirror image does not want to turn left?
I tried to add a local variable here which should force the sprite rotation to change in mirror image but unfortunately it did not help ... Right is fine, but when I turn left the mirror sprite does not turn left
and the last thing .. what do I have to set so that the sprite in the mirror image jumps up and not down?

Thank you all


GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);


// mirror position


_xx = x+32;
_yy = y+32;





_surf = surface_create(150,100); // mirror size

var image_xscaleX = 1; // Player mirror direction.

if (hspeed  > 0) {
   image_xscaleX = 1;
} else
if (hspeed  < 0) {
    image_xscaleX = -1;
}




surface_set_target(_surf);
draw_clear_alpha(c_black,0);
draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx, (_yy - obj_player.y) +64, image_xscaleX, 1, image_blend, 0.7);



surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror
surface_free(_surf) // clear mirror
 

muki

Member
in this line :

GML:
draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx, (_yy - obj_player.y) +64, image_xscaleX, 1, image_blend, 0.7);
Try changing image_xscaleX to obj_player.image_xscale.

I'm not sure why you are creating var image_xscaleX. Or setting it based on hspeed. If it's just to flip the reflection, you can ignore all that and just use obj_player.image_xscale for draw_sprite_part_ext. Your code doesn't work anyway, since it looks like you are using the mirror's hspeed, not obj_player's.

Sometimes the best solutions are the ones that use less code! :)
 
Last edited:

Imiglikos

Member
in this line :

GML:
draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx, (_yy - obj_player.y) +64, image_xscaleX, 1, image_blend, 0.7);
Try changing image_xscaleX to obj_player.image_xscale.

I'm not sure why you are creating var image_xscaleX. Or setting it based on hspeed. If it's just to flip the reflection, you can ignore all that and just use obj_player.image_xscale for draw_sprite_part_ext. Your code doesn't work anyway, since it looks like you are using the mirror's hspeed, not obj_player's.

Sometimes the best solutions are the ones that use less code! :)
yea :) I don't need to use a local variable here ... I will test this solution... Thanks for the hint :)
 

Imiglikos

Member
Ok it worked..forgot about it thanks for the hint..the thing is about the hero's jump in the mirror image..is still jumping down..what should i do to fix it??

GML:
draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx, (_yy - obj_player.y) +64, obj_player.image_xscale, obj_player.image_yscale, image_blend, 0.7);
 

Imiglikos

Member
ok I set it up and the hero in the mirror image jump up, not down ...
but I have one question and I can't find the answer anywhere ..
what needs to be done so that the mirror image of the hero also shows the bullet during the hero's shot while he is at the mirror
now I can only see how his sprite changes but he doesn't show the sphere in mirror image ... What's missing in this code?

Thank you


obj_mirror

draw


GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);

// mirror position
_xx = x;
_yy = y;


_surf = surface_create(300,200); // mirror size


surface_set_target(_surf);
draw_clear_alpha(c_black,0);

draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx ,  obj_player.y - _yy - 70 , obj_player.image_xscale, obj_player.image_yscale, image_blend, 0.7);

surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 
There isn't anything special about switching to a surface. Think of it like drawing on paper; every new surface you create is a new sheet that you place on the table. If you draw a detailed park on one piece of paper but then only draw a single tree on the next, you shouldn't be surprised that the second piece of paper only has a tree on it when you put it next to the park. So, now that you have your mirror surface, whatever you want to be in the mirror, you have to draw to it just like you did the player.
 

Imiglikos

Member
There isn't anything special about switching to a surface. Think of it like drawing on paper; every new surface you create is a new sheet that you place on the table. If you draw a detailed park on one piece of paper but then only draw a single tree on the next, you shouldn't be surprised that the second piece of paper only has a tree on it when you put it next to the park. So, now that you have your mirror surface, whatever you want to be in the mirror, you have to draw to it just like you did the player.

Ok ... so I have to use the same draw_sprite_part and draw the projectile I want to be displayed in the mirror?
 
There's no need for draw_sprite_part(). The regular function will do just fine. Use a with statement on the bullet object and then draw the sprite with the same offset as the player.
 

Imiglikos

Member
ok

ok i drew a bullet on the surface ... but i did something wrong because still no bullet is showing on the mirror


obj_mirror

draw


GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);

// mirror position
_xx = x;
_yy = y;


_surf = surface_create(300,200); // mirror size


surface_set_target(_surf);
draw_clear_alpha(c_black,0);

draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx ,  obj_player.y - _yy - 70 , obj_player.image_xscale, obj_player.image_yscale, image_blend, 0.7);

with obj_bullet {


_xx1 = x;
_yy1 = y;



draw_sprite_part_ext(obj_bullet.sprite_index, obj_bullet.image_index, 0, 0, 5, 5, obj_bullet.x - _xx1 ,  obj_bullet.y - _yy1 - 70 , obj_bullet.image_xscale, obj_bullet.image_yscale, image_blend, 0.7);


}

surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 
A with statement changes the scope to the current instance. You don't need those obj_bullet prefixes because it may not reference itself if there's more than one bullet active. What's happening right now is that _xx1 and _yy1 are taking the values from the bullet itself - or the first one created - not the mirror object, so you're essentially drawing all your bullets at 0,0 or at another small offset. Either put those declarations outside of the with statement and prefix them with "var", or use "other." as a prefix to grab the mirror's ID.

Also, if your bullet is a 5x5 sprite (and your player is 80x80), you don't need draw_sprite_part(). That's only if you are intentionally not drawing the whole sprite. I think you may have been a bit confused by an earlier post as they weren't referencing a surface when recommending the function. draw_sprite_part is only needed if you want to cut off the sprite manually and is not necessary for this effect. If you're using a surface, there's no need to use the function. You also don't need to free the surface every frame. Just recreate it if it doesn't exist.
 

Imiglikos

Member
A with statement changes the scope to the current instance. You don't need those obj_bullet prefixes because it may not reference itself if there's more than one bullet active. What's happening right now is that _xx1 and _yy1 are taking the values from the bullet itself - or the first one created - not the mirror object, so you're essentially drawing all your bullets at 0,0 or at another small offset. Either put those declarations outside of the with statement and prefix them with "var", or use "other." as a prefix to grab the mirror's ID.

Also, if your bullet is a 5x5 sprite (and your player is 80x80), you don't need draw_sprite_part(). That's only if you are intentionally not drawing the whole sprite. I think you may have been a bit confused by an earlier post as they weren't referencing a surface when recommending the function. draw_sprite_part is only needed if you want to cut off the sprite manually and is not necessary for this effect. If you're using a surface, there's no need to use the function. You also don't need to free the surface every frame. Just recreate it if it doesn't exist.
well, I changed the functions to draw_sprite_ext, I also added var and I did it after the instructions, but I still do not have a mirror image of the projectile ...


obj_mirror

draw

GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);



// mirror position
_xx = x;
_yy = y;

_surf = surface_create(300,200); // mirror size



surface_set_target(_surf);
draw_clear_alpha(c_black,0);

//draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx ,  obj_player.y - _yy - 70 , obj_player.image_xscale, obj_player.image_yscale, image_blend, 0.7);

draw_sprite_ext(obj_player.sprite_index,obj_player.image_index,obj_player.x - _xx ,obj_player.y - _yy - 70,obj_player.image_xscale,obj_player.image_yscale,0,image_blend,.5)


var _xx1 = x
var _yy1 = y-16

with obj_bullet  {

draw_sprite(spr_bullet, 0, _xx1, _yy1);

}


surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 
You still have to factor in the bullets' coordinates like you did the player. Otherwise, you're drawing every bullet in the same spot.
 

Imiglikos

Member
You still have to factor in the bullets' coordinates like you did the player. Otherwise, you're drawing every bullet in the same spot.

I understand, but I moved the bullet as far as it is from the player. Even so, it does not form on the mirror. I think something else is the reason I don't want to create a bullet on the mirror

Maybe a second surface must be created and then this projectile will be drawn on the mirror? I have really not dealt with surfaces and hence I am asking for advice on what to do ...
I think that even this bullet does not form on the mirror on this surface, because I tried to shoot from anywhere on the mirror and you can't see the bullet anywhere ... if there was a position of 0.0 it would be at the top of the mirror right?
 
I don't understand what you mean by moving it far from the player. You don't need a second surface. You draw everything you want on it the way you would normally, but you have to offset from the surface's coordinates. That's all there is to it. There isn't anything inherently different in drawing to a surface versus regular drawing (which goes onto a surface anyway by default). All the offset stuff is just because the surface isn't drawn at 0,0.
 

Imiglikos

Member
I don't understand what you mean by moving it far from the player. You don't need a second surface. You draw everything you want on it the way you would normally, but you have to offset from the surface's coordinates. That's all there is to it. There isn't anything inherently different in drawing to a surface versus regular drawing (which goes onto a surface anyway by default). All the offset stuff is just because the surface isn't drawn at 0,0.
See ... my bullet has a y-16 offset in the player step event. I really did the same as the hero and yet the bullet does not form on the mirror. It is not visible from any part of the mirror that the bullet is forming on the mirror
if it would form on the mirror coordinates x = 0 and y = 0 then it would be in the top left corner ... well I understand it like with sprites ... but it doesn't ... so I think something is wrong with my code ...
if it was created on the mirror only in a different place, I would have found it and positioned it appropriately
this is what i'm talking about, I can't see him in any part of the mirror here
 

woods

Member
wouldnt it be changed to simply.. ?

with obj_bullet {
draw_sprite(spr_bullet, 0, _xx, _yy);
}
 

Imiglikos

Member
Anyone have any ideas why the sprite of weapons is not drawn on the mirror?

Obj_mirror

Draw

GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);



// mirror position
_xx = x;
_yy = y;

_surf = surface_create(300,200); // mirror size



surface_set_target(_surf);
draw_clear_alpha(c_black,0);

//draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx ,  obj_player.y - _yy - 70 , obj_player.image_xscale, obj_player.image_yscale, image_blend, 0.7);

draw_sprite_ext(obj_player.sprite_index,obj_player.image_index,obj_player.x - _xx ,obj_player.y - _yy - 70,obj_player.image_xscale,obj_player.image_yscale,0,image_blend,.5)


var _xx1 = x
var _yy1 = y-16

with obj_bullet  {

draw_sprite(spr_bullet, 0, _xx1, _yy1);

}


surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 
It's the same issue I pointed out before: you're still drawing all the bullets in the same spot, which also happens to be outside the surface. You're not using the bullets' coordinates at all.
 

woods

Member
i havnt messed with shaders at all yet, so i may be wrong.

what BR is saying here is.... see how you are referencing the player.x and player.y

draw_sprite_part_ext(obj_player.sprite_index, obj_player.image_index, 0, 0, 80, 80, obj_player.x - _xx , obj_player.y - _yy - 70 ,

and you are not referencing the bullet.x and bullet.y below..

draw_sprite(spr_bullet, 0, _xx1, _yy1);

this should be..
Code:
draw_sprite(spr_bullet, 0, spr_bullet.x - _xx1, spr_bullet.y  - _yy1);
//@BattleRifle BR55 for confirmation? ;o)
 

Imiglikos

Member
A few answers earlier I referred to obj_bullet.x and obj_bullet.y but a BattleRifle BR55 suggested that I should not do it because i don't need those obj_bullet prefixes because it may not reference itself if there's more than one bullet active.

that's why I doubted and started to wonder what I was doing wrong ...
rightly here i should use sprite not object. thanks all in all it was enough for me to suggest it

Woods Thanks pal
 
Last edited:

Imiglikos

Member
I still have a question for this post ...
as if I would like to present in the mirror an invisible and non-existent piece of scenery in opposite of the mirror? should I draw it on the same surface as the hero's mirror image?
Someone could explain it to me somehow or show me an example of how I should do it?
based on that code above

Thank you
 

woods

Member
with obj_bullet {
_xx1 = x;
_yy1 = y;



he was referring to the _xx1 / _yy1 being inside the with statement and you should move that out of the with.
it took me a few re-reads to see what was going on

heh is like the first one was half right, and then the second one was the other half right..
what is left..process of elimination, put the two half rights together and found a working solution ;o)


sounds like you got it working đź‘Ť
 
To clarify, I was saying to move the _xx1 and _yy1 variables out of the with loop because those have to belong to the mirror object, but you still have to add x and y to the bullet drawing in order to reference the bullet itself, otherwise you're only using the mirror's coordinates. The player doesn't need anything special because it's just the mirror itself drawing the player sprite, but the with statement is changing the scope to the bullets, as if you're actually writing the code inside the bullet instead of the mirror object, so you have to use x and y directly. Any variable declared with "var" doesn't have a specific object scope as it belongs to the event, so if you store the mirror coordinates in vars, then you can reference them inside the with statement without issue (you could technically forgo them and just use "mirror.x/y" but if you have more than one mirror on the scene, only the first created will be used - or you could just use "other"), but if you set them inside the with statement, they don't get the mirror's x and y, they get the bullets', because the scope is now the bullet. The bullet drawing has to look the same as the player in that they use their own coordinates as well as the offset from the mirror. Your bullets aren't drawing because you're telling them to draw just outside the surface since those variables contain the mirror coordinates without the bullets. woods almost had it, as you were right on your call to not use "obj_bullet."


For your new question, are you asking about drawing something only in the mirror and not in the actual world? If yes, draw it on the surface the exact same way you would the other sprites.
 

Imiglikos

Member
To clarify, I was saying to move the _xx1 and _yy1 variables out of the with loop because those have to belong to the mirror object, but you still have to add x and y to the bullet drawing in order to reference the bullet itself, otherwise you're only using the mirror's coordinates. The player doesn't need anything special because it's just the mirror itself drawing the player sprite, but the with statement is changing the scope to the bullets, as if you're actually writing the code inside the bullet instead of the mirror object, so you have to use x and y directly. Any variable declared with "var" doesn't have a specific object scope as it belongs to the event, so if you store the mirror coordinates in vars, then you can reference them inside the with statement without issue (you could technically forgo them and just use "mirror.x/y" but if you have more than one mirror on the scene, only the first created will be used - or you could just use "other"), but if you set them inside the with statement, they don't get the mirror's x and y, they get the bullets', because the scope is now the bullet. The bullet drawing has to look the same as the player in that they use their own coordinates as well as the offset from the mirror. Your bullets aren't drawing because you're telling them to draw just outside the surface since those variables contain the mirror coordinates without the bullets. woods almost had it, as you were right on your call to not use "obj_bullet."


For your new question, are you asking about drawing something only in the mirror and not in the actual world? If yes, draw it on the surface the exact same way you would the other sprites.

it does not help ... sprite is still not drawn on the mirror ;-(

The bullet sprite in the sprite folder is 4x4 and centered.
now on the mirror surface, when I draw it with any x and y displacement, nowhere on the mirror it creates a sprite of a bullet
I understand that if I do not set any x and y values, it draws behind the mirror fact..but I set these values now..and tested with different values and still no projectile sprite is formed on the mirror


the code looks like this


obj_mirror

draw

GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);






// mirror position


_xx = x;
_yy = y;


_surf = surface_create(300,200); // mirror size






surface_set_target(_surf);
draw_clear_alpha(c_black,0);
draw_sprite_ext(obj_player.sprite_index,obj_player.image_index,obj_player.x - _xx ,obj_player.y - _yy - 70,obj_player.image_xscale,obj_player.image_yscale,0,image_blend,.5)

var _xx1 = x
var _yy1 = y-16

with obj_bullet {






draw_sprite(spr_bullet, 0, spr_bullet.x - _xx1, spr_bullet.y  - _yy1 -70);


  }





surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 
Now you're adding in random things again. Just use x and y by themselves, not spr_bullet which doesn't work the way you think it does. Also, don't subtract 16 from _yy1. If you're doing it because of what you said earlier about some offset in the bullet, you need to change that in the bullets as well. Create the bullets where you need them to be, don't offset their drawing to get around their wrong positions.
 

Imiglikos

Member
Now you're adding in random things again. Just use x and y by themselves, not spr_bullet which doesn't work the way you think it does. Also, don't subtract 16 from _yy1. If you're doing it because of what you said earlier about some offset in the bullet, you need to change that in the bullets as well. Create the bullets where you need them to be, don't offset their drawing to get around their wrong positions.

Hmmmm...
I removed the spr_bullet.x/y and still the bullet sprite is not draw on the mirror ...

GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);






// mirror position


_xx = x;
_yy = y;


_surf = surface_create(300,200); // mirror size






surface_set_target(_surf);
draw_clear_alpha(c_black,0);
draw_sprite_ext(obj_player.sprite_index,obj_player.image_index,obj_player.x - _xx ,obj_player.y - _yy - 70,obj_player.image_xscale,obj_player.image_yscale,0,image_blend,.5)

var _xx1 = x
var _yy1 = y

with obj_bullet {






draw_sprite(spr_bullet, 0, x - _xx1, y  - _yy1 );


  }





surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 

Imiglikos

Member
When i set the surface, this resets the view and the upper left corner is 0.0, so I have to subtract viewa offsets, maybe here's the problem why can't I see the bullet sprite on the mirror?
I don't know how to set it up ... this could be the problem I'm struggling with and I can't see the bullet in the mirror


obj_mirror

draw

GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);






// mirror position


_xx = x;
_yy = y;


_surf = surface_create(300,200); // mirror size






surface_set_target(_surf);
draw_clear_alpha(c_black,0);
draw_sprite_ext(obj_player.sprite_index,obj_player.image_index,obj_player.x - _xx ,obj_player.y - _yy - 70,obj_player.image_xscale,obj_player.image_yscale,0,image_blend,.5)

var _xx1 = x
var _yy1 = y

with obj_bullet {






draw_sprite(spr_bullet, 0, x - _xx1, y  - _yy1 );


  }





surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 

woods

Member
all this is in the obj_mirror draw event..

// mirror position
_xx = x;
_yy = y;

then you draw the player using _xx/_yy and an offset

am curious..
if this works and you can see your player in the mirror... why are you using var _xx1/_yy1 and not simply using the original _xx and _yy?

and why the with obj_bullet? .. you're just drawing sprites ;o)
 

Imiglikos

Member
Thank you for all your help and I am sorry to have tired you with this post for so long


GML:
// draw the mirror sprite
draw_sprite(sprite_index,0,x,y);






// mirror position


_xx = x;
_yy = y;


_surf = surface_create(300,200); // mirror size






surface_set_target(_surf);
draw_clear_alpha(c_black,0);
draw_sprite_ext(obj_player.sprite_index,obj_player.image_index,obj_player.x - _xx ,obj_player.y - _yy - 70,obj_player.image_xscale,obj_player.image_yscale,0,image_blend,.5)

var _xx1 = x
var _yy1 = y


with obj_bullet  {

for (i = 0; i < instance_number(obj_bullet); i += 1) {
    obj= instance_find(obj_bullet, i);
    draw_sprite_ext(spr_bullet,0,obj.x - _xx1+ 32 ,obj.y  - _yy1 - 70,1,1,0,image_blend,.5)
 
}
   }




surface_reset_target();

draw_surface(_surf,_xx,_yy); // draw mirror

surface_free(_surf) // clear mirror
 
Last edited:
Top