## [SOLVED]Positioning a image in another image(A weap in hand)

General discussion about LÖVE, Lua, game development, puns, and unicorns.
Мэтю
Prole
Posts: 31
Joined: Mon Jan 06, 2014 1:24 pm
Location: Espírito Santo, Brazil
Contact:

### [SOLVED]Positioning a image in another image(A weap in hand)

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
Last edited by Мэтю on Tue Jan 07, 2014 8:54 pm, edited 1 time in total.
World needs love.

bekey
Party member
Posts: 255
Joined: Tue Sep 03, 2013 6:27 pm

### []

-snip-
Last edited by bekey on Fri Jan 24, 2014 1:47 am, edited 3 times in total.

micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

### Re: Positioning a image in another image (A weapon in a hand

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
Prole
Posts: 9
Joined: Tue Jan 07, 2014 6:20 am

### Re: Positioning a image in another image (A weapon in a hand

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

jjmafiae
Party member
Posts: 1331
Joined: Tue Jul 24, 2012 8:22 am

### Re: Positioning a image in another image (A weapon in a hand

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.

Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

### Re: Positioning a image in another image (A weapon in a hand

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.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
li = love.image
lg = love.graphics

Мэтю
Prole
Posts: 31
Joined: Mon Jan 06, 2014 1:24 pm
Location: Espírito Santo, Brazil
Contact:

### Re: Positioning a image in another image (A weapon in a hand

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 )
World needs love.

micha
Inner party member
Posts: 1083
Joined: Wed Sep 26, 2012 5:13 pm

### Re: Positioning a image in another image (A weapon in a hand

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.

Мэтю
Prole
Posts: 31
Joined: Mon Jan 06, 2014 1:24 pm
Location: Espírito Santo, Brazil
Contact:

### Re: Positioning a image in another image (A weapon in a hand

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
World needs love.

Мэтю
Prole
Posts: 31
Joined: Mon Jan 06, 2014 1:24 pm
Location: Espírito Santo, Brazil
Contact:

### Re: Positioning a image in another image (A weapon in a hand

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:
lel.love