I have some characters in my game on SmartFoxServer BASIC. Characters are controlled using the mouse (like in SFS basic avatarchat example)
I need characters can be rotated in different directions (like in different children MMO, for example Club Penguin).
My character is drawn with 8 sides (East, South-East, South, South-West, West, North-West, North, North-East).
How can I do it ? ActionScript 2.0
Maybe someone here have already made a similar on SFS? Or simply advise how this can be implemented ..
I know that it does not need to do anything on server-side.
(sorry for my english, I am not from an English-speaking country)
Note: I have not tested the following answer myself as I don't have testing environment currently:
Create a movieclip in your stage and insert the character sprites in individual frames of the layer sequentially.
Test to see if your character is rotating clockwise as expected starting from East.
Name the movieclip as "hero" for an instance.
Try the following code:
Actionscript 2:
_root.onEnterFrame = function() {
if (Key.isDown(Key.UP)) {
_root.hero.gotoAndStop(7);
if (Key.isDown(Key.LEFT)) {
_root.hero.prevFrame();
} else if (Key.isDown(Key.RIGHT)) {
_root.hero.nextFrame();
}
} else if (Key.isDown(Key.DOWN)) {
_root.hero.gotoAndStop(3);
if (Key.isDown(Key.LEFT)) {
_root.hero.nextFrame();
} else if (Key.isDown(Key.RIGHT)) {
_root.hero.prevFrame();
}
} else if (Key.isDown(Key.LEFT)) {
_root.hero.gotoAndStop(5);
} else if (Key.isDown(Key.RIGHT)) {
_root.hero.gotoAndStop(1);
}
}
Related
I'm trying to build a widget that has a gauge like in the image attached. It does not seem like there are any APIs to render the gauge (or any other view for that matter) on an arc, depending on which corner is used.
Is there any such support, or are such widgets only available to Apple? E.g. can one tell which corner the widget is being rendered in, so that the correct transformations be computed?
Thank you!
You can get close to an Apple style corner widget, but there are currently some limitations. As far as I know you have to use the .widgetLabel modifier which restricts you to an "Image, Text, Gauge, ProgressView, or a container with multiple subviews".
The styling for the Gauge and ProgressView seem to be predefined as well - for example styling the gauge with .gaugeStyle(LinearCapacityGaugeStyle()) doesn't change the appearance.
var body: some View {
switch widgetFamily {
case .accessoryCorner: // WatchOS only
Text("50%") // Watch out for clipping
.font(.system(size: 20))
.foregroundColor(.blue)
.widgetLabel {
ProgressView(value: 0.5)
.tint(.blue)
}
}
}
or
var body: some View {
switch widgetFamily {
case .accessoryCorner: // WatchOS only
Text("50%") // Watch out for clipping
.font(.system(size: 20))
.foregroundColor(.blue)
.widgetLabel {
Gauge(value: 50.0, in: 0...100) {
Text("Not shown")
} currentValueLabel: {
Text("Not shown")
} minimumValueLabel: {
Text("0") // Watch out for clipping
} maximumValueLabel: {
Text("100") // Watch out for clipping
}
.tint(.blue)
.gaugeStyle(LinearCapacityGaugeStyle()) // Doesn't do anything
}
Gives you:
You can rotate the text manually to try and make it line up with corner, but as you say then there doesn't seem to be a way to identify which corner the widget is in so you don't know which way to rotate it...
I'm developing camera app right now.
I finished most of important features but the most important feature left.
I want my app auto exposure mode.
Here is my sample.
do {
try camera.lockForConfiguration()
camera.focusMode = .continuousAutoFocus
camera.exposureMode = .continuousAutoExposure
camera.unlockForConfiguration()
} catch {
return
}
I made this setting between lockForConfiguration and unlockForConfiguration.
This lead to autoexposure, however it is different from native camera app.
Also, shutter speed does not go below 1/40.
It is always 1/40 whenever it is in dark environment.(where native camera app adjust shutter speed to 1/2 or even 1)
I found the answer here (https://developer.apple.com/forums/thread/26227)
But I don't understand this answer and even how to do that...
session.beginConfiguration()
defer {
session.commitConfiguration()
}
device = AVCaptureDevice.default(.builtInDualWideCamera, for: .video, position: .back)
guard let camera = device else {
set(error: .cameraUnavailable)
status = .failed
return
}
I set AVCapturedevice in this code. Also there is a session.
The answer says don't touch sessionpreset, so I did do anything by sessionPreset.
But how can I set the avcapturedevice by activeformat..?
This is very hard to understand.
Just to check if this is work, I added this codes just below above codes.
'''
var bestFormat: AVCaptureDevice.Format?
bestFormat = device!.formats[2]
print(self.device?.formats)
do {
try camera.lockForConfiguration()
camera.focusMode = .continuousAutoFocus
camera.exposureMode = .continuousAutoExposure
camera.activeFormat = bestFormat!
// camera.setExposureModeCustom(duration: CMTime(value: 1, timescale: 500), iso: 2000)
camera.unlockForConfiguration()
} catch {
return
}
'''
I believe this does not work because camera-resolution doesn't change.
even if device!.formats[2] is low resolution for me (I checked it)
I'm trying to automate a nested map scenario using LESS CSS.
Consider the following single level map:
.map(#keys) {
each(#keys, {
#{value} : #index;
});
}
Called something like this:
.render-maps() {
#arr: child1, child2, child3;
#text-colors: {
#map(#arr);
}
}
This works fine for single level maps where the output is a simple key and value, however I want to create a second level map - like below - but I can't get it to compile:
.nested-map(#arr1, #arr2) {
each(#arr1, {
// I cannot get the compiler to output with a prefix '#' on parent!!!
#parent#{index} : {
each(#arr2, {
#{value} : #index;
});
}
});
}
Can it be done? If so, any advice appreciated.
UPDATE
Here's what I'm trying to achieve, just in case there's a better solution:
I have a number of base colors, these are held as variables in themes.
#primary: #000000;
For each base color, there may be a contrasting "on" color - representing text etc.
#on-primary: #ffffff;
For each "on" color, there maybe a number of categories - text, icons, borders.
... and for each category, there could be multiple states and each state uses a different opacity.
For instance,
icons have 3 states - active, inactive, disabled - each with a different opacity but using the same "on" color.
You could choose to place icons on the background or on a colored surface, so there are multiple themes as well.
To summarise, there could be hundreds of different permutations - which I don't want to maintain individually as variables.
Instead, I create a number of key variables/lists and mixins so that I can generate all of the variations.
#primary: #000000; // 10 of these
#on-primary: #ffffff;
#icon-variants: active, inactive, disabled;
#icon-opacity-on-primary: 70, 50, 38;
Once, I have all my variants, I retrieve colors via a mixin. Here's an example of a single level map for colors.
.get-color(#color) {
#colors: {
.map-colors();
}
#return: color(#colors[$#color]);
}
This type of approach means that I can only need to know a theme "primary", from which I can get the correct, "on" colors and any variants for text, icons, borders, and any state of any variant suing just a handful of mixins.
For example: .get-text-color(high-emphasis, on-primary)[];
Here's how I have to map 2 level maps because I can't do it automatically:
.get-text-color(#theme; #type: high) {
#text-colors: {
#on-primary: { .map-text-color(on-primary); }
#on-primary-dark: { .map-text-color(on-primary-dark); }
#on-primary-light: { .map-text-color(on-primary-light); }
#on-secondary: { .map-text-color(on-secondary); }
#on-error: { .map-text-color(on-error); }
#on-surface: { .map-text-color(on-surface); }
#on-background: { .map-text-color(on-background); }
#on-light: { .map-text-color(on-light); }
#on-dark: { .map-text-color(on-dark); }
}
#return: color(#text-colors[##theme][$#type]);
}
Which results in 30 colors - 10 x 3 states.
I have a scene of say a coloured cube with the red side facing the camera and blue side on the far side. I want to click the "End" key and have the camera now facing the blue side (move the camera not the cube). Also have the option to hit the "Home" key to reverse the above, so it then moves back to the red side.
First thing what is the best 1 camera or 2.
Second thing I am having problems getting my keys recognised with the following code.
function animate()
{
requestAnimationFrame(animate);
render();
update();
}
function update()
{
if ( keyboard.pressed("1") )
{ currentCamera = 1; }
if ( keyboard.pressed("2") )
{ currentCamera=2; }
}
function render()
{
if(currentCamera==1) renderer.render( scene, camera1 );
if(currentCamera==2) renderer.render( scene, camera2 );
}
i dont know what the exact problem is with the cameras. but the keys problem is solvable. keys are handled through the use of event listeners. for example:
window.addEventListener('keydown', function(event){
var key = event.keyCode;
switch(key){
case 49: currentCamera = 1; break;
case 50: currentCamera = 2; break;
}
});
keep in mind the keyCode is not the letter or number printed on the key but rather the ascii code.
I'm sure I'm just overlooking this question but I cant seem to find how to check the device.
I want to check whether the device is either a phone, a tablet in landscape mode, a tablet in portrait mode or a other device (computer).
What I have is this:
if (Ext.platform.isPhone) {
console.log("phone");
}
if (Ext.platform.isTablet) {
console.log("tablet");
}
var x = Ext.platform;
But platform is undefined (probably because this is the way of Sencha Touch 1).
Does anyone know the correct place for me to access the device check?
Sencha Environment Detection offers a large spectrum through simple means.
Instead of Ext.os.is.Tablet, you can make life easier via Ext.os.deviceType which will return:
Phone
Tablet
Desktop
NB: this value can also be fudged by adding "?deviceType=" to the url.
http://localhost/mypage.html?deviceType=Tablet
Ext.os.name is the singleton returning:
iOS
Android
webOS
BlackBerry
RIMTablet
MacOS
Windows
Linux
Bada
Other
The usual ability of browser detection is available through Ext.browser.name.
Something I've only recently encountered, which I love is feature detection - allowing coding similar to Modernizr / YepNope based off ability of device. Ext.feature offers:
Ext.feature.has.Audio
Ext.feature.has.Canvas
Ext.feature.has.ClassList
Ext.feature.has.CreateContextualFragment
Ext.feature.has.Css3dTransforms
Ext.feature.has.CssAnimations
Ext.feature.has.CssTransforms
Ext.feature.has.CssTransitions
Ext.feature.has.DeviceMotion
Ext.feature.has.Geolocation
Ext.feature.has.History
Ext.feature.has.Orientation
Ext.feature.has.OrientationChange
Ext.feature.has.Range
Ext.feature.has.SqlDatabase
Ext.feature.has.Svg
Ext.feature.has.Touch
Ext.feature.has.Video
Ext.feature.has.Vml
Ext.feature.has.WebSockets
To detect fullscreen/app/homescreen browser mode on iOS:
window.navigator.standalone == true
Orientation Ext.device.Orientation and orientation change:
Ext.device.Orientation.on({
scope: this,
orientationchange: function(e) {
console.log('Alpha: ', e.alpha);
console.log('Beta: ', e.beta);
console.log('Gamma: ', e.gamma);
}
});
Orientation is based on Viewport. I usually add a listener which is more reliable:
onOrientationChange: function(viewport, orientation, width, height) {
// test trigger and values
console.log('o:' + orientation + ' w:' + width + ' h:' + height);
if (width > height) {
orientation = 'landscape';
} else {
orientation = 'portrait';
}
// add handlers here...
}
Use Ext.env.OS's is() method.
Note that only major component and simplified value of the version are
available via direct property checking. Supported values are: iOS,
iPad, iPhone, iPod, Android, WebOS, BlackBerry, Bada, MacOS, Windows,
Linux and Other
if (Ext.os.is('Android')) { ... }
if (Ext.os.is.Android2) { ... } // Equivalent to (Ext.os.is.Android && Ext.os.version.equals(2))
if (Ext.os.is.iOS32) { ... } // Equivalent to (Ext.os.is.iOS && Ext.os.version.equals(3.2))
Alternatively, you can also use PhoneGap Device API
I found the answer to it:
What seems to be the case is that Ext.os.is.(tablet/phone or something else) is true or undefined. If it is not the case it will be undefined.
I.a. Ext.os.is.Tablet is true when on a tablet and undefined when not.
So this is the answer I was looking for
if(Ext.os.is.Tablet){
this._bIsTablet = true;
}else if(Ext.os.is.Phone){
this._bIsPhone = true;
}else{
this._bIsOther = true;
}