Corona composer.gotoScene() does not reset my scene - lua

I am pretty new to Corona. I have a button that triggers the following code:
local options =
{
effect = "fade",
time = 400,
params = {
loadFromFile = true,
fileName = "level1",
level = levelParams
}
}
composer.gotoScene( "view1", options)
When I finish the level and click this button again, the "view1" scene is in the same state. How do I reset it quickly? Like creating an entirely new scene object?
I tried using composer.removeScene() and purge, but nothing happens. Even non-graphic element stay the same, like scores and stuff.
Any ideas?
Thanks.
Regards,
Serban

You create objects in
function scene:create( event )
then if you want them to change everytime you go away and come back, you should manipulate your objects under:
function scene:show( event )
There is an example under welcome screen>interface>composer in Corona SDK.

Related

How to place model once in ARCore

In my code, the model gets rendered every time I tap the screen. I want that once the model is placed in AR, even if the user taps it should not place the second model. How can I do it? I am using ARcore.
Regardless if it is a native android or an UNITY ARCore project.The easiest logic will be to use a boolean like isPlaced (initially false). Once the model is placed in the AR scene, change the boolean to true.
have the Ontap functions logic in an if statement checking is isPlaced is false.
bool isPlaced = false;
// function to handle tap interaction
ontapped(){
if(!isPlaced){
// logic to place model in AR Scene
isPlaced = true;
}
}
Anchor anchor = hitresult.createAnchor();
AnchorNode anchorNode = new AnchorNode(anchor);
anchorNode.setParent(arFragment.getArSceneView().getScene());
TransformableNode lamp = new TransformableNode(arFragment.getTransformationSystem());
lamp.getScaleController().setSensitivity(3);
lamp.setParent(anchorNode);
lamp.setRenderable(tanRenderable);
lamp.select();
***arFragment.setOnTapArPlaneListener(null)***;

How to stop regenerating the wall after first click?

I just coded a game that needs the wall to be generated forever randomly (just like the walls in Flappy Bird), but every time when I touched the screen, it started to generate again which ended up with generating too much walls. Is there any methods I could use when clicking the screen (to make player jump) without generating too much walls?
Ok so based on our conversation in the comments, what you would want to do is create a boolean like so
var gameStarted = Bool()// outside of didMoveToView
override func touchesBegan() {
if gameStarted == false{
gameStarted = true
movingGround.start()
// add whatever code is left
}
}
Hopefully this is what you were looking for

how can I pause the Game scene in Corona

I want to include a pause button in my game which do not involves physics on the objects.The code only consist of some transitions. How can I do pause and the resume options in corona?
If you are just talking about pausing transitions then the answer is pretty straight forward.
At the top of your lua file add:
local gamePaused = false
Then add a tag to "all" of your transitions like a so:
transition.to(myObject, {time=2000, y = 768, tag = "animationBlock" } )
"tag" can be anything just call it something friendly...
Then when you want to pause simply say transition.pause("animationBlock")
that would cause your animations to stop.
To pause an "entire" game it is a little more code but pretty much the same thing...
so use the local var above then create a function lets say "IsGamePaused" :
local function IsGamePaused()
if (gamePaused == true) then return true end
--you can add more stuff here like if (inDialog == true) then return true end
--etc. and so forth that way you have 1 function that can check all sorts of other
--information.
return false
end
the just create a function that can pause or resume using the above function saying something like if:
if (IsGamePaused() == false) then
transition.resume("animationBlock")
else
transition.pause("animationBlock")
end

Loop activated on mouse movement

