Player/character slides down on level 2 platform game - actionscript-3

so i created a platform game and it has 2 levels. Level 1 is going smoothly and perfectly but when i go to level 2 (which is in frame4), the player/character slides down suddenly. The character i used at level 1 is still the character i use in level 2. I checked the instance name and it's right, I renamed the function name too. It does not have any compiler errors/output errors too that's why im having a hard time figuring out why my player does that. Here's my code:
function charMove1()
{
player_mc.y+=gravity;
if(leftkeyPressed)
{
player_mc.x-=xSpeed;
player_mc.gotoAndStop(2);
player_mc.gotoAndStop(1);
}
if(leftkeyPressed && leftwallBumping)
{
player_mc.x+=xSpeed;
}
if(rightkeyPressed)
{
player_mc.x+=xSpeed;
player_mc.gotoAndStop(1);
player_mc.gotoAndStop(1);
}
if(rightkeyPressed && rightwallBumping)
{
player_mc.x-=xSpeed;
}
if(downwallBumping)
{
player_mc.y-=gravity;
}
if(upwallBumping)
{
player_mc.y+=gravity;
}
//set condition for moving the background, player stays at same position with this code
if(rightkeyPressed && player_mc.x>stage.stageWidth/2+50)
{
background1_mc.x-=backgroundSpeed;
player_mc.x-=xSpeed;
}
if(leftkeyPressed && player_mc.x<stage.stageWidth/2-50)
{
background1_mc.x+=backgroundSpeed;
player_mc.x+=xSpeed;
}
}

Related

Make a play pause switch with html audio

I'm looking for a way to do a play / pause action on click of an element.
Basically when you click and the track is not playing it plays and when it's playing and you click it stops.
So far I was looking for a solution like this but it seems to make a conflict between the play / pause action.
$('#feli').click(function() {
feli.currentTime = 0;
if (feli.play()) {
feli.pause();
} else {
feli.play();;
}
})
Any tips on how to do this simple action ?
Thanks !!
check this code plz
$('#feli').click(function() {
if (feli.play()) {
feli.pause();
feli.currentTime = 0;
} else {
feli.play();;
}
});
Found my solution I put it here :
$('#feli').click(function() {
if (feli.paused) {
feli.currentTime = 0;
feli.play();
} else {
feli.pause();
}
})

Smoothly loading messages Angular 8

I'm writing sort of a chat application using Angular 8 and here's what I want to achieve:
My dialogue component that represents a chat between two users gets one page of last messages that consists of 10 messages after initiating. The div that contains these messages scrolls down to the very last message. When a user scrolls up and reaches a certain point the next page loads. The two arrays join and the user sees now 20 messages. Here's what I have so far:
HTML:
<div>
<div #scrollMe [scrollTop]="scrollMe.scrollHeight" (scroll)="onScroll($event)" style="overflow-y: scroll; height: 400px;">
<ul>
<li *ngFor="let message of messages?.reverse()">
</ul>
</div>
</div>
Typescipt:
loadMessages(page: number, itemsPerPage?: number) {
this.messageService.getMessageThread(page, itemsPerPage || 10)
.subscribe((res: PaginatedResult<MessageThread>) => {
if (this.messages == null) {
this.messages = res.result.messages;
} else {
this.messages = this.messages.concat(res.result.messages);
}
});
}
onScroll(event) {
if (event.target.scrollTop < 100) {
if (this.pagination.currentPage >= this.pagination.totalPages) {
return;
}
this.loadMessages(++this.pagination.currentPage);
}
}
It works, but the problem is that when I join these two arrays, my scrollbar jumps very ugly and since I hold the scrollbar it stays at the same position and keeps loading next pages. I am very new to Angular and front-end in general so I have a feeling that I'm missing something. I tried to find any ready-to-go solutions but could not. Any help would be appreciated.
Please note that I don't want to use JQuery.
Several things:
First, we need a loading flag:
loading = false;
Then we make loadMessages return an observable instead of handle the result:
loadMessages(page: number, itemsPerPage?: number) {
this.loading = true;
return this.messageService.getMessageThread(page, itemsPerPage || 10);
}
A separate method handleResponse handles the response by setting loading to false and concatenating the messages.
Then we can account for the request delay in the scroll handler and use the loading flag to prevent multiple requests:
onScroll(event) {
// get the scroll height before adding new messages
const startingScrollHeight = event.target.scrollHeight;
if (event.target.scrollTop < 100) {
if (this.pagination.currentPage >= this.pagination.totalPages) {
return;
}
else if (!this.loading) {
this.loadMessages(this.pagination.currentPage).subscribe((res) => {
this.handleResponse(res);
// using setTimeout lets the app "wait a beat" so it can measure
// new scroll height *after* messages are added
setTimeout(() => {
const newScrollHeight = this.scrollDiv.nativeElement.scrollHeight;
// set the scroll height from the difference of the new and starting scroll height
this.scrollDiv.nativeElement.scrollTo(0, newScrollHeight - startingScrollHeight);
});
});
}
}
}
Stackblitz (updated)

how to force a Polymer.Element extended class to execute its lifecycle without attaching it to the dom?

