Page 1 of 1
Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 1:49 pm
by WolfosoBastardo
Alright so(I started using LÖVE a few days ago, I've been scripting Lua on Garry's Mod for 2-3 years), there are three little problems I'm having:
1°Weird Alpha
As you can see
Even though I'm setting color with this
Code: Select all
love.graphics.setColor( 226, 65, 65, 255 )
, alpha still doesn't appear to be 255. What am I doing wrong?
2° Layers.
Same image as above, you can see, the tank's barrel is above its base, which isn't suppose to happen. I tried to put the piece of code where I both load and draw the image above or below the base load / draw code, but nothing happened.
3° love.audio.play()
Whenever the tank shoots, it is supposed to play a sound, but it only works sometimes...
4° How do I rotate an image so that it always follows the mouse position? My brother suggested using sine and cosine but I couldn't seem to find the right operation on the wiki.
Thanks for anything helpful you are going to post!
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 2:28 pm
by Robin
I'm not sure what exactly is going on here, but here are a few things I noticed:
- You uploaded a .zip with a .love in it. It is preferred to upload the .love directly to the forums.
- The color problems you have might be due to the colormode or the blendmode, I'm not sure. Try experimenting with them.
- Please don't put code that is not directly related to drawing things in love.draw. That's where love.update is for.
- To point something to something else, you need math.atan2. Specifically:
Code: Select all
rotation = math.atan2(drawy - mousey, mousex - drawx)
Replace "rotation", "drawx", "drawy", "mousex" and "mousey" with the appropriate variables.
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 2:31 pm
by vrld
- You set the blend mode to additive.
- Additive blending...
- It's a bug in love.audio. Until this get's fixed, use .ogg files.
- You can get the angle you need the image to rotate to point to the mouse using math.atan2:
Code: Select all
-- anchorx and anchor y are the points you want rotate the sprite around
local mx, my = love.mouse.getPosition()
local angle = math.atan2(mx - anchorx, my - anchory)
As for your code:
- You do a lot of stuff in love.draw() that should be done in love.update(dt) instead. Things like fullscreen toggling and position updates have nothing to do with drawing.
- Because of that, your code is depends on the framerate. That's not a good thing (use dt).
- Events that should get triggered only once when a key (fullscreen toggling) or mouse button (shooting) is pressed are better moved to love.keypressed and love.mousepressed.
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 2:48 pm
by WolfosoBastardo
Robin wrote:
- You uploaded a .zip with a .love in it. It is preferred to upload the .love directly to the forums.
- The color problems you have might be due to the colormode or the blendmode, I'm not sure. Try experimenting with them.
- Please don't put code that is not directly related to drawing things in love.draw. That's where love.update is for.
- To point something to something else, you need math.atan2. Specifically:
Code: Select all
rotation = math.atan2(drawy - mousey, mousex - drawx)
Alright I will do that next time.
Also thanks! I'll try that now.
vrld wrote:
- You set the blend mode to additive.
- Additive blending...
- It's a bug in love.audio. Until this get's fixed, use .ogg files.
- You can get the angle you need the image to rotate to point to the mouse using math.atan2:
Code: Select all
-- anchorx and anchor y are the points you want rotate the sprite around
local mx, my = love.mouse.getPosition()
local angle = math.atan2(mx - anchorx, my - anchory)
Alright I'll use .ogg file, thanks!
vrld wrote:
As for your code:
- You do a lot of stuff in love.draw() that should be done in love.update(dt) instead. Things like fullscreen toggling and position updates have nothing to do with drawing.
- Because of that, your code is depends on the framerate. That's not a good thing (use dt).
- Events that should get triggered only once when a key (fullscreen toggling) or mouse button (shooting) is pressed are better moved to love.keypressed and love.mousepressed.
Interesting, thanks, I'm going to do it now.
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 3:00 pm
by Boolsheet
vrld wrote:- It's a bug in love.audio. Until this get's fixed, use .ogg files.
I don't think you can call it a bug.
An already playing source does not rewind itself if you pass it to love.audio.play(). You either have to stop the source first or create a few sources and play them in sequence so they overlap. There was talk about changing the behavior of play.
(The love.audio.rewind function seems broken. Is that just me? Edit: Ah, not broken. There is something strange going on though)
The wave decoder that LÖVE uses pads wav files to 5 seconds for some reason. This is probably not a bug, but a design decision by the developer of the library. So yeah, avoid wav for now.
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 3:21 pm
by WolfosoBastardo
Alright just did everything suggested and everything works fine, except for love.keyboardpressed that of course only works when a key is pressed, not down; so in which function can I put the love.keyboard.isDown()?
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 3:25 pm
by Robin
WolfosoBastardo wrote:Alright just did everything suggested and everything works fine, except for love.keyboardpressed that of course only works when a key is pressed, not down; so in which function can I put the love.keyboard.isDown()?
That goes into love.update. But I don't think you'll want to use that for toggling fullscreen, because holding the "f" key gets really annoying then.
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 3:34 pm
by WolfosoBastardo
Robin wrote:WolfosoBastardo wrote:Alright just did everything suggested and everything works fine, except for love.keypressed that of course only works when a key is pressed, not down; so in which function can I put the love.keyboard.isDown()?
That goes into love.update. But I don't think you'll want to use that for toggling fullscreen, because holding the "f" key gets really annoying then.
I did use love.keypressed for fullscreen toggling and put everything else (that requires key down) in love.update of course
(just mis-typed keypressed into keyboardpressed but I did use keypressed)
Re: Weird Alpha, Layers, Sound and Rotate image to mouse pos
Posted: Wed Jul 06, 2011 3:37 pm
by vrld
It's
love.keypressed, not love.key
boardpressed.