Page 1 of 2
[SOLVED]Positioning a image in another image(A weap in hand)
Posted: Mon Jan 06, 2014 11:24 pm
by Мэтю
I want to make a very simple TDS (TOP-DOWN SHOOTER), and I want to position a weapon in the hand of player:
The
green cross Is the point(cross!!) where the player will rotate (I arealdy solved this xDDD)
The
red rectangle is where I want to position the weapon
I think if I discover how to position the weapon I can position the shoot point in the weapon( I think ...)
Wow, it's very simple, or no (i don't know how to do this
)
Anyone help is welcome !!!
Srry bad english, I'm brazilian xDD
[]
Posted: Tue Jan 07, 2014 2:27 am
by bekey
-snip-
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 6:35 am
by micha
You can draw the weapon on an image of the same size as the player (which would be mostly transparent) and set the origin coordinates to the same coordinates. If you keep the angle of both images the same, then the weapon will be perfectly aligned with the hand of the player.
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 6:55 am
by richardperkins
As micha said, create an image the same size as the player (or bigger if you want the gun to extend past the bounds of the player image).
All you need to do then is draw it the same exact way you draw your player. No unnecessary math involved
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 2:01 pm
by jjmafiae
Also remember to add the gun's draw code under the player drawing
Code: Select all
love.graphics.draw(playerimg,0,0)
love.graphics.draw(gunimg,0,0)
or the gun thingy will be under the player image
P.S: don't use "!" all the time.
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 2:57 pm
by Nixola
bekey wrote:Trigonometry xDDD
This is the only valid suggestion, though, if you need to know the actual gun position so that you can spawn bullets there.
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 3:04 pm
by Мэтю
micha wrote:You can draw the weapon on an image of the same size as the player (which would be mostly transparent) and set the origin coordinates to the same coordinates. If you keep the angle of both images the same, then the weapon will be perfectly aligned with the hand of the player.
richardperkins wrote:As micha said, create an image the same size as the player (or bigger if you want the gun to extend past the bounds of the player image).
All you need to do then is draw it the same exact way you draw your player. No unnecessary math involved
Yeah, it's a nice solution
jjmafiae wrote:P.S: don't use "!" all the time.
Obeyied
Now i get this :
http://schineider.hostei.com/lel.love
The bullets are spawning in incorret position
(Imagine the black line in the hand of the player is a weapon )
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 3:59 pm
by micha
Solution 1: Trigonometry (if you want to do this, please tell us and we can give you some code or formulas)
Solution 2: Change the image of the player, such that he is holding the bullet centered. From what I know, this is also more realistic, since the player would aim by looking over the iron sights on top of the weapon. Then you could spawn bullets in the center of the player.
Your .love file seems to be broken. At least I cannot unpack it.
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 4:21 pm
by Мэтю
micha wrote:Solution 1: Trigonometry (if you want to do this, please tell us and we can give you some code or formulas)
Solution 2: Change the image of the player, such that he is holding the bullet centered. From what I know, this is also more realistic, since the player would aim by looking over the iron sights on top of the weapon. Then you could spawn bullets in the center of the player.
Your .love file seems to be broken. At least I cannot unpack it.
The second solution is nice, im going to try now, but if you can tell me some formulas or codes about trigonometry would be nice
New file not broken (i think)
- lel.love
- (2.43 KiB) Downloaded 307 times
Re: Positioning a image in another image (A weapon in a hand
Posted: Tue Jan 07, 2014 8:52 pm
by Мэтю
Weapon position,player rotation and shooting solved, i'll put [SOLVED] on this post
I created a simple stamina system, a simple bar of stamina and a zombie that follow the player.
Now i gonna create a system that if zombie collide with player, he takes damage, and with time, new features, each by your time xDD
I'm too excited with love engine
If u want to see what i did, download the .love file and unpack, all the code are in main.lua
EDIT:
Now stamina number don't show double or float numbers
. Thanks to Doctory
The result: