Show CCLabel for few seconds on touch - cocossharp

I'm new to Cocos Sharp and have been struggling to implement behaviour from question title. I want to show message to user that will fade or disappear after some period of time, lats say 3 seconds, after user touches some sprite. But I can't figure it out how to do that.
I'm showing CCLabel like this:
var scoreLabel = new CCLabel("Touch Menu and Exit button together to exit!", "Arial", 50, CCLabelFormat.SystemFont);
scoreLabel.PositionX = button.PositionX;
scoreLabel.PositionY = button.PositionY + 300;
scoreLabel.AnchorPoint = CCPoint.AnchorMiddleRight;
Can someone help me?

After 3 seconds, fadeout in 1 second
scoreLabel.RunActions(new CCDelayTime(3), new CCFadeOut(1));

Related

how to stop Vpython from being unresponsive

Im fairly new to Vpython and Ive created a simulation for circular motion. I tried adding controls to the simulation and so far I am able to pause the simulation but when i do pause it, the entire control panel becomes unresponsive and i am unable to resume the simulation. Does anyone know why this may be or how i can fix this?
def playorpause(self, goorno):
self.pause = goorno
def actual_sim(self):
c = controls() # Create controls window
# Create a button in the controls window:
# b = Button(pos=(-50, 0), width=60, height=60, text="Pause", action=lambda: self.change)
# play = Button(pos=(50, 0), width=60, height=60, text="Play", command = self.play_sim)
b = button(pos=(-50, 0), width=60, height=60, text='Pause', action=lambda: self.playorpause(True))
play = button(pos=(50,0), width = 60, height = 60, text = "play", action =lambda: self.playorpause(False))
def loop():
#### simulation code
if self.pause == False:
loop()
I'm not sure, because I don't really understand your code, but a repetitive loop needs to include a rate statement. Otherwise the program will lock up, unable to output anything.

Game Maker bounce code not woking

Okay so I am making one of those scrolling shooter Galaga-type game using Game Maker Studio. I created the first enemy and set up a spawner for them. They are supposed to just fly downwards towards your ship. That worked fine. But when I made the 2nd enemy, I wanted to make it move more slowly and side-to-side. I also wanted to make them bounce off the edges of the screen. But it just won't work. I can't figure what the hell the problem is and it it driving me insane. If anyone has any ideas, please, share them with me. If you need any more info on the game i can provide it. Here is the code for the step event of the 2nd enemy:
// Control the enemy
if (y > room_height+16)
{
instance_destroy();
}
// Die code
if (armor <= 0)
{
instance_create(x, y, o_explosion_center);
instance_destroy();
}
// Bounce off edges
if (x >= room_width-16)
{
hspeed = -1;
}
if (x < 16)
{
hspeed = 1;
}
First of all, you didn't say what wasn't working. The code you posted is correct, everything depends on the expected result.
One issue I can see id if this code is used by the two enemies. You want them to have different speeds, but once they bounce, their horizontal speeds will be 1 because you set hspeed to 1 and -1. When you create them, you should set a move_speed variable, and for the bouncing, write in the step event :
hspeed = -1*move_speed //instead of hspeed = -1
and
hspeed = move_speed //instead of hspeed = 1
This way, they will keep their initial speeds.
For more help, could you please explain what doesn't work and post the creation code ?

JavaFx can not continually zoom out

I encountered some strange problem with JavaFX.
The use case is: I want to zoom out a swatch.
I implemented a Scroll event handler, like this:
private void handleSwatchScrollAction(ScrollEvent se){
if(se.getEventType().equals(ScrollEvent.SCROLL)){
System.out.println("Enter into handleSwatchScrollAction ");
//The following two lines just want to calculate a ration to scale
double diff = (se.getDeltaY() / 40) * 2;
double diffFactor = diff / 2 / this.fxDial.getRadius() + 1;
System.out.println("diffFactor is: " + diffFactor);
//The following lines is to set scale
this.fxSwatch.setScaleX(diffFactor);
this.fxSwatch.setScaleY(diffFactor);
}
System.out.println("finish handleDialScrollAction");
}
Problem is, when I use scroll to zoom out, the first time zoom out operation works well.
But from the second time, from the view there is no change.
The log looks right, but just no change to display, everything the same as before.
for example, the log is always like this when I continually do zoom out operation(scroll up), no matter the first time or after that:
Enter into handleSwatchScrollAction
(deltaX, deltaY) = (0.0, 40.0)
diffFactor is: 1.005
finish handleSwatchScrollAction
So, why from the view there is no change from the second time to do zoom out(scroll up) operation?
Thank you so much in advance!
You are just setting the scale values to the same value (1.005) every time you scroll. The first time, you will see a zoom of 0.5% or so; but on subsequent scroll events you are not changing the value.
You need something like:
double diffFactor = ... // as before
double scale = this.fxSwatch.getScaleX() * diffFactor ;
this.fxSwatch.setScaleX(scale);
this.fxSwatch.setScaleY(scale);

