Parallax Sliding long movieclip Animate CC and TweenJs - jquery-animate

I'm creating a sliding movieclip in Animate CC. I have a movie clip that is 19200 pixels wide. How can I TweenJS the movieclip 1920 to the left when the right arrow is clicked and TweenJS the same movieclip 1920 to the right when the left arrow is clicked?
Here is what I have so far in Animate CC HTML5 Canvas:
/* Mouse Click Event
Clicking on the specified symbol instance executes a function in which you can add your own custom code.
*/
this.next.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler()
{
createjs.Tween.get(this.movieClip_1).to({x:-1920}, 500, Ease.getPowIn(2.2))
}
this.prev.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler()
{
createjs.Tween.get(this.movieClip_1).to({x:1920}, 500, Ease.getPowIn(2.2))
}

1) In your code, you have two functions named equally, but with different code inside. The same name is specified on the listener-adding code. Because of that, both listeners will be linked to just one of the functions (specifically, the second one, for being the last one declared).
this.next.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler()
{
/* Code */
}
this.prev.addEventListener("click", fl_MouseClickHandler.bind(this));
function fl_MouseClickHandler()
{
/* Code */
}
To solve that, changing the names of both functions will be enough. Of course, you'll have to change the names in the listener-adding code.
nextMouseClickHandler()
this.next.addEventListener("click", nextMouseClickHandler.bind(this));
function nextMouseClickHandler() {
/* Code */
}
prevMouseClickHandler()
this.prev.addEventListener("click", prevMouseClickHandler.bind(this));
function prevMouseClickHandler() {
/* Code */
}
2) On the to method of the Tweens in both functions, in the ease parameter, before specifying the ease, you need to add createjs:
Tween in nextMouseClickHandler()
createjs.Tween.get(this.movieClip_1).to({x:-1920}, 500, createjs.Ease.getPowIn(2.2));
Tween in prevMouseClickHandler()
createjs.Tween.get(this.movieClip_1).to({x:1920}, 500, createjs.Ease.getPowIn(2.2));
Solving both issues will result in the following code:
this.next.addEventListener("click", nextMouseClickHandler.bind(this));
function nextMouseClickHandler() {
createjs.Tween.get(this.movieClip_1).to({x:-1920}, 500, createjs.Ease.getPowIn(2.2));
}
this.prev.addEventListener("click", prevMouseClickHandler.bind(this));
function prevMouseClickHandler() {
createjs.Tween.get(this.movieClip_1).to({x:1920}, 500, createjs.Ease.getPowIn(2.2));
}
This code works in Animate CC, replicating the MovieClip names you specified.

Related

Custom CollapsingTopAppBar Jetpack Compose

The essence of the problem is that I want to write my own version of the AppBar that would include content as another Compose function. After looking at the source code of the current CollapsingTopAppBar implementation, I saw the following lines:
#Composable
private fun TwoRowsTopAppBar(
...
scrollBehavior: TopAppBarScrollBehavior?
) {
...
val pinnedHeightPx: Float = 64.dp
val maxHeightPx: Float = 152.dp
LocalDensity.current.run {
pinnedHeightPx = pinnedHeight.toPx()
maxHeightPx = maxHeight.toPx()
}
// Sets the app bar's height offset limit to hide just the bottom title area and keep top title
// visible when collapsed.
SideEffect {
if (scrollBehavior?.state?.heightOffsetLimit != pinnedHeightPx - maxHeightPx) {
scrollBehavior?.state?.heightOffsetLimit = pinnedHeightPx - maxHeightPx
}
}
...
Surface(...) {
Column {
TopAppBarLayout(
...
heightPx = pinnedHeightPx
...
)
TopAppBarLayout(
...
heightPx = maxHeightPx - pinnedHeightPx + (scrollBehavior?.state?.heightOffset
?: 0f),
...
)
}
}
}
As I understand it, scrollBehavior is used to handle the collapse and expansion behavior. In the current implementation, just constant values are put in heightOffsetLimit. And since I need my appbar implementation to be able to contain content of any size, I need to somehow know the size of this content in advance and put this value in heightOffsetLimit.
I have already written the code for my AppBar, so that it also contains content. But since I can't pass the height value of the content to scrollBehavior, the AppBar doesn't collapse to the end.
you need to calculate the height that the appbar will have before drawing it into the screen. I have followed this issue and solved my problem with the last solution. hope it helps:
Get height of element Jetpack Compose
use the content you can put (ex. an image or a huge text) as the MainContent
use your appbar as the DependentContent and use the size given in lambda to give the height to your appbar
finally set placeMainContent false as I believe you don't need to draw the image (or any other composable) directly in a box
and you will good to go

How can I add text like "Game is paused" when I pause the game in GameMakerStudio2

