How to use eraser in corona? - coronasdk

In my application i draw the line and circle.how to erase the line.Using touch function to erase the line and circle.

You want to remove objects on touch?
local function onTouch(event)
local object = event.target
object:removeSelf()
return true
end
object:addEventListener("touch",onTouch)

object:removeSelf() will surely help you

Try to place some objects with same color as that of your background.

Related

How can I change the icon of a marker in an OpenStreetMap widget?

Good afternoon! I need to change the icon of a marker in the map here with some JS code, but I don't know how can I achieve that using the images array.
I tried this but it doesn't work. Any help will be appreciated!
The problem was that I wasn't declaring the size of the image. Here is the code that worked for me.
var res = {size: 40};
res.url = images[1];
return res;

Trying to Reset Game in Lua

Very new to game development and Lua in general here. I'm making a platformer, and I want to be able to restart the game once a character collides with a certain object, and show a title before that. I also want to reset the character's position back to 0,0 once that happens, but I don't know how.
I made a global variable called WIN that's set to true if the character collides with the object, which works, but then going into my love.draw() function, I have this:
function love.draw()
-- begin virtual resolution drawing
push:apply('start')
-- clear screen using Mario background blue
love.graphics.clear(108/255, 140/255, 255/255, 255/255)
-- renders our map object onto the screen
love.graphics.translate(math.floor(-map.camX + 0.5), math.floor(-map.camY + 0.5))
map:render()
if WIN == true then
love.graphics.printf('NEXT LEVEL', 0, 30, VIRTUAL_WIDTH, 'center')
love.graphics.printf('Continue to Next Level', 0, 45, VIRTUAL_WIDTH, 'center')
love.load()
end
-- end virtual resolution
push:apply('end')
end
When I actually collide with the object, I get the following error:
Error
push.lua:48: love.window.setMode cannot be called while a Canvas is active in love.graphics.
Traceback
[C]: in function 'windowUpdateMode'
push.lua:48: in function 'setupScreen'
main.lua:43: in function 'load'
main.lua:116: in function 'draw'
[C]: in function 'xpcall'
The error lines are in my love.load() function, which is as follows:
function love.load()
-- sets up a different, better-looking retro font as our default
love.graphics.setFont(love.graphics.newFont('fonts/font.ttf', 8))
-- sets up virtual screen resolution for an authentic retro feel
push:setupScreen(VIRTUAL_WIDTH, VIRTUAL_HEIGHT, WINDOW_WIDTH, WINDOW_HEIGHT, {
fullscreen = false,
resizable = true
})
love.window.setTitle('Super Mario 50')
love.keyboard.keysPressed = {}
love.keyboard.keysReleased = {}
end
I'm guessing the issue is that I can't set up screen again after already doing that once, but I don't know how to fix this and create a fresh start. Any help is appreciated!
love.load() runs once. That one time is when your game starts up. Don't call love.load() (or love.update()) within love.draw() or vice versa. The Love2D game engine calls these functions, so you don't call them.
Update the start position within love.update() not love.draw(). love.draw() is only for drawing stuff. I believe it would be the View in a model-view-controller architecture.
To restart the position of your object, you would have to do something like
if WIN == true then
push.x = push.start.x
push.y = push.start.y
map.camX = map.start.camX
map.camY = map.start.camY
end
Or something along those lines, it's hard to know without seeing your variables. Your love.draw() will then draw the things at the coordinates that they are at.
To reset/restart the Game without reloading the executable use:
love.event.quit('restart')
But before doing this make a dark screen before with red dropping letters: GAME OVER

Corona SDK - How can i change color text with transition?

Can i change color of text field with transition?
I try with normal transition like this but did not work.
explainer = display.newText("my text", 100,100,"Hiragino Maru Gothic Pro",30)
transition.to(explainer, { time=100, color="rgba(255,0,0)" })
You really can't do this with transition.to. You would have to do it in an enterFrame listener and increment your R, G, B values during each step.
Here's a code that let's you make a blink effect. You can remove the part that changes the increment and it will work for you:
local min_r,min_g,min_b=100,100,255 -- Initial color
local max_r,max_g,max_b=255,255,255 -- End color
local color_steps=15 -- Adjust this to make it more fast/slow
local current_step=0
local increment=1
local step_r=(max_r-min_r)/color_steps
local step_g=(max_g-min_g)/color_steps
local step_b=(max_b-min_b)/color_steps
function blink()
if (rowPlayerName and rowPlayerName["text"] and rowScore and rowScore["text"]) then
rowPlayerName:setTextColor( min_r+current_step*step_r, min_g+current_step*step_g, min_b+current_step*step_b )
rowScore:setTextColor(min_r+current_step*step_r, min_g+current_step*step_g, min_b+current_step*step_b )
current_step=current_step+increment
if (current_step>=color_steps) then
current_step=color_steps-1
increment=-increment
elseif (current_step<0) then
current_step=0
increment=-increment
end
timer.performWithDelay(50, blink)
end
end
blink()
In this case, rowPlayerName and rowScore are 2 display.newText that need to be changed together.
What you could also do, is just put another object over it with different color and set its alpha to 0. Then using transition.to method change this objects alpha property to 1.

corona drag and drop an object on container or reference

I am developing a game and one level is solving a jumbled up word. The letters are images like tiles and I am trying to either click a letter and this will move to the first of the allocated spots to solve the word or to actually drag the tile to the spot. Can anyone help me implement this?
To drag an object see this tutorial:
http://www.coronalabs.com/blog/2011/09/24/tutorial-how-to-drag-objects/
If you just want to tap them and have them move to where you want them, then something like this might work for you:
local function moveTile(event)
-- put your code here to move the tile
-- figure out the X, Y where the tile needs to move to
-- either just set the X, Y on the tile or use a transition.to() call
-- to animate it.
local thisTile = event.target
thisTile.x = destinationX -- you have to figure out what destinationX is.
thisTile.y = destinationY -- figure this out too
return true
end
Then on each tile after you create it, simply add this line to make it tappable:
tile:addEventListener("tap", moveTile)

In gmaps4rails, how do I move the map so the marker is in view?

I have a set of locations that I want to bring up, individually through ajax calls, and some of them aren't within the current bounds of the map. Is there a way to move the map so the marker is in view?
I don't need it to be in the center, just as long as it's in view.
I figured it out after some research. I'd still be curious to know how to NOT have to center if the marker is visible on the map.
var centerpoint = new google.maps.LatLng(lat_value, long_value);
Gmaps4Rails.map.setCenter(centerpoint)
edit: Found answer to how to not center map every time.
Pseudo code version.
1. Get values from Gmaps4Rails.map.getBounds().
2. Use resulting ta and la values to see if the marker is within those values.
3. If marker is outside of those values, center map, otherwise place marker without centering map.
Thanks guys. I should post more questions. It really helps me to think through my problems.
Jim's answer was probably right when he posted it. But as of now the right way to do it would be :
var centerpoint = new google.maps.LatLng(lat_value, long_value);
Gmaps.map.map.setCenter(centerpoint);
What you expect is automatically done as long as you pass the auto_adjust setting to true. See here.
Then, you should just use the js function Gmaps4Rails.add_markers described here.

Resources