Consider this element (minimal for the purpose of the question) :
class MyCountDown extends Polymer.Element
{
static get is () { return 'my-count-down'; }
static get properties ()
{
return {
time: { /* time in seconds */
type: Number,
observer: '_startCountDown'
},
remains: Number
}
}
_startCountDown ()
{
this.remains = this.time;
this.tickInterval = window.setInterval(() => {
this.remains--;
if (this.remains == 0) {
console.log('countdown!');
this._stopCountDown();
}
}, 1000);
}
_stopCountDown () {
if (this.tickInterval) {
window.clearInterval(this.tickInterval);
}
}
}
customElements.define(MyCountDown.is, MyCountDown);
If I get one instance and set the property time,
let MyCountDown = customElements.get('my-count-down');
let cd = new MyCountDown();
cd.time = 5;
the property time changes but the observer and the _startCountDown() function is not called. I believe Polymer is waiting for the Instance to be attached to the DOM because in fact when I appendChild() this element to the document the count down starts and after 5 seconds the console logs 'countdown!' as expected.
My goal is to execute this lifecycle without attaching anything to the document because the instances of MyCountDown are not always attached to the view but/and they need to be live-code between the different components of my web application.
One solution is to attach the new MyCountDown instances to an hidden element of the dom to force the Polymer lifecycle but I think this is not so intuitive.
I don't know the exact place to call, but the problem you have is that the property assessors are not in place.
I think you might get a clue from this talk https://www.youtube.com/watch?v=assSM3rlvZ8 at google i/o
call this._enableProperties() in a constructor callback?

Move Window in mfc c++ without titlebar?

I am using this code to move the window. But this code does not work well. When I click anywhere on windows from it will move but i just want to move windows form. When i click on specific think. For example picture. I am using MFC C++ HtmlDialog. Anyone know how to do that?
DHTML_EVENT_ONCLICK(_T("image"), PreTranslateMessage)
BOOL CHtmlDlgTestDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_MOUSEMOVE && (pMsg->wParam & MK_LBUTTON))
{
CPoint p;
GetCursorPos(&p);
CRect r;
GetWindowRect(&r);
if (r.PtInRect(p))
{
ReleaseCapture();
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0);
SendMessage(WM_NCLBUTTONUP, HTCAPTION, 0);
return 1;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
WM_NCLBUTTONDOWN is a notification message, Windows sends this message and the program responds to it. The program should not send this message to Windows. In this case it works but it's not recommended.
I don't know how this code works: DHTML_EVENT_ONCLICK(_T("image"), PreTranslateMessage) it probably gets ignored and you can remove it. PreTranslateMessage is still called. You can restrict it to any rectangle within the Window, for example CRect(50,50,200,200):
BOOL CHtmlDlgTestDlg::PreTranslateMessage(MSG* pMsg)
{
if (pMsg->message == WM_MOUSEMOVE && (pMsg->wParam & MK_LBUTTON))
{
CPoint p = pMsg->pt;
ScreenToClient(&p);
CRect r(50,50,200,200);
if (r.PtInRect(p))
{
ReleaseCapture();
SendMessage(WM_NCLBUTTONDOWN, HTCAPTION, 0);
SendMessage(WM_NCLBUTTONUP, HTCAPTION, 0);
return 1;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
If you want to move an element within the window you can use javascript:
Moveable/draggable <div>
Ps, normally you should use WM_NCHITTEST as explained earlier. This case is very unusual because it's HTML dialog. You should reconsider putting a normal title bar which users understand, or you could put html control within a dialog, then you can control the rest of the dialog with standard WinApi.

multiple tinyMce instances not working in chrome

As with the title in Chrome (v.4.1) multiple tinyMce (v2.08) instances do not work. To be exact the first two instances are ok, the others not, and chrome gives this error:
Uncaught Error: INDEX_SIZE_ERR: DOM Exception 1
Has this happened before?
Unfortunately I can't show you any code because it's for an admin area, I just need some clue for the moment.
Yes, as user XP1 noted, at this link you can find resolution for a comprimed TinyMCE source:
http://my.opera.com/XP1/blog/2011/07/21/tinymce-javascript-error-in-opera-getrangeat-index-size-err
But if you want to work with original uncomprimed source (it's just a bit easier), here is the solution:
Look for code "setRng : function(r) {" (without quotes) and exchange the whole function with:
setRng : function(r) {
var s, t = this;
if (!t.tridentSel) {
s = t.getSel();
if (s) // this block fixed according to TinyMCE JavaScript error in Opera (getRangeAt, INDEX_SIZE_ERR); http://my.opera.com/XP1/blog/2011/07/21/tinymce-javascript-error-in-opera-getrangeat-index-size-err
{
if(s.anchorNode === null && s.focusNode === null)
{
t.explicitRange = r;
try {
s.removeAllRanges();
} catch (ex) {
// IE9 might throw errors here don't know why (NOW WE KNOW WHY DAMMIT!)
}
s.addRange(r);
}
if (s.rangeCount > 0)
t.selectedRange = s.getRangeAt(0);
}
} else {
// Is W3C Range
if (r.cloneRange) {
t.tridentSel.addRange(r);
return;
}
// Is IE specific range
try {
r.select();
} catch (ex) {
// Needed for some odd IE bug #1843306
}
}
},
ONE NOTE: please make sure variables match. I am not sure how it is between different TinyMCE versions BUT the variables are not the same between comprimed and src mutations of the script file.
Take Care and God Speed