Hiya! So, I’m making a game using LOVE called TerraCraft. For those not in the know, TerraCraft is a 2D Platformer Robinsonade Sandbox. It’s similar to Terraria and minecraft, but with some distinct differences. One of the main points of the game (which came up during development) was to make this a grid based game (Sort of like Pokémon Mystery Dungeon). I’ve just started it recently (about three or four days ago) and I’ve finally met my maker. I just can’t seem to get this to work now.
So, getting to the point, I can’t seem to apply physics to my player. The player keeps disappearing every time I try to test out the game. The line that’s giving me headaches is line 81. Maybe it’s because I can’t have “ objects.player.body:getX(), objects.player.body:getY()” in “animation:draw” . I’m not quite sure though since I’m not familiar with what goes inside anim8.
Could ya guys lend me a hand? I know you guys probably have better things to do, but I’ve made it my goal to finish this game and I’ll do my darnest to try and finish it. So, with that said, I hope you guys have a nice day and thanks in advance.
- Stacy
Player disappears when I add physics
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Player disappears when I add physics
Welcome!
Could you upload your game? That would help us a lot, because now we don't know what line 81 is.
What could be the case anyhow is that the player is somehow getting "launched" because of some bug in your physics system. Unfortunately, we can't tell unless you upload your game (complete with images and whatever else is needed to run it, see the wiki for how to do that.)
Could you upload your game? That would help us a lot, because now we don't know what line 81 is.
What could be the case anyhow is that the player is somehow getting "launched" because of some bug in your physics system. Unfortunately, we can't tell unless you upload your game (complete with images and whatever else is needed to run it, see the wiki for how to do that.)
Help us help you: attach a .love.
Re: Player disappears when I add physics
Yes, of course. I'm so sorry about that. While I was writing up the stuff, I nearly forgotten the most important things and I couldn't put it back in there after I posted (the post was being approved). I'm still having trouble getting my files into LOVE files. However when I do get them, I must apologize for all the unused stuff in there. I've put them there before I started to work on them.
Final Edit: Nevermind guys! I got the file in there. Turns out there was just too much stuff.
(I'll have to remember that next time I try and upload here)
Final Edit: Nevermind guys! I got the file in there. Turns out there was just too much stuff.
(I'll have to remember that next time I try and upload here)
- Attachments
-
- TerraCraft.love
- (9.89 MiB) Downloaded 213 times
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Re: Player disappears when I add physics
It seems that you are not putting in the correct arguments.
From: https://github.com/kikito/anim8
Animation:draw(image, x,y, angle, sx, sy, ox, oy)
Line 81:
animation:draw(player_sprite, player.act_x, player.act_y, objects.player.body:getX(), objects.player.body:getY())
You seem to be missing the angle argument. Also, getX and getY returns the x,y coordinates of your body, I don't see what that has to do with the scale factors sx and sy.
From: https://github.com/kikito/anim8
Animation:draw(image, x,y, angle, sx, sy, ox, oy)
Line 81:
animation:draw(player_sprite, player.act_x, player.act_y, objects.player.body:getX(), objects.player.body:getY())
You seem to be missing the angle argument. Also, getX and getY returns the x,y coordinates of your body, I don't see what that has to do with the scale factors sx and sy.
Re: Player disappears when I add physics
I didn't seem to need an angle argument, and in his/her example, it sure doesn't look like she used it. Also, the getX and getY doesn't have anything to do with scale factor, it has to do with physics (The body being the player, which is represented by an animation). I was trying to recreate the same effects on a ball in https://love2d.org/wiki/Tutorial:Physicsdreadkillz wrote:It seems that you are not putting in the correct arguments.
From: https://github.com/kikito/anim8
Animation:draw(image, x,y, angle, sx, sy, ox, oy)
Line 81:
animation:draw(player_sprite, player.act_x, player.act_y, objects.player.body:getX(), objects.player.body:getY())
You seem to be missing the angle argument. Also, getX and getY returns the x,y coordinates of your body, I don't see what that has to do with the scale factors sx and sy.
Otherwise, the sprite would just be floating in the air.
- Robin
- The Omniscient
- Posts: 6506
- Joined: Fri Feb 20, 2009 4:29 pm
- Location: The Netherlands
- Contact:
Re: Player disappears when I add physics
Ah, now we're getting somewhere.
- Small detail, but the .love file is packaged incorrectly. It needs to contain the files directly, not the directory that contains the files.
- The "player object" that the player controls and the "player object" for the physics are separate. That doesn't work. In love.keypressed, influence the Body instead, using Body:applyLinearImpulse.
- dreadkillz is right, mostly.
The way you call it, in Animation:draw:- image = player_sprite
- x = player.act_x
- y = player.act_y
- angle = objects.player.body:getX()
- sx = objects.player.body:getY()
- sy = ox = oy = nil
to get something that follows the physical body of the player.Code: Select all
animation:draw(player_sprite, objects.player.body:getX(), objects.player.body:getY())
Help us help you: attach a .love.
- dreadkillz
- Party member
- Posts: 223
- Joined: Sun Mar 04, 2012 2:04 pm
- Location: USA
Re: Player disappears when I add physics
I think you misunderstand me. You aren't putting in the correct arguments for your Anim8 draw function, which is why your player is not showing up.
It should be (draw your player sprite where your player body is):
animation:draw(player_sprite, objects.player.body:getX(), objects.player.body:getY())
Also in your keypressed callback, you should update the position of your physical body so your sprite moves:
It should be (draw your player sprite where your player body is):
animation:draw(player_sprite, objects.player.body:getX(), objects.player.body:getY())
Also in your keypressed callback, you should update the position of your physical body so your sprite moves:
Code: Select all
function love.keypressed(key)
--Assigns the left key with animation and motion
if key == "left" then
player.grid_x = player.grid_x - 16 --Motion
animation = anim8.newAnimation('loop', g('1-2,2'), 0.6) -- Animation
objects.player.body:setX(player.grid_x)
-- Same as above, except for the right key
elseif key == "right" then
player.grid_x = player.grid_x + 16
animation = anim8.newAnimation('loop', g('1-2,1'), 0.6)
objects.player.body:setX(player.grid_x)
end
end
Re: Player disappears when I add physics
Ok! I'll give that a try! If it doesn't work, I'll come back!
Thanks for your help,
Stacy
Edit: @dreadkillz I know. Robin corrected you (I think). Thanks anyway!
Thanks for your help,
Stacy
Edit: @dreadkillz I know. Robin corrected you (I think). Thanks anyway!
Last edited by MalNeige on Wed Jul 18, 2012 2:18 pm, edited 1 time in total.
Re: Player disappears when I add physics
For me the file in attachment was incorrectly packaged. The easiest way to do it:MalNeige wrote:I'm still having trouble getting my files into LOVE files.
Final Edit: Nevermind guys! I got the file in there.
Enter the folder you have your project files (where main.lua, image, sound and other lua files and folders are), select all, right click and zip/compress those files. Rename "name_of_zipped_archive.zip" to "whatever_name_you_want.love". That's all, ready to play and upload.
(Remember to zip and not rar or 7zip.)
Also path and filenames are case-sensitive. You are calling "image/player/..." files but your folder is named Player.
Re: Player disappears when I add physics
Oh thank you! I was wondering why it was acting a bit odd. I didn't notice if was player with a capital P.coffee wrote:For me the file in attachment was incorrectly packaged. The easiest way to do it:MalNeige wrote:I'm still having trouble getting my files into LOVE files.
Final Edit: Nevermind guys! I got the file in there.
Enter the folder you have your project files (where main.lua, image, sound and other lua files and folders are), select all, right click and zip/compress those files. Rename "name_of_zipped_archive.zip" to "whatever_name_you_want.love". That's all, ready to play and upload.
(Remember to zip and not rar or 7zip.)
Also path and filenames are case-sensitive. You are calling "image/player/..." files but your folder is named Player.
Also, I was aware that the .love wasn't packaged correctly. I was in a rush to try and get it on here.
Who is online
Users browsing this forum: No registered users and 7 guests