I have a code to when I press "p" the game pauses. Although, I want to show some text saying like "Game is Paused. Press P to progress" how can I do that? HereĀ“s my code:
//create event
pause=false;
pauseSurf=-1;
pauseSurfBuffer=-1;
resW=1920;
resH=1080;
//Post-Draw event
gpu_set_blendenable(false);
if(pause)
{
surface_set_target(application_surface);
if(surface_exists(pauseSurf)) draw_surface(pauseSurf,0,0);
else // restore from buffer if we lost the surface
{
pauseSurf = surface_create(resW,resH);
buffer_set_surface(pauseSurfBuffer,pauseSurf,0);
}
surface_reset_target();
}
if(keyboard_check_pressed(ord("P")))// Toggle pause(Whatever condition/trigger you like)
{
if(!pause)// pause now
{
pause=true;
// deactivate everything other than this instance
instance_deactivate_all(true);
// NOTE:
// If you need to pause anything like animating sprites,tiles,room backgrounds
// you need to do that separately,unfortunately!
// capture this game moment(won't capture draw gui contents though)
pauseSurf=surface_create(resW,resH);
surface_set_target(pauseSurf);
draw_surface(application_surface,0,0);
surface_reset_target();
// Back up this surface toabuffer in case we lose it(screen focus,etc)
if(buffer_exists(pauseSurfBuffer)) buffer_delete(pauseSurfBuffer);
pauseSurfBuffer=buffer_create(resW*resH*4,buffer_fixed,1);
buffer_get_surface(pauseSurfBuffer,pauseSurf,0);
}
else // unpause now
{
pause=false;
instance_activate_all();
if(surface_exists(pauseSurf))surface_free(pauseSurf);
if(buffer_exists(pauseSurfBuffer))buffer_delete(pauseSurfBuffer);
}
}
gpu_set_blendenable(true);
//Clean up event
if(surface_exists(pauseSurf))surface_free(pauseSurf);
if(buffer_exists(pauseSurfBuffer))buffer_delete(pauseSurfBuffer);
Code from: https://www.youtube.com/watch?v=dNiLIX8jNOM&t=95s&ab_channel=ShaunSpalding
If any of you knows how to help me I would be thankful! :)
Add a DrawGui Event to your object, and then add the following code within:
if (pause)
{
draw_text(50, 50, "Game is Paused. Press P to progress");
}
DrawGui makes it so that it renders on top of your viewport, so it's not connected with the position in the room.
The 50, 50, is the X and Y position of the text, use it as you see fit. You can use it centered if you take the width/height of the camera/viewport and divide that by 2.
The pause is already defined in the Create Event, so that shouldn't give any problems.

Creating a flexible UI contianer for an image and a label

I thought this would be like pretty simple task to do, but now I have tried for hours and cant figure out how to get around this.
I have a list of friends which should be displayed in a scrollable list. Each friend have a profile image and a name associated to him, so each item in the list should display the image and the name.
The problem is that I cant figure out how to make a flexible container that contains both the image and the name label. I want to be able to change the width and height dynamically so that the image and the text will scale and move accordingly.
I am using Unity 5 and Unity UI.
I want to achieve the following for the container:
The width and height of the container should be flexible
The image is a child of the container and should be left aligned, the height should fill the container height and should keep its aspect ratio.
The name label is a child of the contianer and should be left aligned to the image with 15 px left padding. The width of the text should fill the rest of the space in the container.
Hope this is illustrated well in the following attached image:
I asked the same question here on Unity Answers, but no answers so far. Is it really possible that such a simple task is not doable in Unity UI without using code?
Thanks a lot for your time!
Looks like can be achieved with layout components.
The image is a child of the container and should be left aligned, the height should fill the container height and should keep its aspect ratio.
For this try to add Aspect Ratio Fitter Component with Aspect mode - Width Controls Height
The name label is a child of the container and should be left aligned to the image with 15 px left padding. The width of the text should fill the rest of the space in the container.
For this you can simply anchor and stretch your label to the container size and use BestFit option on the Text component
We never found a way to do this without code. I am very unsatisfied that such a simple task cannot be done in the current UI system.
We did create the following layout script that does the trick (tanks to Angry Ant for helping us out). The script is attached to the text label:
using UnityEngine;
using UnityEngine.EventSystems;
[RequireComponent (typeof (RectTransform))]
public class IndentByHeightFitter : UIBehaviour, UnityEngine.UI.ILayoutSelfController
{
public enum Edge
{
Left,
Right
}
[SerializeField] Edge m_Edge = Edge.Left;
[SerializeField] float border;
public virtual void SetLayoutHorizontal ()
{
UpdateRect ();
}
public virtual void SetLayoutVertical() {}
#if UNITY_EDITOR
protected override void OnValidate ()
{
UpdateRect ();
}
#endif
protected override void OnRectTransformDimensionsChange ()
{
UpdateRect ();
}
Vector2 GetParentSize ()
{
RectTransform parent = transform.parent as RectTransform;
return parent == null ? Vector2.zero : parent.rect.size;
}
RectTransform.Edge IndentEdgeToRectEdge (Edge edge)
{
return edge == Edge.Left ? RectTransform.Edge.Left : RectTransform.Edge.Right;
}
void UpdateRect ()
{
RectTransform rect = (RectTransform)transform;
Vector2 parentSize = GetParentSize ();
rect.SetInsetAndSizeFromParentEdge (IndentEdgeToRectEdge (m_Edge), parentSize.y + border, parentSize.x - parentSize.y);
}
}

