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

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
Мэтю
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)

Post by Мэтю » Mon Jan 06, 2014 11:24 pm

I want to make a very simple TDS (TOP-DOWN SHOOTER), and I want to position a weapon in the hand of player:
Image
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 :P)

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

[]

Post by bekey » Tue Jan 07, 2014 2:27 am

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

User avatar
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

Post by micha » Tue Jan 07, 2014 6:35 am

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.

User avatar
richardperkins
Prole
Posts: 9
Joined: Tue Jan 07, 2014 6:20 am

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

Post by richardperkins » Tue Jan 07, 2014 6:55 am

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

Post by jjmafiae » Tue Jan 07, 2014 2:01 pm

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.

User avatar
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

Post by Nixola » Tue Jan 07, 2014 2:57 pm

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
lt = love.thread
li = love.image
lg = love.graphics

User avatar
Мэтю
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

Post by Мэтю » Tue Jan 07, 2014 3:04 pm

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 :huh:

(Imagine the black line in the hand of the player is a weapon :rofl: )
World needs love.

User avatar
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

Post by micha » Tue Jan 07, 2014 3:59 pm

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.

User avatar
Мэтю
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

Post by Мэтю » Tue Jan 07, 2014 4:21 pm

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 :D

New file not broken (i think)
lel.love
(2.43 KiB) Downloaded 163 times
World needs love.

User avatar
Мэтю
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

Post by Мэтю » Tue Jan 07, 2014 8:52 pm

Weapon position,player rotation and shooting solved, i'll put [SOLVED] on this post :ultrahappy:

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 :crazy:

If u want to see what i did, download the .love file and unpack, all the code are in main.lua :nyu:

EDIT:

Now stamina number don't show double or float numbers :ultraglee: . Thanks to Doctory :ultraglee:

The result:
lel.love
(4 KiB) Downloaded 168 times
Last edited by Мэтю on Mon Jan 20, 2014 12:50 am, edited 2 times in total.
World needs love.

Post Reply

Who is online

Users browsing this forum: No registered users and 34 guests