How can I use JavaFX 8 to do zoom operations with several nodes together

everyone. I am new in JavaFX, I have one problem maybe easier for you but spent me a lot of time, I still can not figure out. My problem is this:
I need to implement a swatch GUI with Java Scene Builder. I choose class Circle as swatch dial, and choose class Label to as time index(1, 2, 3, ... 12), and choose class Line as hour hand, minute hand and second hand.
When I want to do zoom in zoom out operations, I want that the Label(time Indexes) and the Line(swatch hands) can be the children of the Circle(swatch dial), but it seems can not.
So, is there any method can zoom in or zoom out together this several nodes together?
Put all the nodes in a Group and apply the zoom to the Group.
Something like
Pane mainContainer = ... ;
Group watch = new Group();
Circle dial = new Circle(...);
Line hourHand = ... ;
Line minuteHand = ... ;
watch.getChildren().addAll(dial, hourHand, minuteHand);
Label[] timeLabels = new Label[12];
for (int i=1; i<=12; i++) {
timeLabels[i-1]= new Label(String.valueOf(i));
watch.getChildren().add(timeLabels[i-1]);
}
mainContainer.getChildren().add(watch);
Obviously you need to position the various pieces.
Then to zoom just do
watch.setScaleX(...);
watch.setScaleY(...);

Multiple "panes" in game window

I would like to have multiple "panes" or sections of my game window. Section 1 would be a view that follows the player. I have played around with views and they, of course, are different views of the same "room". I could use views then just cover up views 2,3 and 4 with sprites or rectangles, but it seems like there should be a more efficient way to do this.
Ideas or suggestions?
If your using Game Maker: Studio
you can use the (Draw GUI) event and it will draw above everything but buttons might not with this
If your not using Game Maker: Studio
View are most likely your best bet.
Ah, a problem we all face at some point in game development. How to make a HUD?
Here's my trick:
Create an object, say, obj_HUD whose only function is to draw the HUD
Set the depth to something like -100, so that it draws HUD on top of everything else
Place one instance in the room
Let's first initialize some variables in the create event:
//CREATE EVENT
depth = -100;
width_pane2 = 150;
height_pane2 = 300;
width_pane3 = 500;
height_pane3 = 120;
width_pane4 = 120;
// Set the above values according to your needs
Now, for the step event:
//STEP EVENT
x = view_xview;
y = view_yview; //Just for simplifying the code in draw event
Here's the code you need to add to the draw event of obj_HUD:
//DRAW EVENT
draw_rectangle(x , y , x+width_pane2 , y+height_pane2 , false);
draw_rectangle(x , y+view_hview-height_pane3 , x+width_pane3 , y+view_hview , false);
draw_rectangle(x+view_wview-width_pane4 , y , x+view_wview , y+view_hview , false);
If you need to make these transparent, set the value of alpha to something less than 1 before you draw anything, and then back to 1 after you draw everything.
//DRAW EVENT (TRANSPARENT HUD)
draw_set_alpha(0.6);
draw_set_color(c_black);
draw_rectangle(x , y , x+width_pane2 , y+height_pane2 , false);
draw_rectangle(x , y+view_hview-height_pane3 , x+width_pane3 , y+view_hview , false);
draw_rectangle(x+view_wview-width_pane4 , y , x+view_wview , y+view_hview , false);
draw_set_alpha(1);
That should solve the problem!

Resources