dojo splitter not resizing properly with dynamic content

I'm creating a seemingly simple dojo 1.8 web page which contains an app layout div containing a tab container and an alarm panel below the tab container. They are separated by a splitter so the user can select how much of the alarms or the tabcontainer they want to see.
Here's the example on jsfiddle:
http://jsfiddle.net/bfW7u/
For the purpose of the demo, there's a timer which grows the table in the alarm panel by an entry every 2 seconds.
The problem(s):
If one doesn't do anything and just lets the table grow, no scroll bar appears in the alarm panel.
If one moves the splitter without having resized the browser window first, the splitter handle ends up in a weird location.
Resizing the browser window makes it behave like I would expect it to begin with.
Questions:
Am I doing something wrong in the way I'm setting things up and that's causing this problem?
How can I catch the splitter has been moved event (name?)
How do I resize the splitter pane to an arbitrary height? I've tried using domStyle.set("alarmPanel", "height", 300) and this indeed sets the height property... but the pane does not resize!
Any help greatly appreciated!
I forked your jsFiddle and made some modifications to it: http://jsfiddle.net/phusick/f7qL6/
Get rid of overflow: hidden in html, body and explicitly set height of alarmPanel:
.claro .demoLayout .edgePanel {
height: 150px;
}
This tricky one. You have two options: to listen to splitter's drag and drop or to listen to ContentPane.resize method invocation. Both via dojo/aspect:
// Drag and Drop
var splitter = registry.byId("appLayout").getSplitter("bottom");
var moveHandle = null;
aspect.after(splitter, "_startDrag", function() {
moveHandle = aspect.after(splitter.domNode, "onmousemove", function() {
var coords = {
x: !splitter.horizontal ? splitter.domNode.style.left : 0,
y: splitter.horizontal ? splitter.domNode.style.top : 0
}
dom.byId("dndOutput").textContent = JSON.stringify(coords);
})
});
aspect.after(splitter, "_stopDrag", function() {
moveHandle && moveHandle.remove();
});
// ContentPane.resize()
aspect.after(registry.byId("alarmPanel"), "resize", function(duno, size) {
dom.byId("resizeOutput").textContent = JSON.stringify(size);
});
Call layout() method after changing the size:
registry.byId("alarmPanel").domNode.style.height = "200px";
registry.byId("appLayout").layout();

How to make a MovieClip remove itself in AS3?

What is the equivalent to removeMovieClip() in AS3?
Apparently many have the same question:
StackOverflow:
How to completely remove a movieclip in as3
Remove movie clip as3
How to remove childmovieclip and add to new parent movieclip
Others:
removeMovieClip(this) in AS3?
Destroy/Delete a Movieclip???
Remove movie clip
But none of their solutions seem to work, for me:
Im working on flash CS4 with AS3:
I have a very simple movie with a single button called click. On pressing the button, a new instance of coin is created:
this.click.addEventListener(MouseEvent.CLICK,justclick);
function justclick(e:MouseEvent){
var money=new coin
this.addChild(money)
money.x=e.stageX
money.y=e.stageY
}
It might not be the best code, but it works fine. Now, the coin MovieClip is supposed to show a small animation and remove itself. In good old AS2 I would have added:
this.removeMovieClip()
in the last frame of the animation. But this doesn't exist in AS3.
I have tried, without success:
this.parent.removeChild(this) // 'Cannot access a property or method of nullobject reference'...
this.removeMovieClip() // 'removeMovieClip is not a function'
removeMovieClip(this) //'call to possibly undefined method removeMovieClip'
unloadMovie(this)//'call to possibly undefined method removeMovieClip'
Solutions?
Thanks,
this.parent.removeChild(this);
This one should be working; it's what I use. One problem I had when I switched to AS3 is that sometimes it wouldn't be added as a child right, so you might want to check that. You also have to import flash.display via putting this at the top if you're not already:
import flash.display.*
You should also remove the event listener on it before removing it.
If your animation is ending on frame 20.
note: using 19 because flash count frames from zero(0) similar to array index.
class animatedCloud
{
public function animatedCloud(){
addFrameScript(19, frame20);
}
private function frame20(){
parent.removeChild(this);
}
}
Always ensure that those self removing movieclips can get garbage collected.
This solution wiped away all my instances from a loaded swf's library symbol:
var mc:MovieClip = new definition() as MovieClip;
addChild(mc);
mc.x = 1000 * Math.random();
mc.y = 1000 * Math.random();
mc.addFrameScript(mc.totalFrames - 1, function onLastFrame():void
{
mc.stop();
mc.parent.removeChild(mc);
mc = null;
});
public static function removeDisplayObject(displayObject:DisplayObject):void {
/* normal code
if(displayObject && displayObject.parent){
displayObject.parent.removeChild(displayObject);
}
*/
displayObject ? displayObject.parent ? displayObject.parent.removeChild(displayObject) : null : null;
}
I use, in an extra blank keyframe at the end of the MovieClip which should remove itself:
stop();
MovieClip(parent).removeChild(this);
Found it to be the proper and best solution.