I'm just going to explain the context so it is clearer.
I made this menu : my menu
I am looking to make an improved and more advanced version of the same menu.
I made an animation of waves on the cofee's surface and am looking to make it loop when the mouse is moving and to stop looping when it's not.
Sorry for the lack of specifications as I am quite new to actionscript, but I hope somebody will be able to help me. :)
Thanks,
Mathieu
Well, you said it - leverage MouseEvent.MOUSE_MOVE to set a conditional in your looping routine.
private var _isMoving:Boolean = false;
stage.addEventListener(MouseEvent.MOUSE_MOVE, checkMouse);
this.addEventListener(Event.ENTER_FRAME, doLoop);
private function checkMouse(e:MouseEvent):void
{
_isMoving = true;
}
private function doLoop(e:Event):void
{
trace("moving =" + _isMoving);
if(_isMoving)
{
// loop animation
}
_isMoving = false;
}
depending on how you want it to work I would do this as follows:
create an animation of wavy coffee
ensure the animation loops
note that clips loop by default, so all you have to do is match the first and last frames!
place the clip at the edge of your current coffee graphic
double click on the graphic to edit it
drag an instance of the looping animation from the library onto the "edge" of the graphic
OR just replace your entire light brown graphic with an animated one that loops
when the mouse is moving, call play on the animated loop clip
when the mouse stops, call stop on the animated loop clip
Some example code would be along the lines of:
public function init():void {
menuClip.addEventListener(MouseEvent.MOUSE_OVER, onMenuRollOver);
menuClip.addEventListener(MouseEvent.MOUSE_OUT, onMenuRollOut);
}
public function onMenuRollOver(event:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_MOVE, onMove);
/* do the stuff you're currently doing to animate the clip here.
something like: coffee graphic height = ease to mouseHeight */
}
public function onMenuRollOut(event:MouseEvent):void {
/* do the stuff you're currently doing to stop the clip here. */
stage.removeEventListener(MouseEvent.MOUSE_MOVE, onMove);
coffeeClip.stop();
}
public function onMove(event:MouseEvent):void {
resetTimer();
coffeeClip.play(); //note: play has no effect when movie is playing (that's ideal in this case)
}
public function resetTimer():void {
if(mouseMovementTimer == null) createTimer();
mouseMovementTimer.reset();
mouseMovementTimer.start();
}
public function createTimer():Timer {
mouseMovementTimer = new Timer(DELAY, 1); //fiddle with the delay variable. Try 500, at first
mouseMovementTimer.addEventListener(TimerEvent.TIMER, stopAnimationLoop);
}
public function stopAnimationLoop(event:TimerEvent):void {
mouseMovementTimer.removeEventListener(TimerEvent.TIMER, stopAnimationLoop); //optional but recommended
mouseMovementTimer = null;
coffeClip.stop();
}
Of course, you would need to do things like call init() and import flash.utils.Timer and initialize variables like mouseMovementTimer, menuClip, coffeeClip and DELAY.
Warning: This code is off the top of my head and untested. So there's likely to be small bugs in it but you should get the general idea:
add a mouse listener when the user mouses over the menu
remove that listener if the user mouses out of the menu
have that listener play the looping movie clip
trigger an event that will stop the looping clip if movement hasn't been detected in a while
once the trigger goes of, stop the clip
The key is in detecting when the mouse stops moving. Flash detects interaction well but does not detect NON-INTERACTION for obvious reasons. One easy way to solve that is to trigger a timer that will go off once too much time has elapsed since the last activity. Then, when the timer triggers, you know action has stopped!
I think that's the key piece to solving your problem. I hope that helps someone in some way.
~gmale

How do I 'addChild' an DisplayObject3d from another class? (Papervision3d)

Im kind of new in the whole papervision scene.
For a school assignment I'm making a panorama version of my own room using
a cube with 6 pictures in it. It created the panorama, it works great.
But now I want to add clickable objects in it. One of the requirements
is that my code is OOP focused. So that's what I am trying right now.
Currently I got two classes
- Main.as (Here i make the panorama cube as the room)
- photoWall.as (Here I want to create my first clickable object)
Now my problem is: I want to addChild a clickable object from photoWall.as
to my panorama room. But he doesn't show it? I think it has something to do with
the scenes. I use a new scene in Main.as and in photoWall.as. No errors or warnings are reported
This is the piece in photoWall.as were I want to addChild my object (photoList):
private function portret():void
{
//defining my material for the clickable portret
var material : BitmapFileMaterial = new BitmapFileMaterial('images/room.jpg');
var material_list : MaterialsList = new MaterialsList( { front: material, back: material } );
// I don't know if this is nessecary? that's my problem
scene = new Scene3D();
material.interactive = true;
// make the clickable object as a cube
var photoList : DisplayObject3D = new Cube(material_list, 1400, 1400, 1750, 1, 4, 4, 4);
// positioning
photoList.x = -1400;
photoList.y = -280;
photoList.z = 5000;
//mouse event
photoList.addEventListener( InteractiveScene3DEvent.OBJECT_CLICK, onPress);
// this is my problem! I cannot see 'photoList' within my scene!!!
scene.addChild(photoList);
// trace works, so the function must be loaded.
trace('function loaded');
}
Hope you guys can help me out here. Would really be great!
Thanks,
Sandor
you have to render before you can se anything.
missing:
viewport.startRender()
No I already rendered everything in another class.
I figured it out, the answer is: I have to make this class a displayobject3d.
that's it. everything you addchild on the stage now is a displayobject3d.
for details or code..just ask.
view the result of my little project here :
http://www.sandorkerst.com/papervision/bin

Resources